【发布时间】:2017-08-17 03:57:53
【问题描述】:
我在对象检测 API 中使用 ssd_mobilenets 来训练我自己的模型,并获取 .ckpt 文件。它在我的电脑上运行良好,但现在我想在手机上使用该模型。所以,我需要将其转换为 .pb 文件。我不知道该怎么做,有人可以帮忙吗?顺便说一句,ssd_mobilenets 的图很复杂,我找不到哪个是模型的输出。有没有人知道输出的名称?
【问题讨论】:
标签: tensorflow solid-state-drive
我在对象检测 API 中使用 ssd_mobilenets 来训练我自己的模型,并获取 .ckpt 文件。它在我的电脑上运行良好,但现在我想在手机上使用该模型。所以,我需要将其转换为 .pb 文件。我不知道该怎么做,有人可以帮忙吗?顺便说一句,ssd_mobilenets 的图很复杂,我找不到哪个是模型的输出。有没有人知道输出的名称?
【问题讨论】:
标签: tensorflow solid-state-drive
使用export_inference_graph.py将模型检查点文件转换为.pb文件。
python tensorflow_models/object_detection/export_inference_graph.py \
--input_type image_tensor \
--pipeline_config_path architecture_used_while_training.config \
--trained path_to_saved_ckpt/model.ckpt-NUMBER \
--output_directory model/
【讨论】:
tf.train.Saver() 创建了一个.ckpt 文件,但它没有给我一个.config 文件。这是哪里来的?
这是此链接中 object_detection_tutorial.ipynb 中的第 4 个代码单元 -https://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb
# What model to download.
MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17'
MODEL_FILE = MODEL_NAME + '.tar.gz'
DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'
# Path to frozen detection graph. This is the actual model that is used for the object detection.
PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'
# List of the strings that is used to add correct label for each box.
PATH_TO_LABELS = os.path.join('data', 'mscoco_label_map.pbtxt')
NUM_CLASSES = 90
现在单元格清楚地显示了.pb 文件名,即/frozen_inference_graph.pb
.pb 文件为什么要转换??tensorflow.python.tools.freeze_graph() 函数将您的.ckpt 文件转换为.pb 文件下面的代码行显示了你是如何做到的
freeze_graph.freeze_graph(input_graph_path,
input_saver_def_path,
input_binary,
input_checkpoint_path,
output_node_names,
restore_op_name,
filename_tensor_name,
output_graph_path,
clear_devices,
initializer_nodes)
.pb 文件的路径,您将在该文件中写入图表,并且此.pb 文件未冻结。您将使用tf.train.write_graph() 来编写图表.ckpt file 的路径
pb文件的路径【讨论】:
freeze_graph。您是说它将.ckpt 文件转换为.pb 文件,但input_graph_path 是一个预先存在的.pb 文件的路径?这是哪里来的?