【问题标题】:Converting TensorFlow datasets to images and labels将 TensorFlow 数据集转换为图像和标签
【发布时间】:2020-09-23 17:18:31
【问题描述】:

目标是从 TensorFlow 数据集中训练猫和狗数据集,我需要将数据转换为图像和标签。我需要构建一个函数,从 TensorFlow 数据集的“特征”返回图像和标签,并从中创建训练数据集。请运行代码以获取更多详细信息。

基础架构会将所有图像的大小调整为 224x224,颜色深度为 3 个字节。确保您的输入层根据该规范训练图像。

similar code

代码:

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)

我将在这里对模型进行编码并提供训练数据集作为输入。

【问题讨论】:

标签: python tensorflow tensorflow-datasets


【解决方案1】:

解决办法

def preprocess(features):
    image = features['image']
    image = tf.image.resize(image, (224, 224))
    image = image / 255.0
    return image, features['label']

【讨论】:

    猜你喜欢
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 2015-01-24
    • 2017-11-14
    • 2017-03-09
    • 2020-12-08
    • 1970-01-01
    相关资源
    最近更新 更多