【问题标题】:How to know ImageDataGenerator() assigns which label to which image class?如何知道 ImageDataGenerator() 将哪个标签分配给哪个图像类?
【发布时间】:2020-11-15 13:06:02
【问题描述】:

对于猫狗图片的二元分类,我的目录结构是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? 我在某处读到,对于多类分类,返回的概率按类名的字母顺序排列。但我认为二进制分类并非如此。

【问题讨论】:

    标签: python tensorflow computer-vision conv-neural-network imagedata


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-05
      • 2021-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多