在 tensorflow 中使用 inception-v3 检查点文件 [英] Using inception-v3 checkpoint file in tensorflow

查看:139
本文介绍了在 tensorflow 中使用 inception-v3 检查点文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个项目中,我使用了一个公开的预训练的 inception-v3 模型,这里提供:http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz.

In one of my project, I used a public pre-trained inception-v3 model available here : http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz.

我只想使用最后一个特征向量(pool_3/_reshape:0 的输出).通过查看脚本示例classify_image.py,我可以成功地通过深度DNN传递图像,提取瓶颈张量(bottleneck_tensor = sess.graph.get_tensor_by_name('pool_3/_reshape:0'))和将其用于其他目的.

I only want to use last feature vector (output of pool_3/_reshape:0). By looking at script example classify_image.py, I can successfully pass an image throught the Deep DNN, extract the bottleneck tensor (bottleneck_tensor = sess.graph.get_tensor_by_name('pool_3/_reshape:0')) and use it for further purpose.

我最近看到有一个更新的训练初始模型.训练检查点可在此处获得:http://download.tensorflow.org/models/image/imagenet/inception-v3-2016-03-01.tar.gz.

I recently saw that there were a more recent trained inception model. Checkpoint of training is available here : http://download.tensorflow.org/models/image/imagenet/inception-v3-2016-03-01.tar.gz.

我想使用这个新的预训练而不是旧的.但是文件格式不同.旧模型"使用易于重用的 ProtocolBuffer 形式(classify_image_graph_def.pb)的图形定义.新的"仅提供检查点格式,我正在努力将其插入到我的代码中.

I would like to use this new pretrained instead of the old one. However file format is different. The "old model" uses a graph def in ProtocolBuffer form (classify_image_graph_def.pb) that is easily reusable. The "new one" only provides a checkpoint format, and I'm struggling to insert it into my code.

是否有一种简单的方法可以将检查点文件转换为随后可用于创建图形的 ProtocolBuffer 文件?

Is there an easy way to convert a checkpoint file to a ProtocolBuffer file that could be then used to create a graph?

推荐答案

看来你必须使用 freeze_graph.py:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py

该脚本将检查点变量转换为独立 GraphDef 文件中的 Const ops.该脚本旨在获取一个 GraphDef proto、一个 SaverDef proto 和一组存储在检查点文件中的变量值,并输出一个 GraphDef,其中所有变量 ops 都转换为包含变量.当我们需要在 C++ 中加载单个文件时,这样做很有用,尤其是在移动或嵌入式等环境中,我们可能无法访问它们所依赖的 RestoreTensor 操作和文件加载调用.

The script converts checkpoint variables into Const ops in a standalone GraphDef file. This script is designed to take a GraphDef proto, a SaverDef proto, and a set of variable values stored in a checkpoint file, and output a GraphDef with all of the variable ops converted into const ops containing the values of the variables. It's useful to do this when we need to load a single file in C++, especially in environments like mobile or embedded where we may not have access to the RestoreTensor ops and file loading calls that they rely on.

命令行用法的一个例子是:

An example of command-line usage is:

bazel build tensorflow/python/tools:freeze_graph && \
bazel-bin/tensorflow/python/tools/freeze_graph \
--input_graph=some_graph_def.pb \
--input_checkpoint=model.ckpt-8361242 \
--output_graph=/tmp/frozen_graph.pb --output_node_names=softmax

这篇关于在 tensorflow 中使用 inception-v3 检查点文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆