Keras 如何查看来自图像\u数据\u生成器和来自\u目录的流\u的错误分类图像?

Keras 如何查看来自图像\u数据\u生成器和来自\u目录的流\u的错误分类图像?,keras,deep-learning,computer-vision,Keras,Deep Learning,Computer Vision,我正在使用图像数据生成器和来自目录的流来训练模型。 我想知道如何找到错误分类的图像。我知道其中有两个,因为我已经绘制了一个混淆矩阵 给出了显示测试数据发生器以及混淆矩阵的截取代码 test_datagen=tf.keras.preprocessing.image.ImageDataGenerator(preprocessing_function=preprocess_input) test_generator=train_datagen.flow_from_directory('./test',

我正在使用图像数据生成器和来自目录的流来训练模型。 我想知道如何找到错误分类的图像。我知道其中有两个,因为我已经绘制了一个混淆矩阵

给出了显示测试数据发生器以及混淆矩阵的截取代码

test_datagen=tf.keras.preprocessing.image.ImageDataGenerator(preprocessing_function=preprocess_input)
test_generator=train_datagen.flow_from_directory('./test',target_size=(224,224),
                                              batch_size=8,class_mode='binary',
                                            shuffle=False)
      ### mod is the model name
predictions=mod.predict(x=test_generator,verbose=0)
y_pred=[1*(x[0]>0.5) for x in predictions]

cm=confusion_matrix(y_true=test_generator.classes,y_pred=y_pred)
      
####I have found the relative indices in the fianl array used to classify the images 
k=(test_generator.classes==y_pred)
idx=np.where(k==k.min())
有没有一种好方法可以访问错误分类的图像,或者我只是通过使用批次数通过索引手动查找图像?

其次,如果我们使用class\u mode=binary,那么来自\u目录的流如何将图像作为0和1放入二进制分类问题中?