hey, I have same error.
AttributeError                            Traceback (most recent call last)
 in 
35                   device=device,
36                   img_scale=0.5,
—> 37                   val_percent=0.1)
38
39     except KeyboardInterrupt:
 in train_net(net, device, epochs, batch_size, lr, img_scale, val_percent, save_cp)
87                         tag = tag.replace(’.’, ‘/’)
88                         writer.add_histogram(‘weights/’ + tag, value.data.cpu().numpy(), global_step)
—> 89                         writer.add_histogram(‘grads/’ + tag, value.grad.data.cpu().numpy(), global_step)
90                     val_score = eval_net(net, val_loader, device)
91                     scheduler.step(val_score)
AttributeError: ‘NoneType’ object has no attribute ‘data’
In my model, I used nn.Parameter to initialize weight and bias. According to your explanation here, self.weight or any other parameters should be used in the forward method. Could you please explain, how would this work in my case since it leads to the solution of error? To my understanding, there is no necessary(way) to use them in forward method. But, maybe I am wrong about it since I am a new hand to pytorch. Thank u.
class ResDown(nn.Module):
“”“Downscaling “””
def __init__(self, 
             in_channels, 
             out_channels, 
             scale=4 ): 
    super().__init__()
    self.scale = scale

    self.down = nn.Sequential(
        nn.ZeroPad2d(1),
        nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=scale, stride=scale),
        nn.LeakyReLU(inplace=True) )
    self.down.weight = nn.Parameter(
        nn.init.normal_(torch.empty((out_channels, in_channels,scale,scale),dtype=torch.float32)))  
    self.down.weight.requires_grad = True
   
def forward(self, x):
    #print('input feature size',x.shape)
    x = self.down(x)
    #print('before partial padding:output of first convertional layer',x.shape)
    in_c,out_c,h,w = x.shape
    #print('the mask_ratio',partial_padding(3,h,w).shape)
    x = x*partial_padding(3,h,w) # kernel_size = 4 instead of self.scale
    #print('the output of down sampling',x.shape)
    return x