|
板凳
楼主 |
发表于 2020-5-6 16:46:45
|
只看该作者
报错 log 如下,从 pytorch 直接转 rknn
toymodel3_matrix_mult.pt ********************
WARNING: Token 'COMMENT' defined, but not used
WARNING: There is 1 unused token
E Catch exception when loading pytorch model: toymodel3_matrix_mult.pt!
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 97, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 570, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.__init__
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 654, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.model_simplify
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 113, in rknn.base.RKNNlib.converter.convert_pytorch.torch_inference_engine.shape_pick
E File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 148, in rknn.base.RKNNlib.converter.convert_pytorch.torch_inference_engine.__ir_shape_inference
E KeyError: 'aten::matmul'
我的模型:
- class ToyModel3(nn.Module):
- """
- 测试目的:用 one-hot vector multiplication 代替 if-else
- torch -> onnx -> rknn 转化失败, matmul 不支持
- torch -> rknn 失败, matmul 不支持
- """
- def __init__(self, num_channels):
- super(ToyModel3, self).__init__()
- self.num_channels = num_channels
- self.conv0 = nn.Conv2d(self.num_channels, self.num_channels,
- kernel_size=3, stride=1, padding=0, bias=False)
- self.conv1 = nn.Conv2d(self.num_channels, self.num_channels,
- kernel_size=3, stride=1, padding=0, bias=False)
- self.conv2 = nn.Conv2d(self.num_channels, self.num_channels,
- kernel_size=3, stride=1, padding=0, bias=False)
- n = self.num_channels
- self.conv0.weight = torch.nn.Parameter(torch.Tensor(np.ones((n, n, 3, 3)).astype(np.float32)))
- self.conv1.weight = torch.nn.Parameter(torch.Tensor(2 * np.ones((n, n, 3, 3)).astype(np.float32)))
- self.conv2.weight = torch.nn.Parameter(torch.Tensor(3 * np.ones((n, n, 3, 3)).astype(np.float32)))
- def forward(self, x, one_hot_vec):
- """
- :param x:
- :param one_hot_vec: of shape [3, 1]
- :return:
- """
- x0 = self.conv0(x)
- x1 = self.conv0(x)
- x2 = self.conv0(x)
- y = torch.cat([x0, x1, x2], axis=0)
- yt = y.permute(1, 2, 3, 0)
- out = torch.matmul(yt, one_hot_vec)
- return out
|
|