将保存的模型转换为 tflite - 'image_tensor' 的形状无效 '[None, None, None, 3]' [英] Conveting saved model into tflite - 'image_tensor' has invalid shape '[None, None, None, 3]'
问题描述
型号名称:ssd_mobilenet_v1_ppn_cocohttps://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
model name: ssd_mobilenet_v1_ppn_coco https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
我尝试使用以下命令将模型转换为 tflite pb:
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/
出现此错误:
ValueError: None 仅在第一维中受支持.张量image_tensor"的形状无效[None, None, None, 3]".
Got this error:
ValueError: None is only supported in the 1st dimension. Tensor 'image_tensor' has invalid shape '[None, None, None, 3]'.
为了获得有关模型的更多信息,我使用 bazel 从源代码构建了 tensorflow 并运行以下命令:
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/
输出:
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
其他详情:
张量流版本:1.13.1在 python 2.7 和 3.6.5 中运行它.
Other details:
tensorflow version: 1.13.1 Run it both in python 2.7 and 3.6.5.
还尝试使用检查点 (ckpt) 文件而不是保存的模型,但没有奏效.
Also tried to use a checkpoint (ckpt) file and not a saved model, but it did not work.
得到这个结果:ValueError: None 仅在第一维中受支持.张量image_tensor"的形状无效[None, None, None, 3]".
Got this result: ValueError: None is only supported in the 1st dimension. Tensor 'image_tensor' has invalid shape '[None, None, None, 3]'.
预期:两个文件:somefilename.pb somefilename.pbtxt
expected: two files: somefilename.pb somefilename.pbtxt
推荐答案
可以这样转换,
!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.
这篇关于将保存的模型转换为 tflite - 'image_tensor' 的形状无效 '[None, None, None, 3]'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!