Toybrick

标题: pytorch 是否支持 torch.nn.Parameter 定义 Parameter [打印本页]

作者: kkkaaa    时间: 2020-5-13 17:48
标题: pytorch 是否支持 torch.nn.Parameter 定义 Parameter
  1. class Model(torch.nn.Module):
  2.     def __init__(self):
  3.         super(Model, self).__init__()

  4.         self.weights_0 = torch.nn.Parameter(torch.ones(1))
  5.         self.weights_1 = torch.nn.Parameter(torch.ones(1))

  6.     def forward(self, input_0, input_1):
  7.         result = torch.mul(self.weights_0 , input_0) + torch.mul(self.weights_1 , input_1)
  8.         return result
复制代码
模型里需要通过 torch.nn.Parameter 的方式定义可学习参数,但是上面这个模型在 torch -> rknn 的时候会报错如下:WARNING: Token 'COMMENT' defined, but not used
WARNING: There is 1 unused token
W Not match tensor little_model_param.weights_0ut0
E Catch exception when loading pytorch model: little_model_param.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 104, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run
E   File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 1205, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.match_paragraph_and_param
E   File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 1129, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch._torch_push_ready_tensor
E TypeError: 'NoneType' object is not iterable
Load resnet50v2 failed!

我觉得主要原因是 W Not match tensor little_model_param.weights_0ut0 导致的。如果
self.weights_0 =torch.ones(1)
self.weights_1 =torch.ones(1)
则没有问题。


torch->onnx->rknn 应该没有问题,但是由于别的原因只能通过 pytorch -> rknn 直接转化。
谢谢





作者: jefferyzhang    时间: 2020-5-13 17:57
W Not match tensor little_model_param.weights_0ut0
就是指这个op不支持。这名字看过去就不是通用的OP,肯定不会支持的。。
作者: kkkaaa    时间: 2020-5-13 18:33
jefferyzhang 发表于 2020-5-13 17:57
W Not match tensor little_model_param.weights_0ut0
就是指这个op不支持。这名字看过去就不是通用的OP, ...

好的 谢谢




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