tensorflowjs_converter输出“不在图中”,但显示在saved_model_cli中

时间:2019-04-30 17:43:26

标签: tensorflow tensorflow.js

我正在尝试将另存为SavedModel的Python的TensorFlow模型转换为可以在JavaScript的Tensorflow中加载的GraphModel。

我正在使用以下代码生成SavedModel:

<div class="ui-toolbar-group-left">
   <button 
     pButton 
     type="button"
     label="Edit" 
     icon="pi pi-search"
     id="editBtn"  
     class="ui-button-danger" 
     (click)="handleEdit($event)">
      Hello
   </button>                  
</div>

这将产生一个名为import tensorflow as tf print(tf.__version__) with tf.Session() as sess: inputs = tf.keras.layers.Input(shape=[3]) outputs = tf.keras.layers.Dense(1)(inputs) sess.run(tf.global_variables_initializer()) tf.saved_model.simple_save( sess, 'model', inputs={ 'x': inputs }, outputs={ 'y': outputs }, ) 的文件夹和以下输出:

model

可以使用1.13.1 2019-04-30 19:35:11.186131: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1491760000 Hz 2019-04-30 19:35:11.187666: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x480ad20 executing computations on platform Host. Devices: 2019-04-30 19:35:11.190831: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): <undefined>, <undefined> WARNING:tensorflow:From /home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. WARNING:tensorflow:From ./saver.py:13: simple_save (from tensorflow.python.saved_model.simple_save) is deprecated and will be removed in a future version. Instructions for updating: This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.simple_save. WARNING:tensorflow:From /home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/saved_model/signature_def_utils_impl.py:205: build_tensor_info (from tensorflow.python.saved_model.utils_impl) is deprecated and will be removed in a future version. Instructions for updating: This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.utils.build_tensor_info or tf.compat.v1.saved_model.build_tensor_info. 并通过以下输出来探索模型:

saved_model_cli

但是,$ saved_model_cli show --dir model --all MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs: signature_def['serving_default']: The given SavedModel SignatureDef contains the following input(s): inputs['x'] tensor_info: dtype: DT_FLOAT shape: (-1, 3) name: input_1:0 The given SavedModel SignatureDef contains the following output(s): outputs['y'] tensor_info: dtype: DT_FLOAT shape: (-1, 1) name: dense/BiasAdd:0 Method name is: tensorflow/serving/predict 找不到输出tensorflowjs_converter

y

我正在使用以下软件包版本:

$ tensorflowjs_converter --input_format=tf_saved_model --output_node_names=y model web_model                                                          [0/1724]
Using TensorFlow backend.
2019-04-30 19:35:43.778028: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1491760000 Hz
2019-04-30 19:35:43.780592: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x40c5ee0 executing computations on platform Host. Devices:
2019-04-30 19:35:43.780794: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>
WARNING:tensorflow:From /home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py:161: load (from tensorflow.python.saved_model.loader_i
mpl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for 
importing SavedModels in Tensorflow 2.0.
WARNING:tensorflow:From /home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.c
heckpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to check for files with this prefix.
WARNING:tensorflow:From /home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py:232: convert_variables_to_constants (from tensorflow.p
ython.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.compat.v1.graph_util.convert_variables_to_constants
WARNING:tensorflow:From /home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/framework/graph_util_impl.py:245: extract_sub_graph (from tensorflow.python.
framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.compat.v1.graph_util.extract_sub_graph
Traceback (most recent call last):
  File "/home/ubuntu/.pyenv/versions/3.6.3/bin/tensorflowjs_converter", line 10, in <module>
    sys.exit(main())
  File "/home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflowjs/converters/converter.py", line 322, in main
    strip_debug_ops=FLAGS.strip_debug_ops)
  File "/home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflowjs/converters/tf_saved_model_conversion_pb.py", line 290, in convert_tf_saved_model
    input_saved_model_dir=saved_model_dir)
  File "/home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py", line 363, in freeze_graph
    checkpoint_version=checkpoint_version)
  File "/home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/tools/freeze_graph.py", line 232, in freeze_graph_with_def_protos
    variable_names_blacklist=variable_names_blacklist)
  File "/home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
    return func(*args, **kwargs)
  File "/home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/framework/graph_util_impl.py", line 245, in convert_variables_to_constants
    inference_graph = extract_sub_graph(input_graph_def, output_node_names)
  File "/home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
    return func(*args, **kwargs)
  File "/home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/framework/graph_util_impl.py", line 181, in extract_sub_graph
    _assert_nodes_are_present(name_to_node, dest_nodes)
  File "/home/ubuntu/.pyenv/versions/3.6.3/lib/python3.6/site-packages/tensorflow/python/framework/graph_util_impl.py", line 137, in _assert_nodes_are_present
    assert d in name_to_node, "%s is not in graph" % d
AssertionError: y is not in graph

0 个答案:

没有答案