将TensorFlow数据集转换为图像和标签

2024-05-15 21:07:08 发布

您现在位置:Python中文网/ 问答频道 /正文

目标是从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)

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


Tags: 数据代码name图像importinfotensorflowdef
1条回答
网友
1楼 · 发布于 2024-05-15 21:07:08

这是解决办法

&13; 第13部分,;
def preprocess(features):
    image = features['image']
    image = tf.image.resize(image, (224, 224))
    image = image / 255.0
    return image, features['label']
和#13;
和#13;

相关问题 更多 >