首页 > 解决方案 > 使用 TensorFlow 和 flow_from_directory 计算 CNN 的准确度

问题描述

我正在使用 flow_from_directory 方法将数据输入神经网络:

train_generator = train_datagen.flow_from_directory('.../train', target_size=(img_width, img_height), batch_size=32,class_mode='categorical')

现在我想打印(计算)训练精度。当您将训练数据拆分为 y_train 和 x_train 时,您可以使用如下内容:

training_accuracy = compute_accuracy(y_train, model.predict(x_train))

但我没有拆分数据。我怎样才能做到这一点?

标签: pythontensorflow

解决方案


flow_from 目录返回一个 (x, y) 的元组,其中 x 是一个 numpy 数组,其中包含一批形状为 (batch_size, *target_size, channels) 的图像,y 是一个对应标签的 numpy 数组。

所以你的x_traintrain_generator[0]y_traintrain_generator[1]


推荐阅读