当前位置: 首页 > 知识库问答 >
问题:

将保存的模型输入tflite-'image_tensor'的形状无效'[无,无,无,3]'

郎思远
2023-03-14

型号名称: 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:只有第1维度支持无。张量“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

Tensorflow版本:1.13.1在python 2.7和3.6.5中运行它。

还尝试使用检查点(ckpt)文件而不是保存的模型,但没有成功。

得到这个结果:值错误:没有仅在第一维度中受支持。张量“image_tensor”具有无效的形状“[无,无,无,3]”。

预期: 两个文件: 一些文件名.pb 一些文件名.pbtxt

共有2个答案

岑叶秋
2023-03-14

要转换成tflite,你可以点击下面的教程链接。

重新训练的模型转换:转换初始 V3 重新训练的模型

对象检测模型转换:将. pb目标检测文件转换为. tflite文件

沈琨
2023-03-14

你可以这样转换,

!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

最好遵循此链接进行对象检测。

 类似资料:
  • 我不知道如何解决这个错误,我也试着把它转换成float32 Float32 --------------------------------------------------------------------------- ValueError Traceback(最近的调用最后)在11 x=x.astype(Float32)12 print(x.dtype)--- #############

  • 收到以下错误: SQLState[22P02]:无效文本表示:7错误:类型bigint的输入语法无效:“ebbdac9d-3633-43d6-9faf-0d3847fb83d0”(SQL:插入到“objects”(“parent_id”,“team_id”,“objectable_id”,“objectable_type”,“id”,“updated_at”,“created_at”)值(?,4,

  • 问题内容: 我有一个列表,说temp_list具有以下属性: 现在,当我转换为numpy数组时, 我收到错误消息: 有人可以帮我吗? 问题答案: 列表中至少有一项不是三维的,或者其第二维或第三维与其他元素不匹配。如果仅第一维不匹配,则数组仍然匹配,但是作为单独的对象,不会尝试将它们协调为新的(四维)数组。下面是一些示例: 也就是说,冒犯元件的, 或(与是非负整数)。 那就是给你错误的原因。 您需要

  • 当用户输入无效的方向时,只需要一些关于打印一行的指导。我曾尝试在代码的几个不同部分使用if-move-not-in-rooms[position],但似乎无法正常运行。我觉得盯着我看是件很愚蠢的事,但唉,我还在学习。但基本上,当用户输入除北、南、东、西或出口以外的内容时,这是一个打印行的问题。 此外,如果还有更好的方法来编写代码,我会接受批评。谢谢你们!

  • 问题内容: 我是TensorFlow和机器学习的新手。我正在尝试将两个对象归类为杯子和Pendrive(jpeg图像)。我已经成功训练并导出了model.ckpt。现在,我正在尝试恢复保存的model.ckpt以进行预测。这是脚本: 当我运行上述脚本进行预测时,出现以下错误: 我究竟做错了什么?以及如何修复numpy数组的形状? 问题答案: 形状为。 您的输入占位符的形状为。 问题是您要为占位符提

  • 使用以下代码从表中获取数据列表,但获取无效列错误。 例外 表中列为Varchar2 有人知道为什么我们不能根据字符串列获取数据吗?