简体   繁体   English

ImageDataGenerator 输出的形状不符合预期

[英]Shape of ImageDataGenerator output not as expected

I use the following code to create a generator for the imagewoof dataset:我使用以下代码为 imagewoof 数据集创建一个生成器:

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?为什么生成器的输出是 5 维的? I would expect the following shape of the output [batch_size, width, height, channels] .我希望输出[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.生成器生成元组作为输出(图像、标签),这是维度 2 的来源。 Then 32 is the batch size 64, 64 is the image size and 3 is the number of channels那么32是批量大小64,64是图像大小,3是通道数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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