i am a new hand in this item, met a problem which is hard for me to solve…i need someone to help me
code below.:
class CNN(nn.Module):
def init(self,size):
    super(CNN, self).__init__()
    resnet = models.resnet152(pretrained=False)
    modules = list(resnet.children())[:-1]      # delete the last fc layer.
    self.resnet = nn.Sequential(*modules)
    self.linear = nn.Linear(resnet.fc.in_features, size)
   
            
def forward(self, images):
    """Extract feature vectors from input images."""
    
    with torch.no_grad():
        features = self.resnet(images)

    features = self.linear(features)
    
  
    return features

class NN(nn.Module):
def init(self, in_dim, n_hidden1, n_hidden2, out_dim):
super(NN, self).init()
self.layer1 = nn.Linear(in_dim, n_hidden1)
self.layer2 = nn.Linear(n_hidden1, n_hidden2)
self.layer3 = nn.Linear(n_hidden2, out_dim)
def forward(self, x):
    x = self.layer1(x)
    x = self.layer2(x)
    x = self.layer3(x)

device = torch.device(‘cuda’ if torch.cuda.is_available() else ‘cpu’)
size = 1
in_dim, n_hidden1, n_hidden2, out_dim = 20, 300, 100, 2
learning_rate = 0.001
encoder = CNN(size).cuda()
decoder = NN(in_dim, n_hidden1, n_hidden2, out_dim).cuda()
criterion = nn.MSELoss()
params = list(decoder.parameters()) + list(encoder.parameters())
optimizer = torch.optim.Adam(params, lr=learning_rate)
for epoch in range (10):
for img, rst, character in train_dataloader:
    img=img.to(device)
    rst =torch.Tensor(rst)
    rst = rst.to(device)
    character = torch.Tensor(character)
    character = character.to(device)
    
    
    features = encoder(img)
    
    character = torch.cat((features, character),1)
    outputs = decoder(character)
    loss = criterion(outputs, rst)
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()