简体   繁体   中英

Shape of ImageDataGenerator output not as expected

I use the following code to create a generator for the imagewoof dataset:

import tensorflow as tf
data_path_train = "C:/data/imagewoof2-160/train/"
image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1.0/255.0)
train_gen = image_generator.flow_from_directory(data_path_train,
                                                target_size=(64, 64),
                                                batch_size=32,
                                                shuffle=True,
                                                class_mode="input",
                                                save_to_dir=None)
print(tf.shape(train_gen.next()))

When I run the script I get the following output

Found 9025 images belonging to 10 classes.

tf.Tensor([ 2 32 64 64 3], shape=(5,), dtype=int32)

Why is the generator's output 5-dimensional? I would expect the following shape of the output [batch_size, width, height, channels] . What is in the first dimension?

The generator produces tuples as an output (image, label) that is where the dimension 2 comes from. Then 32 is the batch size 64, 64 is the image size and 3 is the number of channels

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM