![](/img/trans.png)
[英]How can I convert Tensorflow model to tensorflow.js model?
[英]How do I save a Tensorflow LinearClassifier model and convert it to Tensorflow.js compatible
我最近开始使用 tensorflow,我只有一个简单的 LinearClassifier 模型。 我想保存它,然后使用tfjs-converter 转换保存的模型
但问题是我似乎无法毫无错误地完成保存模型的第一步。
下面是我的代码片段。
linear_est = tf.estimator.LinearClassifier(feature_columns=feature_columns)
linear_est.train(train_input_fn) # train
linear_est.save('saved_model/my_model') # This gives an error
非常感谢任何帮助摆脱困境!
评论中的示例对我不起作用,但我按照说明进行操作并解决了这样的问题
import tensorflow as tf
import tensorflow.keras as keras
import tensorflowjs as tfjs
input_column = tf.feature_column.numeric_column("x")
a = tf.estimator.LinearClassifier(input_column)
serving_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(
tf.feature_column.make_parse_example_spec([input_column]))
# Save Estimator as a tf model
a.export_saved_model("modelFromEstimator/", serving_input_fn)
# Import model as keras model
model = keras.models.load_model("modelFromEstimator/")
# Save as tfjs model
tfjs.converters.save_keras_model(model, "tfjsmodel")
当我尝试运行 Tensorflow 的用于制作基本线性估计器的示例时,它崩溃了。 您不必使用 Estimator 来进行机器学习——目前它们似乎仍在开发中。
如果你刚刚开始使用 Tensorflow,你可能想从keras.models
开始,比如这里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.