Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用keras ImageDataGenerator时如何获取分类报告(F1分数)-AttributeError:';目录迭代器';对象没有属性';argmax';_Python_Keras - Fatal编程技术网

Python 使用keras ImageDataGenerator时如何获取分类报告(F1分数)-AttributeError:';目录迭代器';对象没有属性';argmax';

Python 使用keras ImageDataGenerator时如何获取分类报告(F1分数)-AttributeError:';目录迭代器';对象没有属性';argmax';,python,keras,Python,Keras,因为在使用Keras ImageDataGenerator时,我没有将训练集和标签分开,而是依赖于文件夹结构。如何获取分类报告,即如何获取/计算精度、召回率和F1 这是我尝试过的,我得到的错误是抱怨列车发电机没有argmax。我怎样才能解决这个问题 AttributeError:“DirectoryIterator”对象没有属性“argmax” 这个解决方案对我很有效,因为如果你使用flow\u from\u directory,那么你必须在模型上使用predict\u generator方法,

因为在使用Keras ImageDataGenerator时,我没有将训练集和标签分开,而是依赖于文件夹结构。如何获取分类报告,即如何获取/计算精度、召回率和F1

这是我尝试过的,我得到的错误是抱怨列车发电机没有argmax。我怎样才能解决这个问题

AttributeError:“DirectoryIterator”对象没有属性“argmax”


这个解决方案对我很有效,因为如果你使用
flow\u from\u directory
,那么你必须在模型上使用
predict\u generator
方法,并谈论
sklearn.metrics.classification\u报告
ytrue
ypred
应该是
1-d numpy
数组,因此使用
train\u generator.labels

train_datagen = ImageDataGenerator(
    rescale=1. / 255,
)

train_generator = train_datagen.flow_from_directory(
    train_dir, 
    target_size=(150, 150), shuffle = False,   # Must
)

predIdxs = model.predict_generator(train_generator)

predIdxs = np.argmax(predIdxs, axis=1)

print(classification_report(train_generator.labels, predIdxs,
                            target_names=["class 1", "class 2"]))

train\u generator.argmax(轴=1)
不工作,因为
train\u generator
是一个生成器,而不是numpy数组。您需要加载地面真相标签,然后使用them@GPhilo谢谢你的提示!是的,我做到了。张贴了答案。非常感谢。
train_datagen = ImageDataGenerator(
    rescale=1. / 255,
)

train_generator = train_datagen.flow_from_directory(
    train_dir, 
    target_size=(150, 150), shuffle = False,   # Must
)

predIdxs = model.predict_generator(train_generator)

predIdxs = np.argmax(predIdxs, axis=1)

print(classification_report(train_generator.labels, predIdxs,
                            target_names=["class 1", "class 2"]))