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

How to know ImageDataGenerator() assigns which label to which image class?

对于猫狗图像的二进制class化,我的目录结构是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()的概率return属于哪个class?是 Cat=1 还是 dog=1? 我在某处读到,对于 multiclass classification returned 概率按 class 名称的字母顺序排列。但我认为二进制 classification.

并非如此

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