如何知道ImageDataGenerator()将哪个标签分配给哪个图像类



对于猫和狗图像的二元分类,我的目录结构是train_dir/cats和train_dir/dogs。

train_datagen = ImageDataGenerator(rescale=1/255)

train_generator = train_datagen.flow_from_directory(
'/train_dir/',  # This is the source directory for training images
target_size=(300, 300),  # All images will be resized to 150x150
batch_size=128,
# Since we use binary_crossentropy loss, we need binary labels
class_mode='binary')
model.predict(images, batch_size=10)

如何知道model.predict((返回的概率属于哪一类?猫=1还是狗=1?我在某个地方读到,对于多类分类,返回的概率是按类名的字母顺序排列的。但我认为二元分类并非如此。

您需要访问与每个ImageDataGenerator类关联的class_indices变量。只需打印train_generator.class_indices即可查看哪个类被赋予了哪个标签。

最新更新