简体   繁体   English

如何将 TensorFlow keras 模型保存为 .js 文件

[英]How to save TensorFlow keras model as .js file

如何以.js (TensorFlow js) 格式保存 TensorFlow-Keras 模型

After installing tensorflowjs package try this code you may also need to install ipython package as安装tensorflowjs包后试试这个代码,你可能还需要安装ipython包作为

pip install tensorflowjs pip install -U 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)`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM