|
import torch
import torch.nn as nn
import torch.nn.functional as F
from rknn.api import RKNN
class siamrpn(nn.Module):
def __init__(self):
super(siamrpn, self).__init__()
def forward(self, x, w):
return F.conv2d(x, w)
if __name__ == "__main__":
net = siamrpn()
net.eval()
torch_model = 'siamrpn.pt'
rknn_model = 'siamrpn.rknn'
# export pt
trace_model = torch.jit.trace(
net, (torch.Tensor(1, 3, 224, 224), torch.Tensor(1, 3, 4, 4)))
print(trace_model.code)
trace_model.save(torch_model)
# export rknn
rknn = RKNN()
# pre-process config
print('--> config model')
rknn.config(target_platform='rk3399pro')
print('done')
# Load pytorch model
print('--> Loading model')
ret = rknn.load_pytorch(model=torch_model, input_size_list=[
[3, 224, 224], [3, 4, 4]])
if ret != 0:
print('Load pytorch model failed!')
exit(ret)
print('done')
报错:
WARNING: Token 'COMMENT' defined, but not used
WARNING: There is 1 unused token
E Try match aten::_convolution_at_17ut0 failed, catch exception!
E Catch exception when loading pytorch model: siamrpn.pt!
E Traceback (most recent call last):
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 1191, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.match_paragraph_and_param
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 1111, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch._torch_build_acu_layer
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 1085, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch._torch_acu_param_assign
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 1077, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch._torch_acu_blob_assign
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 1070, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch._torch_parase_execute
E File "<string>", line 1, in <module>
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 893, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.tensor_to_numpy
E File "<__array_function__ internals>", line 6, in transpose
E File "/home/xcq/.local/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 653, in transpose
E return _wrapfunc(a, 'transpose', axes)
E File "/home/xcq/.local/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 55, in _wrapfunc
E return _wrapit(obj, method, *args, **kwds)
E File "/home/xcq/.local/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 44, in _wrapit
E result = getattr(asarray(obj), method)(*args, **kwds)
E ValueError: axes don't match array
E During handling of the above exception, another exception occurred:
E Traceback (most recent call last):
E File "rknn/api/rknn_base.py", line 611, in rknn.api.rknn_base.RKNNBase.load_pytorch
E File "rknn/base/RKNNlib/app/importer/import_pytorch.py", line 104, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 1202, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.match_paragraph_and_param
E File "rknn/api/rknn_log.py", line 312, in rknn.api.rknn_log.RKNNLog.e
E ValueError: Try match aten::_convolution_at_17ut0 failed, catch exception!
Load pytorch model failed!
环境:rk3399pro,debian10,rknn-toolkit1.3.2,pytorch1.2
|
|