import tensorflow_datasets as tfds
import tensorflow as tf
def input_fn():
dataset_builder = tfds.builder("oxford_flowers102")
dataset_builder.download_and_prepare()
ds = dataset_builder.as_dataset(split=tfds.Split.TRAIN)
ds = ds.repeat()
ds = ds.batch(32)
return ds
将导致
InvalidArgumentError: Cannot batch tensors with different shapes in component 1.
First element had shape [500,666,3] and element 1 had shape [752,500,3].
[Op:IteratorGetNextSync]
这可以通过使用调整大小/填充功能来解决,该功能返回与here和here相同形状的图像>
ds = ds.map(resize_or_pad_function) ds = ds.batch(...)
但是,由于我想保留图像的原始大小和外观,因此我不想调整图像大小或填充图像。它用于训练可以接受各种图像大小的卷积神经网络。
如果我需要一批形状为(32, None, None, 3)
的张量,而每个图像的高度和宽度都不同,该怎么办?
作为tfds导入tensorflow_datasets作为tf def input_fn()导入张量流:dataset_builder = tfds.builder(“ oxford_flowers102”)dataset_builder.download_and_prepare()ds = ...