tensorflow-yolov3 icon indicating copy to clipboard operation
tensorflow-yolov3 copied to clipboard

怎么pb转tflite

Open panguxiaoshen opened this issue 6 years ago • 18 comments

调用函数:tf.contrib.lite.TFLiteConverter.from_frozen_graph 报错: 2019-07-10 03:18:33.807555: F tensorflow/lite/toco/graph_transformations/resolve_strided_slice_attributes.cc:95] Check failed: start_indices_size <= num_input_axes (2 vs. 1)StridedSlice op requires no more than 1 start indices

作者尝试过转换吗?

panguxiaoshen avatar Jul 10 '19 07:07 panguxiaoshen

pb_file = "../my_yolov3_coco.pb"
input_arrays = ["input/input_data"]
output_arrays = ["pred_sbbox/concat_2", "pred_mbbox/concat_2", "pred_lbbox/concat_2"]

converter = tf.lite.TFLiteConverter.from_frozen_graph(pb_file, input_arrays, output_arrays, {"input/input_data" :[1, 416, 416, 3]})
tflite_model = converter.convert()
open("myModel.tflite", "wb").write(tflite_model)

遇到同样的问题

dvlee1024 avatar Jul 11 '19 02:07 dvlee1024

@dvlee1024 您好我也想转一下部署在安卓上,之前没有做过,请问你转好了吗

lukaisheng1203 avatar Jul 17 '19 15:07 lukaisheng1203

找到问题所在了,在模型里面作者扩展tensor维数通过tf.newaxis实现,转tflite会一直报上述的错误。通过tf.expand_dims来实现tensor扩维就可以转成功了。(这部分在def decode()函数里面) @dvlee1024 @airu924123

panguxiaoshen avatar Jul 18 '19 07:07 panguxiaoshen

补充:虽然可以生成tflite,但在调用是会报._interpreter.allocate_tensors()的相关错误:StridedSlice op only supports 1D-4D input arrays.Node number 43 (STRIDED_SLICE) failed to prepare. 所以相关运算中需要把5维改成4维,应该就可以了,尝试中。。。

panguxiaoshen avatar Jul 18 '19 11:07 panguxiaoshen

@panguxiaoshen 大佬您好,请问有什么update吗?感谢!

yuanzhedong avatar Jul 27 '19 01:07 yuanzhedong

@panguxiaoshen 大佬您好,请问有什么update吗?感谢!

按照我上面说的改就行,我已经成功转换。tiny_tolov3可以在板子上跑50ms

panguxiaoshen avatar Jul 29 '19 02:07 panguxiaoshen

@panguxiaoshen 大佬您好,请问有什么update吗?感谢!

我已经上传到 https://github.com/panguxiaoshen/tiny_yolov3

panguxiaoshen avatar Aug 02 '19 02:08 panguxiaoshen

@panguxiaoshen 万分感谢!我回来试一下

yuanzhedong avatar Aug 02 '19 05:08 yuanzhedong

Hi, I encounter the same error message than in the original issue. Have you found a solution or a workaround ?

pauqilaz avatar Sep 06 '19 11:09 pauqilaz

Hi, I encounter the same error message than in the original issue. Have you found a solution or a workaround ?

There are two places to change in the code. When you are expanding the dimensions of tensor,you should use "tf.expand_dims" rather than "tf.newaxis". Another thing is , so far ,tflite op only supports 1D-4D input arrays, but in Yunyang1994's code, there exists 5D operations. If you want to solve the problem, you can refer to the link mentioned above.

panguxiaoshen avatar Sep 11 '19 01:09 panguxiaoshen

Solution is here: https://github.com/peace195/tensorflow-lite-yolo-v3 The .pb file must be in right format of SavedModel. Please try it. I would appreciate if you give me a star for this project 👍

peace195 avatar Oct 20 '19 16:10 peace195

dear @peace195 :+1: how can I get the right format (.pb) from training the Yolo v3 model here, not from the original https://pjreddie.com/darknet/yolo/. thanks in advance.

kerolos avatar Nov 08 '19 08:11 kerolos

@kerolos Please use this code: https://github.com/peace195/tensorflow-lite-yolo-v3/blob/master/convert_weights_pb.py

peace195 avatar Nov 08 '19 08:11 peace195

转成功了我在为这个问题烦恼,可以加下微信吗?15348365038

774219268 avatar Nov 20 '19 07:11 774219268

@panguxiaoshen 大佬您好,请问有什么update吗?感谢!

我已经上传到 https://github.com/panguxiaoshen/tiny_yolov3

参考了你的代码,绕过5D -> 4D的方法很棒。

tongda avatar Mar 03 '20 06:03 tongda

@panguxiaoshen 大佬您好,请问有什么update吗?感谢!

我已经上传到 https://github.com/panguxiaoshen/tiny_yolov3

参考了你的代码,绕过5D -> 4D的方法很棒。

请问,哪个文件里有5D操作? train.py吗?

netist123 avatar Mar 06 '20 13:03 netist123

不是什么大佬,互相学习,可以加我微信15348365038互相探讨,都是慢慢测试出来的

------------------ 原始邮件 ------------------ 发件人: "netist123"<[email protected]>; 发送时间: 2020年3月6日(星期五) 晚上9:46 收件人: "YunYang1994/tensorflow-yolov3"<[email protected]>; 抄送: "烧火棍"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [YunYang1994/tensorflow-yolov3] 怎么pb转tflite (#232)

@panguxiaoshen 大佬您好,请问有什么update吗?感谢!

我已经上传到 https://github.com/panguxiaoshen/tiny_yolov3

参考了你的代码,绕过5D -> 4D的方法很棒。

请问,哪个文件里有5D操作? train.py吗?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

774219268 avatar Mar 06 '20 13:03 774219268

@panguxiaoshen 大佬您好,请问有什么update吗?感谢!

我已经上传到 https://github.com/panguxiaoshen/tiny_yolov3

参考了你的代码,绕过5D -> 4D的方法很棒。

请问,哪个文件里有5D操作? train.py吗?

yolov3.py里面,从下面这行开始:

conv_output = tf.reshape(conv_output, (batch_size, output_size, output_size, 2, 5 + NUM_CLASS))

就都是5D操作了。

tongda avatar Mar 13 '20 03:03 tongda