【发布时间】:2020-07-31 17:15:19
【问题描述】:
我对 Keras 有这个问题, 我的 test_set 定义如下:
我的测试集
test_datagen = ImageDataGenerator(rescale = 1./255)
test_set = test_datagen.flow_from_dataframe(dataframe=X_test,
x_col='image_path',
y_col='category_id',
#imagepath_test,
target_size = (64, 64),
batch_size = 32,
class_mode = 'categorical')
为了尽快恢复,我使用 Keras 的 ImageDataGenerator,然后将数据生成器分配给我的 test_set。
我的数据框 X_test 有 2 列,
x_col='image_path' ## The path to my image files
y_col='category_id' ## My categorical features - Labels
我需要从我的 test_set 中提取 y_col 中的值,因为,
test_set['category_id'] is not in same order neither same shape as X_test['category_id']
X_test['category_id'].shape
(315,)
当我查看 test_set 类型时,我得到:
type(test_set)
keras_preprocessing.image.dataframe_iterator.DataFrameIterator
原因:
当我们进行预测时,我们需要在这个“test_set”上进行预测
#_________________________________
# Making Predictions
y_preds = classifier.predict(test_set)
所以,
当我想显示我的分类报告时,我不能使用"test_set",因为格式错误,我也不能使用我的X_test['categorical_id'],因为真实值的顺序与test_set.不同
Below an example of classification_report with test_set and the result:
print(classification_report(test_set, predicted,
target_names=df_data['product_cat1'].unique()))
结果我得到一个错误:
ValueError: Found input variables with inconsistent numbers of samples: [10, 315]
记住,我的'X_test' 形状是:
X_test['category_id'].shape
(315,)
无论我尝试将此'test_set' 转换为数组或数据框,都不起作用。
如果我在我的分类报告中使用X_test['category_id'],它可以工作,但分数是假的,
否则,使用 Keras 进行多类分类很有趣但没用,如果我们不能确定每个类的准确率和召回分数以及 f1_score 准确度模型,我的意思是我们只是得到一个全局准确度模型,仅此而已,只对比赛有好处。
欢迎任何想法和解决方法。
【问题讨论】: