如何使用 Keras 重建模型并检查其准确性?
Keras 在希腊语中意为“角”。Keras 是作为 ONEIROS 项目(开放式神经电子智能机器人操作系统)研究的一部分而开发的。Keras 是一个用 Python 编写的深度学习 API。它是一个高级 API,具有高效的接口,有助于解决机器学习问题。
Tensorflow 是 Google 提供的机器学习框架。它是一个开源框架,与 Python 结合使用以实现算法、深度学习应用程序等等。它用于研究和生产目的。
Keras 运行在 Tensorflow 框架之上。它旨在帮助快速进行实验。它提供了开发和封装机器学习解决方案所需的必要抽象和构建块。它具有高度可扩展性,并具有跨平台能力。这意味着 Keras 可以运行在 TPU 或 GPU 集群上。Keras 模型也可以导出到 Web 浏览器或移动电话上运行。
Keras 已经存在于 Tensorflow 包中。可以使用以下代码行访问它。
import tensorflow from tensorflow import keras
我们正在使用 Google Colaboratory 来运行以下代码。Google Colab 或 Colaboratory 帮助在浏览器上运行 Python 代码,无需任何配置,并可免费访问 GPU(图形处理单元)。Colaboratory 基于 Jupyter Notebook 构建。以下是代码:
print("Check the accuracy and loss associated with the model")
loss, acc = new_model.evaluate(test_images, test_labels, verbose=2)
print('Restored model, accuracy: {:5.3f}%'.format(100 * acc))代码来源 &minus https://tensorflowcn.cn/tutorials/keras/save_and_load
输出
Check the accuracy and loss associated with the model 32/32 - 0s - loss: 0.4021 - sparse_categorical_accuracy : 0.8720 Restored model, accuracy:87.200%
解释
这个新模型使用“evaluate”方法进行评估。
确定其在训练过程中的准确性和损失。
这些值显示在控制台上。
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP