tensorflow优化

来源:互联网 发布:机房网络改造注意事项 编辑:程序博客网 时间:2024/06/16 09:10
源码位置:
tensorflow/python/tools
tensorflow/tools/quantization

bin位置:
bazel-bin/tensorflow/python/tools
bazel-bin/tensorflow/tools/

输出pb类型graph:

from tensorflow.python.framework import graph_iograph_io.write_graph(self.sess.graph,"./tests/", "input_graph.pb")

固化freeze_graph

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

例如:

bazel-bin/tensorflow/python/tools/freeze_graph--input_graph=./input_graph.pb--input_checkpoint=./VGGnet_fast_rcnn_iter_52700.ckpt --output_graph=./froze_graph1.pb --output_node_names=rois/Reshape,rois/PyFunc

 

优化optimize_for_inference

 

bazel build tensorflow/python/tools:optimize_for_inference&& \bazel-bin/tensorflow/python/tools/optimize_for_inference \--input=frozen_inception_graph.pb \--output=optimized_inception_graph.pb \--frozen_graph=True \--input_names=Mul \--output_names=softmax

例如:

bazel-bin/tensorflow/python/tools/optimize_for_inference--input=froze_ctc.pb--output=optimized_ctc.pb--frozen_graph=True --input_names=Placeholder,seq_len--output_names=CTCGreedyDecoder--placeholder_type_enum=13

13的原理如下:

from tensorflow.python.framework import dtypesprint(dtypes.float32.as_datatype_enum)#1print(dtypes.int32.as_datatype_enum)#3


量化quantize_graph

 

bazel build tensorflow/tools/quantization:quantize_graph \&&bazel-bin/tensorflow/tools/quantization/quantize_graph \--input=tensorflow_inception_graph.pb--output_node_names="softmax2" --print_nodes--output=/tmp/quantized_graph.pb \--mode=eightbit--logtostderr

例如:
bazel-bin/tensorflow/tools/quantization/quantize_graph--input=./optimized_ctc.pb--output_node_names=CTCGreedyDecoder--print_nodes--output=./quantized_graph.pb--mode=eightbit--logtostderr

Tensorboard查看pb文件:

tensorflow/python/tools /import_pb_to_tensorboard.py

查看节点计算时间profile:

bazel build -c opt tensorflow/tools/benchmark:benchmark_model&& \bazel-bin/tensorflow/tools/benchmark/benchmark_model \--graph=/tmp/tensorflow_inception_graph.pb--input_layer="Mul" \--input_layer_shape="1,299,299,3" --input_layer_type="float" \--output_layer="softmax:0" --show_run_order=false --show_time=false \--show_memory=false --show_summary=true --show_flops=true --logtostderr



原创粉丝点击