- Keras 教程
- Keras - 首页
- Keras - 简介
- Keras - 安装
- Keras - 后端配置
- Keras - 深度学习概述
- Keras - 深度学习
- Keras - 模块
- Keras - 层
- Keras - 自定义层
- Keras - 模型
- Keras - 模型编译
- Keras - 模型评估和预测
- Keras - 卷积神经网络
- Keras - 使用MPL进行回归预测
- Keras - 使用LSTM RNN进行时间序列预测
- Keras - 应用
- Keras - 使用ResNet模型进行实时预测
- Keras - 预训练模型
- Keras 有用资源
- Keras - 快速指南
- Keras - 有用资源
- Keras - 讨论
Keras - 后端配置
本章详细解释了 Keras 后端实现 TensorFlow 和 Theano。让我们逐一了解每个实现。
TensorFlow
TensorFlow 是一个开源机器学习库,用于 Google 开发的数值计算任务。Keras 是一个构建在 TensorFlow 或 Theano 之上的高级 API。我们已经知道如何使用 pip 安装 TensorFlow。
如果尚未安装,可以使用以下命令安装:
pip install TensorFlow
一旦我们执行 keras,我们就可以看到配置文件位于您的主目录内,并转到 .keras/keras.json。
keras.json
{
"image_data_format": "channels_last",
"epsilon": 1e-07, "floatx": "float32", "backend": "tensorflow"
}
这里,
image_data_format 表示数据格式。
epsilon 表示数值常数。它用于避免除以零错误。
floatx 表示默认数据类型float32。您还可以使用set_floatx()方法将其更改为float16或float64。
image_data_format 表示数据格式。
假设,如果文件未创建,则移动到该位置并按照以下步骤创建:
> cd home > mkdir .keras > vi keras.json
请记住,您应该将 .keras 指定为其文件夹名称,并将上述配置添加到 keras.json 文件中。我们可以执行一些预定义的操作来了解后端函数。
Theano
Theano 是一个开源深度学习库,允许您有效地评估多维数组。我们可以使用以下命令轻松安装:
pip install theano
默认情况下,keras 使用 TensorFlow 后端。如果要将后端配置从 TensorFlow 更改为 Theano,只需在 keras.json 文件中将 backend = theano 更改即可。如下所述:
keras.json
{
"image_data_format": "channels_last",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "theano"
}
现在保存您的文件,重新启动终端并启动 keras,您的后端将更改。
>>> import keras as k using theano backend.
广告