【问题标题】:Conveting saved model into tflite - 'image_tensor' has invalid shape '[None, None, None, 3]'将保存的模型转换为 tflite - 'image_tensor' 的形状无效 '[None, None, None, 3]'
【发布时间】:2019-09-01 04:33:39
【问题描述】:

尝试将保存的模型转换为 tflite。

型号名称:ssd_mobilenet_v1_ppn_coco https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md

我尝试使用以下命令将模型转换为 tflite pb:

$tflite_convert   --output_file=/tmp/dec.tflite  
 --saved_model_dir=/ppn/saved_model/

得到这个错误:

ValueError: None 仅在第一维中受支持。张量“image_tensor”的形状无效“[None, None, None, 3]”。

为了获取有关模型的更多信息,我使用 bazel 从源代码构建了 tensorflow 并运行以下命令:

$ 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 中运行它。

还尝试使用检查点 (ckpt) 文件而不是保存的模型,但它不起作用。

得到这个结果: ValueError: None 仅在第一维中受支持。张量“image_tensor”的形状无效“[None, None, None, 3]”。

预计: 两个文件:somefilename.pb somefilename.pbtxt

【问题讨论】:

    标签: tensorflow-lite


    【解决方案1】:

    你可以这样转换,

    !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
    

    最好按照link 进行对象检测。

    【讨论】:

    • 有一个问题:检查失败:array.data_type == array.final_data_type 数组“image_tensor”的实际和最终数据类型不匹配(data_type=uint8,final_data_type=float)。
    • 嘿@Novice,您找到解决问题的方法了吗?我也面临同样的问题。
    • 是的,我能够将 .pb 文件转换为 .tflite 文件。
    【解决方案2】:

    要转换为 tflite,您可以按照以下教程链接进行操作。

    再训练模型转换:Convert Inception-V3 retrained model

    对象检测模型转换: Convert .pb object detection file to .tflite file

    【讨论】:

      猜你喜欢
      • 2019-06-11
      • 1970-01-01
      • 2021-07-07
      • 2021-12-05
      • 1970-01-01
      • 1970-01-01
      • 2020-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多