Problem with initializing network

I can’t initialize my model an get TypeError: forward() missing 1 required positional argument: ‘input’
Code below:

class News_classifier_resnet_based(torch.nn.Module):

def init(self):

super().__init__()

self.activation = torch.nn.ReLU6()

self.sigmoid = torch.nn.Sigmoid()

self.positional_encodings = PositionalEncoder()



self.resnet = list(torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained=True).children())



self.to_appropriate_shape = torch.nn.Conv2d(in_channels=1, out_channels=1, kernel_size=77)



self.conv1 = torch.nn.Conv2d(in_channels=1,out_channels=64,kernel_size=7,stride=2,padding=3)

self.conv1.weight = torch.nn.Parameter(self.resnet[0].weight[:,0,:,:].data)

self.center = torch.nn.Sequential(*self.resnet[1:-2])

self.conv2 = torch.nn.Conv2d(in_channels=512, out_channels=1, kernel_size=1)

self.conv3 = torch.nn.Conv2d(in_channels=1,out_channels=1,kernel_size=7)



self.title_conv = torch.nn.Sequential(

                    torch.nn.Conv2d(in_channels=1,out_channels=1,kernel_size=3,stride=3),

                    self.activation(),

                    torch.nn.Conv2d(in_channels=1,out_channels=1,kernel_size=2,stride=2),

                    self.activation(),

                    torch.nn.Conv2d(in_channels=1,out_channels=1,kernel_size=2,stride=2)

                )

self.title_lin = torch.nn.Linear(25,1)

self.year_lin = torch.nn.Linear(10,1)

self.month_lin = torch.nn.Linear(12,1)

self.day_lin = torch.nn.Linear(31,1)

self.date_lin = torch.nn.Linear(3,1)

self.final_lin = torch.nn.Linear(3,1)

def forward(self,x_in):

#input shape - (batch_size, 3+title_len+seq_len, embedding_dim)

#output shape - (batch_size, 1)

year = x_in[:,0,:10]

month = x_in[:,1,:12]

day = x_in[:,2,:31]



title = x_in[:,3:3+args.title_len,:]

text = x_in[:,3+args.title_len:,:]

title = self.positional_encodings(title)

text = self.positional_encodings(text)



text = text.unsqueeze(1)

text = self.activation(self.to_appropriate_shape(text))

text = self.activation(self.conv1(text))

text = self.activation(self.center(text))

text = self.activation(self.conv2(text))

text = self.activation(self.conv3(text))

text = text.reshape(args.batch_size,-1)

title = title.unsqueeze(1)

title = self.activation(self.title_conv(title))

title = title.reshape(args.batch_size,-1)

title = self.activation(self.title_lin(title))

year = self.activation(self.year_lin(year))

month = self.activation(self.month_lin(month))

day = self.activation(self.day_lin(day))

date = torch.cat([year,month,day], dim=-1)

date = self.activation(self.date_lin(date))

final = torch.cat([date,title,text], dim=-1)

final = self.sigmoid(self.final_lin(final))

return final

if name==‘main’:

dataset = News_Dataset(true_path=args.true_news_file, fake_path=args.fake_news_file, 

                       embeddings_path=args.embeddings_file)

classifier = News_classifier_resnet_based().cuda()

Error is on last line
What should I do?
There is a lack of underscores in init,name and ‘main’, but they present in code

Hi @Aleks_Bot,
Maybe try:

super(News_classifier_resnet_based, self).__init__()

Hope it helps.