导出PB模型

时间:2017-09-26 02:05:16

标签: tensorflow

我按照说明here进行了操作。

这是确切的命令:

python object_detection/export_inference_graph.py \
 --input_type image_tensor \
 --pipeline_config_path gs://${BUCKET}/data/ssd_mobilenet_v1_nest.config \
 --trained_checkpoint_prefix gs://${BUCKET}/data/model.ckpt \
 --output_directory output_inference_graph.pb

错误:

2017-09-26 01:55:30.293505: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instru
ctions, but these are available on your machine and could speed up CPU computations.
2017-09-26 01:55:30.293663: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instru
ctions, but these are available on your machine and could speed up CPU computations.
2017-09-26 01:55:30.293716: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructi
ons, but these are available on your machine and could speed up CPU computations.
2017-09-26 01:55:30.293761: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instruct
ions, but these are available on your machine and could speed up CPU computations.
2017-09-26 01:55:30.293805: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructi
ons, but these are available on your machine and could speed up CPU computations.
Traceback (most recent call last):
  File "object_detection/export_inference_graph.py", line 106, in <module>
    tf.app.run()
  File "/home/paulocoelho/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "object_detection/export_inference_graph.py", line 102, in main
    FLAGS.output_directory)
  File "/home/paulocoelho/tensorflow/models/object_detection/exporter.py", line 376, in export_inference_graph
    optimize_graph, output_collection_name)
  File "/home/paulocoelho/tensorflow/models/object_detection/exporter.py", line 336, in _export_inference_graph
    trained_checkpoint_prefix=trained_checkpoint_prefix)
  File "/home/paulocoelho/tensorflow/models/object_detection/exporter.py", line 295, in _write_graph_and_checkpoint
    saver.restore(sess, trained_checkpoint_prefix)
  File "/home/paulocoelho/.local/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 1560, in restore
    {self.saver_def.filename_tensor_name: save_path})
  File "/home/paulocoelho/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 895, in run
    run_metadata_ptr)
  File "/home/paulocoelho/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1124, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/paulocoelho/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1321, in _do_run
    options, run_metadata)
  File "/home/paulocoelho/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1340, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [1,1,128,12] rhs 
shape= [1,1,128,546]
         [[Node: save/Assign_23 = Assign[T=DT_FLOAT, _class=["loc:@BoxPredictor_5/ClassPredictor/weights"], use_locking=true, validate_shap
e=true, _device="/job:localhost/replica:0/task:0/cpu:0"](BoxPredictor_5/ClassPredictor/weights, save/RestoreV2_23)]]

Caused by op u'save/Assign_23', defined at:
  File "object_detection/export_inference_graph.py", line 106, in <module>
    tf.app.run()
  File "/home/paulocoelho/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "object_detection/export_inference_graph.py", line 102, in main
    FLAGS.output_directory)
  File "/home/paulocoelho/tensorflow/models/object_detection/exporter.py", line 376, in export_inference_graph
    optimize_graph, output_collection_name)
  File "/home/paulocoelho/tensorflow/models/object_detection/exporter.py", line 336, in _export_inference_graph
    trained_checkpoint_prefix=trained_checkpoint_prefix)
  File "/home/paulocoelho/tensorflow/models/object_detection/exporter.py", line 291, in _write_graph_and_checkpoint
    tf.import_graph_def(inference_graph_def, name='')
  File "/home/paulocoelho/.local/lib/python2.7/site-packages/tensorflow/python/framework/importer.py", line 313, in import_graph_def
    op_def=op_def)
  File "/home/paulocoelho/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2630, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "/home/paulocoelho/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1204, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [1,1,128,12] rhs shape= [1,1,12
8,546]
         [[Node: save/Assign_23 = Assign[T=DT_FLOAT, _class=["loc:@BoxPredictor_5/ClassPredictor/weights"], use_locking=true, validate_shap
e=true, _device="/job:localhost/replica:0/task:0/cpu:0"](BoxPredictor_5/ClassPredictor/weights, save/RestoreV2_23)]]

1 个答案:

答案 0 :(得分:0)

我发现了问题。

我多次参加训练。在上面的命令中,我碰巧引用了一个未使用相同管道配置创建的检查点文件。