Ncnn: keras转onnx后再用onnx2ncnn转换,出现flatten not supported axis=0错误

Created on 14 Jan 2019  ·  5Comments  ·  Source: Tencent/ncnn

原keras模型有个flatten层:输入:[2,2,20],格式:channels last。输出:80
转换onnx成功,但在onnx2ncnn转换时,报错:
unsupported flatten axis = 0
identity not supported yet
请教,目前ncnn支持keras转换过来的这种格式的flatten吗?如果不支持,怎么修改?
我目前打算修改ncnn读入flatten层部分的代码,不知能否实现。

Most helpful comment

All 5 comments

axis=0 警告暂时无视
identity 可以用 onnx optimizer 提前去掉

axis=0 警告暂时无视
identity 可以用 onnx optimizer 提前去掉

非常感谢,已经转换成功!

你好,我也在尝试keras2onnx2ncnn,我也是keras的flatten层出现问题,如下所述:

1、在keras2onnx之后,发现flatten层被分割成很多层,如下
%TFNodes_pool2_MaxPool_0 = Identity(%pool2_MaxPool_0)
%TFNodes_flatten_stack_Unsqueeze__12_0 = Unsqueezeaxes = [0]
%TFNodes_flatten_Shape_0 = Shape(%TFNodes_pool2_MaxPool_0)
%TFNodes_flatten_Shape__7_0 = Castto = 1
%TFNodes_flatten_strided_slice_0 = Slice(%TFNodes_flatten_Shape__7_0, %const_slice__8, const_slice__9, %const_slice__10)
%TFNodes_flatten_strided_slice__11_0 = Castto = 6
%TFNodes_flatten_Prod_0 = ReduceProd[axes = [0], keepdims = 0]
(%TFNodes_flatten_strided_slice__11_0)
%TFNodes_flatten_stack_Unsqueeze__13_0 = Unsqueezeaxes = [0]
%TFNodes_flatten_stack_Concat__14_0 = Concataxis = 0
%TFNodes_flatten_Reshape__15_0 = Castto = 7
%TFNodes_flatten_Reshape_0 = Reshape(%TFNodes_pool2_MaxPool_0,
%TFNodes_flatten_Reshape__15_0)
感觉不是很正常,因为其他卷积层池化层等转换后还是一层,所以想请问flatten层转换后被拆分是正常的吗?
2、在使用onnx2ncnn.exe时,出现如下报错:
Identity not supported yet!
Unsqueeze not supported yet!
# axes 7
Shape not supported yet!
Cast not supported yet!
# to=1
Cast not supported yet!
# to=6
ReduceProd not supported yet!
# axes 7
# keepdims=0
Unsqueeze not supported yet!
# axes 7
Cast not supported yet!
# to=7
Identity not supported yet!
可以发现除了Identity层外,其他不支持的层都是flaten的拆分层,向请问这个问题怎么解决。
3、我参考了你的csdn帖子去除identity层,报错如下:
Traceback (most recent call last):
File "G:/keras/FE_LeNet/keras_to_onnx.py", line 26, in
optimized_model = optimizer.optimize(onnx_model, passes)
File "F:\Anaconda3\lib\site-packages\onnx\optimizer.py", line 55, in optimize
optimized_model_str = C.optimize(model_str, passes)
IndexError: invalid unordered_map key
程序基本跟官方的一样,想请问这个报错如何处理。

谢谢!

image

求问这个怎么解决啊,有影响吗

Was this page helpful?
0 / 5 - 0 ratings