Toybrick

标题: Couldn't not load resnet18.pt [打印本页]

作者: nvnn    时间: 2020-2-20 10:37
标题: Couldn't not load resnet18.pt
本帖最后由 nvnn 于 2020-2-20 10:41 编辑

Hi, I am trying to run the provided pytorch example, However I met the error below.
The code I tried is from rknn-toolkit: https://github.com/rockchip-linux/rknn-toolkit/blob/master/examples/pytorch/resnet18/test.py
Please let me know if you have any suggestions. Thanks
Here is the error log:
Downloading: "https://download.pytorch.org/models/resnet18-5c106cde.pth" to /home/nvnn/.cache/torch/checkpoints/resnet18-5c106cde.pth
100.0%
--> config model
done
--> Loading model
/home/nvnn/Downloads/env_rknn11/lib/python3.6/site-packages/onnx_tf/common/__init__.py:87: UserWarning: FrontendHandler.get_outputs_names is deprecated. It will be removed in future release.. Use node.outputs instead.
  warnings.warn(message)
./resnet18.pt ********************
WARNING: Token 'COMMENT' defined, but not used
WARNING: There is 1 unused token
Syntax error in input! LexToken(NAMED_IDENTIFIER,'__torch__',1,16)
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
!!!!! Illegal character '.'
done
--> Building model
W Genreate input meta fail, please check model.
W External input meta file "/tmp/tmpzjk3unin/resnet18_inputmeta.yml" is not exists.
Traceback (most recent call last):
  File "test.py", line 66, in <module>
    ret = rknn.build(do_quantization=True, dataset='./dataset.txt')
  File "/home/nvnn/Downloads/env_rknn11/lib/python3.6/site-packages/rknn/api/rknn.py", line 238, 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 719, in rknn.api.rknn_base.RKNNBase.build
  File "rknn/api/rknn_base.py", line 2249, in rknn.api.rknn_base.RKNNBase._generate_inputmeta
IndexError: list index out of range



作者: jefferyzhang    时间: 2020-2-20 11:26
pytorch version MUST equals 1.2

作者: nvnn    时间: 2020-2-24 08:22
Hi, pytorch version is 1.2.0. However still has some problem converting resnet18.pt
resnet18.pt ********************
WARNING: Token 'COMMENT' defined, but not used
WARNING: There is 1 unused token
E Catch exception when loading pytorch model: resnet18.pt!
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 567, in rknn.api.rknn_base.RKNNBase.load_pytorch
E   File "rknn/base/RKNNlib/app/importer/import_pytorch.py", line 95, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run
E   File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 517, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.__init__
E   File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 601, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.model_simplify
E   File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 104, in rknn.base.RKNNlib.converter.convert_pytorch.torch_inference_engine.shape_pick
E   File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 139, in rknn.base.RKNNlib.converter.convert_pytorch.torch_inference_engine.__ir_shape_inference
E KeyError: 'aten::softmax'
Traceback (most recent call last):
  File "rknn_transform.py", line 28, in <module>
    rknn.build(do_quantization=True, dataset='./dataset.txt')
  File "/home/nvnn/Downloads/env_rknn11/lib/python3.6/site-packages/rknn/api/rknn.py", line 220, in build
    inputs = self.rknn_base.net.get_input_layers()
AttributeError: 'NoneType' object has no attribute 'get_input_layers'

作者: jefferyzhang    时间: 2020-2-24 17:20
nvnn 发表于 2020-2-24 08:22
Hi, pytorch version is 1.2.0. However still has some problem converting resnet18.pt
resnet18.pt **** ...

The resnet18 of torchvision version does't have softmax layer, aten::softmax is written by yourself?
You can try remove this op, and do softmax in 3399 side,
or try our fix version 1.3.1beta as below:
https://pan.baidu.com/s/1Kn2FGAdF_j3CMLNEsC3OPw
password:   rcds

作者: nvnn    时间: 2020-2-26 08:33
本帖最后由 nvnn 于 2020-2-26 08:36 编辑
jefferyzhang 发表于 2020-2-24 17:20
The resnet18 of torchvision version does't have softmax layer, aten::softmax is written by yoursel ...

Thank you. I didn't add anything to resnet18.pt.
The code is from here:
  1. def export_pytorch_model():
  2.     net = models.resnet18(pretrained=True)
  3.     net.eval()
  4.     trace_model = torch.jit.trace(net, torch.Tensor(1,3,224,224))
  5.     trace_model.save('./resnet18.pt')
复制代码

I use this sample from rknn-toolkit: https://github.com/rockchip-linux/rknn-toolkit/blob/master/examples/pytorch/resnet18/test.py
so, it should be the origin resnet18 from pytorch
by the way, Can you upload version 1.3.1beta to onedrive? I am unable to download from baidu server. Thanks


作者: jefferyzhang    时间: 2020-2-26 08:37
Can the version 1.3.1beta fix this problem?

作者: nvnn    时间: 2020-2-26 10:26
jefferyzhang 发表于 2020-2-26 08:37
Can the version 1.3.1beta fix this problem?

I am not sure, I could not download it from baidu. Can you upload it to drive? Thanks
作者: jefferyzhang    时间: 2020-2-26 10:54
OK.

https://1drv.ms/u/s!AptzmNNWT7VUmX_16_tAmUZSt2Uc?e=jl30TB
作者: raul    时间: 2020-3-10 16:02
What`s the version of torchvision? We tested it in 0.4.0 and 0.4.2, both are success. You can also update RKNN Toolkit to version 1.3.1beta, the softmax error should be fixed.




欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3