ImageDataGenerator 输出的形状不符合预期
Shape of ImageDataGenerator output not as expected
我使用以下代码为 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()))
当我 运行 脚本时,我得到以下输出
Found 9025 images belonging to 10 classes.
tf.Tensor([ 2 32 64 64 3], shape=(5,), dtype=int32)
为什么生成器的输出是 5 维的?我希望输出的形状如下 [batch_size, width, height, channels]
。第一维是什么?
生成器生成元组作为输出(图像、标签),这是维度 2 的来源。那么32就是batch size 64,64是图像大小,3是通道数
我使用以下代码为 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()))
当我 运行 脚本时,我得到以下输出
Found 9025 images belonging to 10 classes.
tf.Tensor([ 2 32 64 64 3], shape=(5,), dtype=int32)
为什么生成器的输出是 5 维的?我希望输出的形状如下 [batch_size, width, height, channels]
。第一维是什么?
生成器生成元组作为输出(图像、标签),这是维度 2 的来源。那么32就是batch size 64,64是图像大小,3是通道数