import os
import sys
import numpy as np
import paddle
import paddle.nn as nn
from paddle.nn import Layer
import paddle.nn.functional as F
SRM_npy = np.load('SRM_Kernels.npy')
残差网络卷积2D卷积
class Res_conv2d(nn.Layer):
definit(self):
super(Res_conv2d, self).init()
self.weight = paddle.create_parameter([30,1,5,5],dtype = "float32")
self.bias = paddle.create_parameter([30],dtype = "float32")
self.reset_parameters()
def reset_parameters(self):
self.weight.shape.numpy()[:] = SRM_npy#报错
self.bias.shape.zero_() #报错
def forward(self, input):
return F.conv2d(input, self.weight, self.bias)
问题:之前self.weight = Parameter(torch.Tensor(30, 1, 5, 5), requires_grad=True)
通过API文档用paddle.create_parameter([30,1,5,5],dtype = "float32")替换,但在替换之后不确定新生成的shape和原来的torch.Tensor(30, 1, 5, 5)是不是同一格式,也就是不确定shape是不是Tensor。
假如是Tensor,为什么在报错部分self.weight.shape.numpy()[:] = SRM_npy会显示没有numpy()。
2条答案
按热度按时间vd8tlhqk1#
您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档、常见问题、历史Issue、AI社区来寻求解答。祝您生活愉快~
Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the API,FAQ,Github Issue and AI community to get the answer.Have a nice day!
sbtkgmzw2#
您好,self.weight.shape是list类型,没有numpy方法