|
转 pytorch 模型的时候遇到很多错,就把 op 一个一个拿出来试试。遇到 nn.Upsamle 和 nn.MaxPool2d 转换失败。
Upsample 的模型:
- from torch import nn
- import torch
- model_name = "little_model_upsample"
- ONNX_MODEL = model_name + '.onnx'
- RKNN_MODEL = model_name + '.rknn'
- class Identity(nn.Module):
- def __init__(self, ):
- super(Identity, self).__init__()
-
- self.upsample = nn.Upsample(scale_factor=2, mode='nearest')
- def forward(self, x):
-
- x = self.upsample(x)
- return x
MaxPool2 的模型
- class Identity(nn.Module):
- def __init__(self, ):
- super(Identity, self).__init__()
- self.downsample = nn.MaxPool2d(kernel_size=2)
- def forward(self, x):
- x = self.downsample(x)
- return x
nn.Upsample, 试过 pytorch -> onnx -> rknn, pytorch -> rknn, 都失败
pytorch -> onnx -> rknn 的报错
W Not match tensor Upsample_17ut0
E Try match Upsample_17ut0 failed, catch exception!
W ----------------Warning(1)----------------
E Catch exception when loading onnx model: little_model_upsample.onnx!
E Traceback (most recent call last):
E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 1071, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx.match_paragraph_and_param
E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 980, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx._onnx_push_ready_tensor
E TypeError: 'NoneType' object is not iterable
E During handling of the above exception, another exception occurred:
E Traceback (most recent call last):
E File "rknn/api/rknn_base.py", line 513, in rknn.api.rknn_base.RKNNBase.load_onnx
E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 1077, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx.match_paragraph_and_param
E File "rknn/api/rknn_log.py", line 312, in rknn.api.rknn_log.RKNNLog.e
E ValueError: Try match Upsample_17ut0 failed, catch exception!
pytorch -> rknn 的报错
--> Building model
W The target_platform is not set in config, using default target platform rk1808.
W Genreate input meta fail, please check model.
W External input meta file "/tmp/tmp854pv7am/little_model_upsample_inputmeta.yml" is not exists.
Traceback (most recent call last):
File "little_model_upsample_torch_to_rknn.py", line 55, in <module>
ret = rknn.build(do_quantization=False, dataset='./dataset.txt')
File "/data01/wens/venv/rknn/lib/python3.6/site-packages/rknn/api/rknn.py", line 240, in build
ret = self.rknn_base.build(do_quantization=do_quantization, dataset=dataset, pack_vdata=pre_compile, batch_size=rknn_batch_size)
File "rknn/api/rknn_base.py", line 791, in rknn.api.rknn_base.RKNNBase.build
File "rknn/api/rknn_base.py", line 2328, in rknn.api.rknn_base.RKNNBase._generate_inputmeta
IndexError: list index out of range
MaxPool2, pytorch -> onnx -> rknn 失败,pytorch -> rknn成功
pytorch -> onnx -> rknn 报错
E Catch exception when loading onnx model: little_model_downsample.onnx!
E Traceback (most recent call last):
E File "rknn/api/rknn_base.py", line 524, in rknn.api.rknn_base.RKNNBase.load_onnx
E File "rknn/base/RKNNlib/switcher/mode_switcher.py", line 325, in rknn.base.RKNNlib.switcher.mode_switcher.C2T_Switcher.switch
E File "rknn/base/RKNNlib/switcher/mode_switcher.py", line 292, in rknn.base.RKNNlib.switcher.mode_switcher.ModeSwitcher.build_mark
E File "rknn/base/RKNNlib/switcher/mode_switcher.py", line 276, in rknn.base.RKNNlib.switcher.mode_switcher.ModeSwitcher.set_net_layout
E File "rknn/base/RKNNlib/core/shape.py", line 35, in rknn.base.RKNNlib.core.shape.Shape.length
E File "rknn/base/RKNNlib/core/shape.py", line 30, in rknn.base.RKNNlib.core.shape.Shape.dim_num
E TypeError: '>=' not supported between instances of 'list' and 'int'
Load resnet50v2 failed!
谢谢
|
|