tensorflow ssdlite压缩模型transform

下载最新的TensorFlow库
git clone https://github.com/tensorflow/tensorflow.git
./configure
bazel build tensorflow/tools/graph_transforms:transform_graph
bazel build tensorflow/lite/toco:toco 

bazel build tensorflow/python/tools:freeze_graph 

使用ssdlite训练生成的模型,使用research/object_detection/export_tflite_ssd_graph.py转换为tflite_graph.pb、tflite_graph.pbtxt。
然后在tensorflow/tensorflow文件夹中使用命令,将其转换为detect.tflite文件。

bazel run tensorflow/lite/toco:toco --  --input_file=/home/shzy/disks/project/fingerdtpaper/models/data/stept_finger/model/ssdlite/tflite_graph.pb --output_file=/home/shzy/detect.tflite --input_shapes=1,300,300,3 --input_arrays=normalized_input_image_tensor --output_arrays='TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3' --inference_type=QUANTIZED_UINT8 --mean_values=128 --std_values=128 --change_concat_input_ranges=false --allow_custom_ops --default_ranges_min=0 --default_ranges_max=255

bazel run tensorflow/lite/toco:toco --  --input_file=/home/shzy/disks/project/fingerdtpaper/models/data/stept_finger/model/ssdlite/tflite_graph.pb --output_file=/home/shzy/detect_float.tflite --input_shapes=1,300,300,3 --input_arrays=normalized_input_image_tensor --output_arrays='TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3' --inference_type=FLOAT --mean_values=128 --std_values=128 --change_concat_input_ranges=false --allow_custom_ops --default_ranges_min=0 --default_ranges_max=255

如果不转换为tflite文件,可以使用transform_graph转换为
bazel-bin/tensorflow/tools/graph_transforms/transform_graph --in_graph=/home/shzy/frozen_inference_graph.pb --out_graph=/home/shzy/optimized_frozen_inference_graph.pb  --inputs="image_tensor"  --outputs="detection_boxes,detection_classes,detection_scores" --transforms='fold_old_batch_norms quantize_weights strip_unused_nodes sort_by_execution_order merge_duplicate_nodes'
参考的内容是:https://blog.csdn.net/aslily1234/article/details/84840885 https://medium.com/tensorflow/training-and-serving-a-realtime-mobile-object-detector-in-30-minutes-with-cloud-tpus-b78971cf1193

你可能感兴趣的:(深度学习)