[英]How to load images and labels seperately in a dataset loaded by tensorflow_datasets
[英]Converting TensorFlow datasets to images and labels
目标是从 TensorFlow 数据集中训练猫和狗数据集,我需要将数据转换为图像和标签。 我需要构建一个 function 从 TensorFlow 数据集的“特征”返回图像和标签,并从中创建训练数据集。 请运行代码以获取更多详细信息。
基础设施会将所有图像的大小调整为 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)
这是我将编码 model 并提供训练数据集作为输入的地方。
这是解决方案
def preprocess(features): image = features['image'] image = tf.image.resize(image, (224, 224)) image = image / 255.0 return image, features['label']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.