|
板凳
楼主 |
发表于 2020-6-19 09:04:14
|
只看该作者
版本号:pytorch==1.2.0 onnx==1.4.1 rknn==1.3.2
Conv3d卷积代码:
import torch
import torch.onnx
from torch.autograd import Variable
from torch import nn
from rknn.api import RKNN
class Net(nn.Module):
def __init__(self, ):
super(Net, self).__init__()
self.layer1 = nn.Conv3d(in_channels=3, out_channels=3, kernel_size=(3, 7, 7), stride=1, padding=0)
def forward(self, x):
x = self.layer1(x)
return x
if __name__ == '__main__':
PATH = 'conv3d_demo.pt'
ONNX_PATH = 'conv3d_demo.onnx'
input = Variable(torch.randn(1, 3, 7, 60, 40))
net = Net()
net.eval()
# save pt model
trace_model = torch.jit.trace(net, input)
print(trace_model.graph)
trace_model.save(PATH)
# save onnx model
torch.onnx.export(net, input, ONNX_PATH, verbose=True)
rknn = RKNN()
rknn.config(reorder_channel='0 1 2', channel_mean_value='0 0 0 1')
ret = rknn.load_onnx(model=ONNX_PATH)
if ret != 0:
print('Load conv3d failed!')
exit(ret)
print('done')
打印输出:
graph(%self : ClassType<Net>,
%input : Float(1, 3, 7, 60, 40)):
%1 : ClassType<Conv3d> = prim::GetAttr[name="layer1"](%self)
%2 : Tensor = prim::GetAttr[name="weight"](%1)
%3 : Tensor = prim::GetAttr[name="bias"](%1)
%5 : int = prim::Constant[value=1](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%6 : int = prim::Constant[value=1](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%7 : int = prim::Constant[value=1](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%8 : int[] = prim:istConstruct(%5, %6, %7), scope: Net/Conv3d[layer1]
%9 : int = prim::Constant[value=0](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%10 : int = prim::Constant[value=0](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%11 : int = prim::Constant[value=0](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%12 : int[] = prim:istConstruct(%9, %10, %11), scope: Net/Conv3d[layer1]
%13 : int = prim::Constant[value=1](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%14 : int = prim::Constant[value=1](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%15 : int = prim::Constant[value=1](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%16 : int[] = prim:istConstruct(%13, %14, %15), scope: Net/Conv3d[layer1]
%17 : bool = prim::Constant[value=0](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%18 : int = prim::Constant[value=0](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%19 : int = prim::Constant[value=0](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%20 : int = prim::Constant[value=0](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%21 : int[] = prim:istConstruct(%18, %19, %20), scope: Net/Conv3d[layer1]
%22 : int = prim::Constant[value=1](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%23 : bool = prim::Constant[value=0](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%24 : bool = prim::Constant[value=0](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%25 : bool = prim::Constant[value=1](), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
%26 : Float(1, 3, 5, 54, 34) = aten::_convolution(%input, %2, %3, %8, %12, %16, %17, %21, %22, %23, %24, %25), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
return (%26)
graph(%0 : Float(1, 3, 7, 60, 40),
%layer1.weight : Float(3, 3, 3, 7, 7),
%layer1.bias : Float(3)):
%3 : Float(1, 3, 5, 54, 34) = onnx::Conv[dilations=[1, 1, 1], group=1, kernel_shape=[3, 7, 7], pads=[0, 0, 0, 0, 0, 0], strides=[1, 1, 1]](%0, %layer1.weight, %layer1.bias), scope: Net/Conv3d[layer1] # /root/venv/lib/python3.6/site-packages/torch/nn/modules/conv.py:478:0
return (%3)
W:tensorflow:From /root/venv/lib/python3.6/site-packages/onnx_tf/handlers/backend/ceil.py:10: The name tf.ceil is deprecated. Please use tf.math.ceil instead.
W:tensorflow:From /root/venv/lib/python3.6/site-packages/onnx_tf/handlers/backend/depth_to_space.py:12: The name tf.depth_to_space is deprecated. Please use tf.compat.v1.depth_to_space instead.
W:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
* https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
* https://github.com/tensorflow/addons
* https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.
W:tensorflow:From /root/venv/lib/python3.6/site-packages/onnx_tf/handlers/backend/log.py:10: The name tf.log is deprecated. Please use tf.math.log instead.
W:tensorflow:From /root/venv/lib/python3.6/site-packages/onnx_tf/handlers/backend/random_normal.py:9: The name tf.random_normal is deprecated. Please use tf.random.normal instead.
W:tensorflow:From /root/venv/lib/python3.6/site-packages/onnx_tf/handlers/backend/random_uniform.py:9: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.
W:tensorflow:From /root/venv/lib/python3.6/site-packages/onnx_tf/handlers/backend/upsample.py:13: The name tf.image.resize_images is deprecated. Please use tf.image.resize instead.
/root/venv/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)
E Try match Conv_3ut0 failed, catch exception!
E Catch exception when loading onnx model: conv3d_demo.onnx!
E Traceback (most recent call last):
E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 1050, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx.match_paragraph_and_param
E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 948, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx._onnx_build_acu_layer
E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 919, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx._onnx_acu_param_assign
E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 911, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx._onnx_acu_blob_assign
E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 904, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx._onnx_parase_execute
E File "<string>", line 1, in <module>
E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 644, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx.tensor_to_numpy
E File "/root/venv/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 639, in transpose
E return _wrapfunc(a, 'transpose', axes)
E File "/root/venv/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 56, in _wrapfunc
E return getattr(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 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 Conv_3ut0 failed, catch exception!
Load conv3d failed!
Process finished with exit code 255 |
|