0

我按照此处的说明将使用 Python 生成的 Tensorflow 模型导入到 Tensorflow.js 中。

该模型是使用tf.estimatorAPI创建的,该 API 会根据此页面自动保存模型文件。

使用 pip安装后tensorflowjs,运行转换脚本时出现以下错误:

$ tensorflowjs_converter     --input_format=tf_saved_model     --output_node_names='DeepWater'     /home/sterengiannini/deepwater/model-js-import-test     /home/sterengiannini/deepwater/web-model
Using TensorFlow backend.
Traceback (most recent call last):
  File "/usr/local/bin/tensorflowjs_converter", line 11, in <module>
    sys.exit(main())
  File "/home/sterengiannini/.local/lib/python2.7/site-packages/tensorflowjs/converters/converter.py", line 317, in main
    strip_debug_ops=FLAGS.strip_debug_ops)
  File "/home/sterengiannini/.local/lib/python2.7/site-packages/tensorflowjs/converters/tf_saved_model_conversion.py", line 289, in convert_tf_saved_model
    input_saved_model_dir=saved_model_dir)
  File "/home/sterengiannini/.local/lib/python2.7/site-packages/tensorflow/python/tools/freeze_graph.py", line 338, in freeze_graph
    input_saved_model_dir, saved_model_tags).graph_def
  File "/home/sterengiannini/.local/lib/python2.7/site-packages/tensorflow/python/tools/saved_model_utils.py", line 42, in get_meta_graph_def
    saved_model = reader.read_saved_model(saved_model_dir)
  File "/home/sterengiannini/.local/lib/python2.7/site-packages/tensorflow/contrib/saved_model/python/saved_model/reader.py", line 55, in read_saved_model
    raise IOError("SavedModel file does not exist at: %s" % saved_model_dir)
IOError: SavedModel file does not exist at: /home/sterengiannini/deepwater/model-js-import-test

以下是模型文件夹中的文件:

$ ls model-js-import-test/
graph.pbtxt  model.ckpt-312.data-00000-of-00001  model.ckpt-312.index  model.ckpt-312.meta
4

1 回答 1

1

看起来模型没有以正确的格式保存。您的模型文件夹中应该会出现以下内容(请参阅 SavedModel 目录的结构):

assets/
assets.extra/
variables/
    variables.data-?????-of-?????
    variables.index
saved_model.pb|saved_model.pbtxt

例如,如果您使用 tf.estimator API,则需要使用以下内容导出模型(请参阅将 SavedModel 与 Estimators 一起使用):

estimator.export_savedmodel(export_dir_base, serving_input_receiver_fn)
于 2018-11-19T02:11:31.197 回答