rknn_model_zoo icon indicating copy to clipboard operation
rknn_model_zoo copied to clipboard

导出.torchscript成功,转换rknn失败

Open zhaotun opened this issue 2 years ago • 2 comments

根据 airockchip/yolov5 使用

python export.py --rknpu rk3399pro

命令成功导出了 yolov5s.torchscript , 然后在rknn-toolkit-1.7.0 的docker里,进入

rknn_model_zoo/models/CV/object_detection/yolo/RKNN_model_convert

yolov5_yolov7.yml内容为:

model_name: yolov5_yolov7
model_framework: pytorch
model_file_path: yolov5s.torchscript
RK_device_platform: RK3399PRO
RK_device_id: simulator
dataset: ../../../../../datasets/COCO/coco_dataset_20.txt
quantize: False
pre_compile: online

graph:
  in_0:
    shape: 3,640,640
    mean_values: 0
    std_values: 255
    img_type: RGB

configs:
  quantized_dtype: asymmetric_quantized-8
  quantized_algorithm: normal
  optimization_level: 3

执行

./convert_yolov5_yolov7.sh 

报以下错误

|| ./../../../../../datasets/COCO/val2017/000000468505.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000570664.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000359781.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000521819.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000001818.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000369675.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000017627.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000039956.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000430875.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000057672.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000157213.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000481480.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000577539.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000406570.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000300659.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000078032.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000471756.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000270402.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000174482.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000193884.jpg || input path in dataset.txt not exist, compute convert loss will be failed
========== parser_config ==========
NPU_VERSION: 1
RK_device_platform: RK3399PRO
input_example: [{'in_0': './../../../../../datasets/COCO/val2017/000000468505.jpg'}, {'in_0': './../  ...
pre_compile: online
core_mask: 1
config:
  target_platform: RK3399PRO
  quantized_dtype: asymmetric_affine-u8
  quantized_algorithm: normal
  optimization_level: 3
  mean_values: [[0, 0, 0]]
  std_values: [[255, 255, 255]]
  mmse_epoch: 3
  do_sparse_network: True
  output_optimize: 0
  batch_size: 100
  quantize_input_node: False
  merge_dequant_layer_and_output_node: False
  force_builtin_perm: False
  reorder_channel: 0 1 2
export_rknn:
  export_path: ./model_cvt/RK1808_3399pro/yolov5_yolov7_RK1808_3399pro_fp.rknn
verbose: False
dataset: ./../../../../../datasets/COCO/coco_dataset_20.txt
quantize: False
build:
  do_quantization: False
  dataset: ./../../../../../datasets/COCO/coco_dataset_20.txt
model_framework: pytorch
qnnpack: False
load:
  model: ./yolov5s.torchscript
  input_size_list: [[3, 640, 640]]
inputs:
  in_0:
    shape: [3, 640, 640]
    mean_values: [0, 0, 0]
    std_values: [255, 255, 255]
    img_type: RGB
outputs:
RK_device_id: simulator
export_pre_compile_path: ./model_cvt/RK1808_3399pro/yolov5_yolov7_RK1808_3399pro_fp_precompile.rknn
===================================
---> Create RKNN object
---> Seting RKNN config
Traceback (most recent call last):
  File "../../../../../common/rknn_converter/rknn_convert.py", line 79, in <module>
    convert(config_dict, args)
  File "../../../../../common/rknn_converter/rknn_convert.py", line 19, in convert
    rknn = cp.convert()
  File "/test/rknn_model_zoo/common/rknn_converter/phase.py", line 96, in convert
    rknn.config(**model_config_dict['config'])
TypeError: config() got an unexpected keyword argument 'quantize_input_node'

在rknn-toolkit-1.7.3 的docker里执行,报以下错误

|| ./../../../../../datasets/COCO/val2017/000000468505.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000570664.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000359781.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000521819.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000001818.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000369675.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000017627.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000039956.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000430875.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000057672.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000157213.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000481480.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000577539.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000406570.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000300659.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000078032.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000471756.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000270402.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000174482.jpg || input path in dataset.txt not exist, compute convert loss will be failed
|| ./../../../../../datasets/COCO/val2017/000000193884.jpg || input path in dataset.txt not exist, compute convert loss will be failed
========== parser_config ==========
NPU_VERSION: 1
RK_device_platform: RK3399PRO
input_example: [{'in_0': './../../../../../datasets/COCO/val2017/000000468505.jpg'}, {'in_0': './../  ...
pre_compile: online
core_mask: 1
config:
  target_platform: RK3399PRO
  quantized_dtype: asymmetric_affine-u8
  quantized_algorithm: normal
  optimization_level: 3
  mean_values: [[0, 0, 0]]
  std_values: [[255, 255, 255]]
  mmse_epoch: 3
  do_sparse_network: True
  output_optimize: 0
  batch_size: 100
  quantize_input_node: False
  merge_dequant_layer_and_output_node: False
  force_builtin_perm: False
  reorder_channel: 0 1 2
export_rknn:
  export_path: ./model_cvt/RK1808_3399pro/yolov5_yolov7_RK1808_3399pro_fp.rknn
verbose: False
dataset: ./../../../../../datasets/COCO/coco_dataset_20.txt
quantize: False
build:
  do_quantization: False
  dataset: ./../../../../../datasets/COCO/coco_dataset_20.txt
model_framework: pytorch
qnnpack: False
load:
  model: ./yolov5s.torchscript
  input_size_list: [[3, 640, 640]]
inputs:
  in_0:
    shape: [3, 640, 640]
    mean_values: [0, 0, 0]
    std_values: [255, 255, 255]
    img_type: RGB
outputs:
RK_device_id: simulator
export_pre_compile_path: ./model_cvt/RK1808_3399pro/yolov5_yolov7_RK1808_3399pro_fp_precompile.rknn
===================================
---> Create RKNN object
---> Seting RKNN config
---> Loading pytorch model
./yolov5s.torchscript ********************
E Catch exception when loading pytorch model: ./yolov5s.torchscript!
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 399, in rknn.api.rknn_base.RKNNBase.load_pytorch
E   File "rknn/base/RKNNlib/RK_nn.py", line 161, in rknn.base.RKNNlib.RK_nn.RKnn.load_pytorch
E   File "rknn/base/RKNNlib/app/importer/import_pytorch.py", line 129, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run
E   File "rknn/base/RKNNlib/converter/convert_pytorch_new.py", line 5113, in rknn.base.RKNNlib.converter.convert_pytorch_new.convert_pytorch.load
E   File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 275, in load
E     cpp_module = torch._C.import_ir_module(cu, f, map_location, _extra_files)
E RuntimeError: 
E aten::_convolution(Tensor input, Tensor weight, Tensor? bias, int[] stride, int[] padding, int[] dilation, bool transposed, int[] output_padding, int groups, bool benchmark, bool deterministic, bool cudnn_enabled) -> (Tensor):
E Expected at most 12 arguments but found 13 positional arguments.
E :
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/nn/modules/conv.py(439): _conv_forward
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/nn/modules/conv.py(443): forward
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/nn/modules/module.py(1039): _slow_forward
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/nn/modules/module.py(1051): _call_impl
E /home/hhit/alg_sun/rk3399pro/yolov5-master-airockchip/yolov5-master/models/common.py(47): forward
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/nn/modules/module.py(1039): _slow_forward
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/nn/modules/module.py(1051): _call_impl
E /home/hhit/alg_sun/rk3399pro/yolov5-master-airockchip/yolov5-master/models/common_rk_plug_in.py(30): forward
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/nn/modules/module.py(1039): _slow_forward
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/nn/modules/module.py(1051): _call_impl
E /home/hhit/alg_sun/rk3399pro/yolov5-master-airockchip/yolov5-master/models/yolo.py(112): _forward_once
E /home/hhit/alg_sun/rk3399pro/yolov5-master-airockchip/yolov5-master/models/yolo.py(199): forward
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/nn/modules/module.py(1039): _slow_forward
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/nn/modules/module.py(1051): _call_impl
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/jit/_trace.py(952): trace_module
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/jit/_trace.py(735): trace
E export.py(110): export_torchscript
E export.py(598): run
E /home/hhit/anaconda3/envs/yolov5_torch1.9_py3.8/lib/python3.8/site-packages/torch/autograd/grad_mode.py(28): decorate_context
E export.py(682): main
E export.py(688): <module>
E Serialized   File "code/__torch__/torch/nn/modules/conv.py", line 11
E     argument_1: Tensor) -> Tensor:
E     _0 = self.bias
E     input = torch._convolution(argument_1, self.weight, _0, [1, 1], [1, 1], [1, 1], False, [0, 0], 1, False, False, True, True)
E             ~~~~~~~~~~~~~~~~~~ <--- HERE
E     return input
E Please feedback the detailed log file <log_feedback_to_the_rknn_toolkit_dev_team.log> to the RKNN Toolkit development team.
E You can also check github issues: https://github.com/rockchip-linux/rknn-toolkit/issues
---> Building
Traceback (most recent call last):
  File "../../../../../common/rknn_converter/rknn_convert.py", line 79, in <module>
    convert(config_dict, args)
  File "../../../../../common/rknn_converter/rknn_convert.py", line 19, in convert
    rknn = cp.convert()
  File "/test/rknn_model_zoo/common/rknn_converter/phase.py", line 106, in convert
    rknn.build(**model_config_dict['build'])
  File "/usr/local/lib/python3.6/dist-packages/rknn/api/rknn.py", line 262, in build
    inputs = self.rknn_base.net.get_input_layers()

zhaotun avatar Dec 15 '22 08:12 zhaotun

我用1.7.3做rknn3399Pro的转换也报同样的错误

GuardSkill avatar Jan 11 '23 07:01 GuardSkill

I just update the torch version in 1.7.3 docker and solve this problem: pip install torch==1.9 The RKNN docker never considers the torchscript input model.

GuardSkill avatar Jan 11 '23 08:01 GuardSkill