问题
Trying to convert saved model into tflite.
model name: ssd_mobilenet_v1_ppn_coco https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
I have tried converting the model to tflite pb with this command:
$tflite_convert --output_file=/tmp/dec.tflite
--saved_model_dir=/ppn/saved_model/
Got this error:
ValueError: None is only supported in the 1st dimension. Tensor 'image_tensor' has invalid shape '[None, None, None, 3]'.
In order to get more info about the model, I've built tensorflow from source with bazel and run the following:
$ bazel build tensorflow/tools/graph_transforms:summarize_graph
bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --
in_graph=/Users/nadav/Desktop/tflite/
output:
found 1 possible inputs: (name=image_tensor, type=uint8(4), shape=[?,?,?,3])
No variables spotted.
Found 4 possible outputs: (name=detection_boxes, op=Identity) (name=detection_scores, op=Identity) (name=num_detections, op=Identity) (name=detection_classes, op=Identity)
Found 2197495 (2.20M) const parameters, 0 (0) variable parameters, and 2089 control_edges
Op types used: 2325 Const, 549 GatherV2, 451 Minimum, 360 Maximum, 287 Reshape, 191 Sub, 183 Cast, 183 Greater, 180 Split, 180 Where, 119 StridedSlice, 116 Shape, 109 Pack, 101 ConcatV2, 99 Add, 96 Mul, 94 Unpack, 93 Slice, 92 ZerosLike, 91 Squeeze, 90 NonMaxSuppressionV2, 36 Identity, 30 Conv2D, 29 Switch, 29 Relu6, 26 Enter, 24 BiasAdd, 17 FusedBatchNorm, 14 Merge, 13 RealDiv, 12 Range, 11 DepthwiseConv2dNative, 11 TensorArrayV3, 8 ExpandDims, 8 NextIteration, 6 TensorArrayGatherV3, 6 TensorArrayWriteV3, 6 Exit, 6 TensorArraySizeV3, 5 TensorArrayReadV3, 5 MaxPool, 5 TensorArrayScatterV3, 4 Fill, 3 Assert, 3 Transpose, 2 Less, 2 Equal, 2 Exp, 2 LoopCond, 1 Tile, 1 TopKV2, 1 Placeholder, 1 ResizeBilinear, 1 Size, 1 Sigmoid
To use with tensorflow/tools/benchmark:benchmark_model try these arguments:
bazel run tensorflow/tools/benchmark:benchmark_model -- --graph=/ppn/frozen_inference_graph.pb
--show_flops
--input_layer=image_tensor
--input_layer_type=uint8
--input_layer_shape=-1,-1,-1,3
--output_layer=detection_boxes,detection_scores,num_detections,detection_classes
Other details:
tensorflow version: 1.13.1 Run it both in python 2.7 and 3.6.5.
Also tried to use a checkpoint (ckpt) file and not a saved model, but it did not work.
Got this result: ValueError: None is only supported in the 1st dimension. Tensor 'image_tensor' has invalid shape '[None, None, None, 3]'.
expected: two files: somefilename.pb somefilename.pbtxt
回答1:
You can convert like this,
!tflite_convert --output_file model.tflite \
--saved_model_dir ssd_mobilenet_v1_ppn_shared_box_predictor_300x300_coco14_sync_2018_07_03/saved_model/ \
--output_format TFLITE \
--inference_type FLOAT \
--input_arrays image_tensor \
--input_shapes 1,300,300,3 \
--output_arrays detection_boxes,detection_classes,detection_scores,num_detections
Better to follow this link for object detection.
回答2:
For conversion into tflite you can follow the following tutorial link.
Retrained model conversion:Convert Inception-V3 retrained model
Object Detection Model Conversion: Convert .pb object detection file to .tflite file
来源:https://stackoverflow.com/questions/55617257/conveting-saved-model-into-tflite-image-tensor-has-invalid-shape-none-non