如何使用Tensorflow的Python程序和Tensorflow的检查点文件(从here下载)为Inception-ResNet-v2制作预训练/冻结图?
下面显示了我尝试过的内容,但freeze_graph.py
似乎找不到变量。
还有其他步骤缺失吗?
图表和检查点中的变量名称是否不兼容?
$ python3 $TENSORFLOW_HOME/models/research/slim/export_inference_graph.py \
--modal_name inception_resnet_v2 \
--output_file /tmp/inception_resnet_v2.pb
2018-01-08 02:35:11.819267: I tensorflow/core/platform/s3/aws_logging.cc:53] Initializing Curl library
/usr/lib64/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
INFO:tensorflow:Scale of 0 disables regularizer.
$ python3 $TENSORFLOW_HOME/tensorflow/tensorflow/python/tools/freeze_graph.py \
--input_graph /tmp/inception_resnet_v2.pb \
--input_checkpoint /tmp/inception_resnet_v2_2016_08_30.ckpt \
--output_graph /tmp/inception_resnet_v2-frozen_graph.pb \
--input_binary true \
--output_node_names 'InceptionV3/Predictions/Reshape_1'
2018-01-08 02:36:23.083874: I tensorflow/core/platform/s3/aws_logging.cc:53] Initializing Curl library
/usr/lib64/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
Traceback (most recent call last):
File "/usr/local/src/tensorflow/tensorflow/tensorflow/python/tools/freeze_graph.py", line 350, in <module>
app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "/home/rick/.local/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 124, in run
_sys.exit(main(argv))
File "/usr/local/src/tensorflow/tensorflow/tensorflow/python/tools/freeze_graph.py", line 249, in main
FLAGS.saved_model_tags)
File "/usr/local/src/tensorflow/tensorflow/tensorflow/python/tools/freeze_graph.py", line 239, in freeze_graph
input_meta_graph_def, input_saved_model_dir, saved_model_tags.split(","))
File "/usr/local/src/tensorflow/tensorflow/tensorflow/python/tools/freeze_graph.py", line 127, in freeze_graph_with_def_protos
saver = saver_lib.Saver(var_list=var_list)
File "/home/rick/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1288, in __init__
self.build()
File "/home/rick/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1297, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/home/rick/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1322, in _build
raise ValueError("No variables to save")
ValueError: No variables to save
答案 0 :(得分:0)
您正在使用V2,但是在命令中指定了--output_node_names 'InceptionV3/Predictions/Reshape_1'
。我的猜测是InceptionV3
应该是InceptionV2
?
顺便说一句,我从不使用freeze_graph
成功导出冻结图。另一种方法是使用export_inference_graph.py。该说明可以在Exporting a trained model for inference中找到。
最后,如果您已经在第一步中导出了inception_resnet_v2.pb
(顺便说一句,--modal_name
是--model_name
的错字吗?),为什么还要麻烦再次将其导出到{{1} }?