如何使用Python和Tensorflow评估CNN模型?
可以使用‘evaluate’方法评估卷积神经网络。此方法将测试数据作为其参数。在此之前,数据使用‘matplotlib’库和‘imshow’方法在控制台上绘制。
阅读更多: 什么是TensorFlow以及Keras如何与TensorFlow一起创建神经网络?
卷积神经网络已被用于针对特定类型的问题(例如图像识别)产生良好的结果。
我们使用Google Colaboratory运行以下代码。Google Colab或Colaboratory有助于通过浏览器运行Python代码,无需任何配置,并可免费访问GPU(图形处理单元)。Colaboratory构建在Jupyter Notebook之上。
print("Plotting accuracy versus epoch")
plt.plot(history.history['accuracy'], label='accuracy')
plt.plot(history.history['val_accuracy'], label = 'val_accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.ylim([0.5, 1])
plt.legend(loc='lower right')
print("The model is being evaluated")
test_loss, test_acc = model.evaluate(test_images,test_labels, verbose=2)
print("The accuracy of the model is:")
print(test_acc)代码来源:https://tensorflowcn.cn/tutorials/images/cnn
输出
Plotting accuracy versus epoch The model is being evaluated 313/313 - 3s - loss: 0.8884 - accuracy: 0.7053 The accuracy of the model is: 0.705299973487854

解释
- 可视化精度与轮数数据。
- 这是使用matplotlib库完成的。
- 评估模型,并确定损失和精度。
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP