如何使用transform_graph优化Tensorflow模型 [英] How to use transform_graph to optimize Tensorflow model

查看:906
本文介绍了如何使用transform_graph优化Tensorflow模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经使用optimize_for_inference库来优化冻结的Tensorflow模型.但是,我从不同的来源了解到Tensorflow不再支持它.

I used to use the optimize_for_inference library in optimizing frozen Tensorflow models. However, I have read from different sources that Tensorflow no longer supports it.

我遇到了transform_graph,其文档位于此处:

I came across transform_graph, and its documentation is found here: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#strip_unused_nodes

起初,我遇到错误,发现我需要从源代码安装Tensorflow( https://www.tensorflow.org/install/install_sources#install_the_pip_package ),而不是使用PIP.

At first, I ran into errors and found out that I need to install Tensorflow from source (https://www.tensorflow.org/install/install_sources#install_the_pip_package) instead of using PIP.

我已经从源代码重新安装了Tensorflow,并在bash(/tensorflor/tensorflow目录)中运行了以下代码:

I already re-installed Tensorflow from source, and ran this code in bash (/tensorflor/tensorflow dir):

bazel build tensorflow/tools/graph_transforms:transform_graph
bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph=tensorflow_inception_graph.pb \
--out_graph=optimized_inception_graph.pb \
--inputs='Mul' \
--outputs='softmax' \
--transforms='
  strip_unused_nodes(type=float, shape="1,299,299,3")
  fold_constants(ignore_errors=true)
  fold_batch_norms
  fold_old_batch_norms
  round_weights(num_steps=256)'

然后再次运行此错误:

-bash:bazel-bin/tensorflow/tools/graph_transforms/transform_graph:没有这样的文件或目录

-bash: bazel-bin/tensorflow/tools/graph_transforms/transform_graph: No such file or directory

问题出在哪里?

推荐答案

那很奇怪.

我在下面编写的代码是在CentOS7中安装和使用transform_graph.

The code I write below is to install and using the transform_graph in CentOS7.

yum install epel-release 百胜更新 百胜安装补丁 curl https://copr .fedorainfracloud.org/coprs/vbatts/bazel/repo/epel-7/vbatts-bazel-epel-7.repo -o/etc/yum.repos.d/vbatts-bazel-epel-7.repo yum install bazel

yum install epel-release yum update yum install patch curl https://copr.fedorainfracloud.org/coprs/vbatts/bazel/repo/epel-7/vbatts-bazel-epel-7.repo -o /etc/yum.repos.d/vbatts-bazel-epel-7.repo yum install bazel

curl -L -O https://github.com/tensorflow/tensorflow/archive/v1.8.0.tar.gz

curl -L -O https://github.com/tensorflow/tensorflow/archive/v1.8.0.tar.gz

cd tensorflow-1.8.0

cd tensorflow-1.8.0

./configure#互动!

./configure # interactive!

bazel构建tensorflow/tools/graph_transforms:summarize_graph bazel-bin/tensorflow/tools/graph_transforms/summarize_graph

bazel build tensorflow/tools/graph_transforms:summarize_graph bazel-bin/tensorflow/tools/graph_transforms/summarize_graph

通过源代码安装Tensorflow并完成配置后,Bazel代码应该可以正常工作.

After you install the Tensorflow by source code and finish the configure, the bazel codes should be working.

如果您未按源代码完成Tensorflow的安装,或者您在错误的路径中运行了脚本,则会发生环境错误.

The error from you environment is occurred when you didn't finish the install the Tensorflow by source code, or you ran the script in wrong path.

请检查Tensorflow根的配置步骤,路径.

Please check the configure step, path of the Tensorflow root.

这篇关于如何使用transform_graph优化Tensorflow模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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