尝试将TensorFlow保存模型转换为TensorFlow.js模型时出错 [英] Error Trying to Convert TensorFlow Saved Model to TensorFlow.js Model

查看:453
本文介绍了尝试将TensorFlow保存模型转换为TensorFlow.js模型时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功培训了一个DNNC分类器来对文本进行分类(来自在线讨论板的帖子)。我使用以下代码创建并保存了我的模型:

I have successfully trained a DNNClassifier to classify texts (posts from an online discussion board). I've created and saved my model using this code:

embedded_text_feature_column = hub.text_embedding_column(
    key="sentence",
    module_spec="https://tfhub.dev/google/nnlm-de-dim128/1")
feature_columns = [embedded_text_feature_column]
estimator = tf.estimator.DNNClassifier(
    hidden_units=[500, 100],
    feature_columns=feature_columns,
    n_classes=2,
    optimizer=tf.train.AdagradOptimizer(learning_rate=0.003))
feature_spec = tf.feature_column.make_parse_example_spec(feature_columns)
serving_input_receiver_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
estimator.export_savedmodel(export_dir_base="/my/dir/base", serving_input_receiver_fn=serving_input_receiver_fn)

现在我想转换我保存的模型,将其与TensorFlow的JavaScript版本一起使用, tf.js ,使用 tfjs-converter

Now I want to convert my saved model to use it with the JavaScript version of TensorFlow, tf.js, using the tfjs-converter.

当我发出以下命令时:

tensorflowjs_converter --input_format=tf_saved_model --output_node_names='dnn/head/predictions/str_classes,dnn/head/predictions/probabilities' --saved_model_tags=serve /my/dir/base /my/export/dir

...我收到此错误消息:

…I get this error message:


ValueError:节点'dnn / input_from_feature_columns / input_layer / sentence_hub_module_embedding / module_apply_default / embedding_lookup_sparse / embedding_lookup'期望与未知节点'dnn / input_from_feature_columns / input_layer / sentence_hub_module_embedding

ValueError: Node 'dnn/input_from_feature_columns/input_layer/sentence_hub_module_embedding/module_apply_default/embedding_lookup_sparse/embedding_lookup' expects to be colocated with unknown node 'dnn/input_from_feature_columns/input_layer/sentence_hub_module_embedding

我认为保存模型时我做错了。

I assume I'm doing something wrong when saving the model.

什么是保存估算器模型的正确方法,以便可以使用 tfjs-converter 进行转换?

What is the correct way to save an estimator model so that it can be converted with tfjs-converter?

我的项目的源代码可以在GitHub上找到。

推荐答案

你可以尝试这个,我认为这将有效。只需在代码中输入您的输入格式。

You can try this and I think this will work. Just input your input format in code.

tensorflowjs_converter --input_format keras \
                       path/to/my_model.h5 \
                       path/to/tfjs_target_dir

这篇关于尝试将TensorFlow保存模型转换为TensorFlow.js模型时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆