简体   繁体   English

尝试将TensorFlow保存模型转换为TensorFlow.js模型时出错

[英]Error Trying to Convert TensorFlow Saved Model to TensorFlow.js Model

I have successfully trained a DNNClassifier to classify texts (posts from an online discussion board). 我已成功培训了一个DNNC分类器来对文本进行分类(来自在线讨论板的帖子)。 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)

Now I want to convert my saved model to use it with the JavaScript version of TensorFlow, tf.js , using the tfjs-converter . 现在我想转换我保存的模型,使用tensorFlowtf.js的JavaScript版本,使用tfjs-converter

When I issue the following command: 当我发出以下命令时:

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: 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 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共存

I assume I'm doing something wrong when saving the model. 我假设在保存模型时我做错了什么。

What is the correct way to save an estimator model so that it can be converted with tfjs-converter ? 保存估算器模型的正确方法是什么,以便可以使用tfjs-converter进行转换

The source code of my project can be found on GitHub. 我的项目的源代码可以在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

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

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