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
will result in
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]
This can be solved by using a resize/pad function that returns images of same shape as shown here and here
ds = ds.map(resize_or_pad_function)
ds = ds.batch(...)
However, I do not want to resize or pad my images, as I want to retain the original size and aspect of images. It is for training a convolutional neural network that can accept varied images sizes.
What do I do if I need batches of tensors with shape (32, None, None, 3) where each image has a different height and width?
Tensorflow Datasetthe Tensor's shapes must be equal across all entries. You could try splitting the dataset into smaller datasets each as a batch of differently shaped Tensor's. But that is rather a bit messy workaround rather than direct solution. - sebastian-sz