python - 使用 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))
但我没有拆分数据。我怎样才能做到这一点?
解决方案
flow_from 目录返回一个 (x, y) 的元组,其中 x 是一个 numpy 数组,其中包含一批形状为 (batch_size, *target_size, channels) 的图像,y 是一个对应标签的 numpy 数组。
所以你的x_train是train_generator[0]而y_train是train_generator[1]
推荐阅读
- azure - 使用来自“jwks_uri”端点的值验证从 azure ad b2c 收到的令牌
- java - 有没有办法在 Eclipse 中获取当前活动的向导?
- reactjs - React state 和 React useEffect 的区别
- javascript - JavaScript 查找单词最多的句子
- c++ - 为什么使用 getline 从标准输入获取大量输入会截断我的输入?
- google-bigquery - 有什么方法可以在 BigQuery 标准 SQL 脚本中遍历数据集中的所有表?
- linux - 无法在 jenkins linux 上运行 selenium
- symfony - Doctrine - 如何初始化 DB 值
- winforms - CefSharp 75.1.143 本地 .WebM 视频未加载
- java - 如何在使用带有 Selenium Java 的 Chrome Chromedriver 79 下载 .xml 文件时隐藏警告“这种类型的文件可能会损害您的计算机”