使用ssd mobilenet v1将.pb转换为.tflite
使用此命令创建.pb文件
sudo python export_inference_graph.py --input_type image_tensor --pipeline_config_path /home/ubuntu/training/data/ssd_mobilenet_v1_pets.config --trained_checkpoint_prefix /home/ubuntu/training/data/model.ckpt-78386 --output_directory /home/ubuntu/training/ --input_shape 1,300,300,3
then summarize the frozen_inference_graph.pb
它返回此输出
Found 1 possible inputs: (name=image_tensor, type=uint8(4), shape=[1,300,300,3])
No variables spotted.
Found 4 possible outputs: (name=detection_boxes, op=Identity) (name=detection_scores, op=Identity) (name=detection_classes, op=Identity) (name=num_detections, op=Identity)
Found 6130346 (6.13M) const parameters, 0 (0) variable parameters, and 187 control_edges
Op types used: 1781 Const, 255 GatherV2, 230 Identity, 224 Reshape, 207 Minimum, 164 Maximum, 116 Slice, 113 Cast, 103 Mul, 99 Sub, 95 ConcatV2, 88 Greater, 82 Where, 82 Split, 72 Add, 63 Pack, 63 StridedSlice, 50 Shape, 50 Unpack, 45 ExpandDims, 43 Squeeze, 41 ZerosLike, 41 NonMaxSuppressionV3, 39 Fill, 37 Tile, 35 Relu6, 35 FusedBatchNorm, 34 Conv2D, 33 RealDiv, 21 Switch, 16 Range, 13 DepthwiseConv2dNative, 12 BiasAdd, 6 Merge, 6 Sqrt, 3 Assert, 3 Equal, 3 Transpose, 2 Exp, 1 All, 1 TopKV2, 1 Size, 1 Sigmoid, 1 Placeholder
To use with tensorflow/tools/benchmark:benchmark_model try these arguments:
bazel run tensorflow/tools/benchmark:benchmark_model -- --graph=/home/jayasri/Downloads/ssd_mobilenet_v1_quantized_300x300_coco14_sync_2018_07_18/original/frozen_inference_graph.pb --show_flops --input_layer=image_tensor --input_layer_type=uint8 --input_layer_shape=1,300,300,3 --output_layer=detection_boxes,detection_scores,detection_classes,num_detections
然后尝试使用bazel-bin / tensorflow / lite / toco / toco转换tflite
但是我遇到了这个错误
tensorflow/lite/toco/import_tensorflow.cc:1336] Converting unsupported operation: Size
2019-05-29 15:46:02.589145: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 2780 operators, 4997 arrays (0 quantized)
2019-05-29 15:46:02.794908: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 2741 operators, 4915 arrays (0 quantized)
2019-05-29 15:46:03.070306: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 2741 operators, 4915 arrays (0 quantized)
2019-05-29 15:46:03.162066: F tensorflow/lite/toco/graph_transformations/resolve_constant_slice.cc:59] Check failed: dim_size >= 1 (0 vs. 1)
预期结果:
2019-05-29 16:14:12.900725: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After quantization graph transformations pass 2: 71 operators, 183 arrays (155 quantized)
2019-05-29 16:14:12.907202: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After quantization graph transformations pass 3: 66 operators, 178 arrays (157 quantized)
2019-05-29 16:14:12.913353: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After quantization graph transformations pass 4: 66 operators, 178 arrays (158 quantized)
2019-05-29 16:14:12.918737: W tensorflow/lite/toco/graph_transformations/quantize.cc:132] Constant array anchors lacks MinMax information. To make up for that, we will now compute the MinMax from actual array elements. That will result in quantization parameters that probably do not match whichever arithmetic was used during training, and thus will probably be a cause of poor inference accuracy.
2019-05-29 16:14:12.919564: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After quantization graph transformations pass 5: 64 operators, 176 arrays (159 quantized)
2019-05-29 16:14:12.926182: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before shuffling of FC weights: 64 operators, 176 arrays (159 quantized)
2019-05-29 16:14:12.928728: I tensorflow/lite/toco/allocate_transient_arrays.cc:345] Total transient array allocated size: 2880000 bytes, theoretical optimal value: 2160000 bytes.
2019-05-29 16:14:12.929046: I tensorflow/lite/toco/toco_tooling.cc:433] Estimated count of arithmetic ops: 2.49483 billion (note that a multiply-add is counted as 2 ops)
我收到此错误:
tensorflow/lite/toco/import_tensorflow.cc:1336] Converting unsupported operation: Size
2019-05-29 15:46:02.589145: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 2780 operators, 4997 arrays (0 quantized)
2019-05-29 15:46:02.794908: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 2741 operators, 4915 arrays (0 quantized)
2019-05-29 15:46:03.070306: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 2741 operators, 4915 arrays (0 quantized)
2019-05-29 15:46:03.162066: F tensorflow/lite/toco/graph_transformations/resolve_constant_slice.cc:59] Check failed: dim_size >= 1 (0 vs. 1)