目标是从TensorFlow数据集中训练猫和狗的数据集,我需要将数据转换为图像和标签。我需要构建一个函数,从TensorFlow数据集的'features‘中返回图像和标签,并从中创建训练数据集。请运行代码以了解更多详细信息。
基础设施将所有图像的大小调整为224x224,颜色深度为3字节。确保您的输入层按照该规范训练图像。
代码:
import tensorflow_datasets as tfds
import tensorflow as tf
dataset_name = 'cats_vs_dogs'
dataset, info = tfds.load(name=dataset_name, split=tfds.Split.TRAIN, with_info=True)
def preprocess(features):
// this is where the code must be.
def solution_model():
train_dataset = dataset.map(preprocess).batch(32)
这是我将对模型进行编码并提供训练数据集作为输入的地方。
发布于 2020-06-08 09:34:18
以下是解决方案
def preprocess(features):
image = features['image']
image = tf.image.resize(image, (224, 224))
image = image / 255.0
return image, features['label']
https://stackoverflow.com/questions/62199432
复制