tensorflow - 如何将 TensorFlow keras 模型保存为 .js 文件
问题描述
如何以.js
(TensorFlow js)格式保存TensorFlow-Keras模型
解决方案
安装tensorflowjs
包后尝试此代码,您可能还需要安装ipython
包为
pip install tensorflowjs
pip install -U ipython
import tensorflowjs as tfjs
tfjs_target_dir = "./tfjs"
def train():
model = keras.Sequential([
keras.layers.Flatten(input_shape=(190, 190)),
keras.layers.Dense(80, activation='relu'),
keras.layers.Dense(2, activation='softmax')
]) # for example
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']) # for example
model.fit(train_data_images, train_data_labels, epochs=15) # for example
tfjs.converters.save_keras_model(model, tfjs_target_dir)`
推荐阅读
- xml - 如何处理'
'元素并在新段落中转换字符串 - android - 位置在android中无法正常工作
- javascript - html 中有 2 个表单字段,即 reg no 和 full name。当使用 Javascript 输入与名称无关的 reg 时,我想填写全名
- html - 从数据库中搜索并使用spring boot + html将其显示在网页中
- html - 添加多个文件,并可以在提交表单之前删除选定的文件
- python - 如何对包含多个单引号字符串的 Like 或 Ilike 使用参数化查询
- c - C中的内存分配是否取决于机器?
- node.js - axios 请求不适用于外部 api 上的表单数据
- windows - 如何避免每次推送或拉取代码时都添加 ssh 密钥
- flutter - 如何用 Flutter 在 initState 函数中一一调用异步函数