Sir, I’d like to ask for your help. I adopt a simple feed-forward net to classify feature maps. Following is the code:
class FmDataLoad(Dataset):
def init(self, npy_file, root_dir):
self.npy_data = np.load(npy_file)
self.root_dir = root_dir
def __len__(self):
    return self.npy_data.shape[0]

def __getitem__(self, index):
    fm_data = np.array(self.npy_data[:, :-1], dtype = np.float)
    label_data = np.array(self.npy_data[:, -1], dtype = np.float)

    return fm_data, label_data

train_data = FmDataLoad(npy_file = ‘models/train_data_conv22.npy’, root_dir = ‘models/’)
test_data = FmDataLoad(npy_file = ‘models/test_data_conv22.npy’, root_dir = ‘models/’)
class Net(nn.Module):
def init(self, input_size, hidden_size, num_classes):
super(Net, self).init()
self.fc1 = nn.Linear(input_size, hidden_size)
self.relu = nn.ReLU()
self.fc2 = nn.Linear(hidden_size, num_classes)
def forward(self, x):
    out = self.fc1(x)
    out = self.relu(out)
    out = self.fc2(out)
    return out

net = Net(input_size, hidden_size, num_classes)
net.cuda()
criterion = nn.MSELoss()
optimizer = torch.optim.Adam(net.parameters(), lr=learning_rate)
for epoch in range(num_epochs):
for i in range(len(train_data)):
for fm_data, label_data in train_data:
fm_data = torch.from_numpy(fm_data).float().cuda()
fm_data = Variable(fm_data)
        label_data = torch.from_numpy(label_data).float().cuda()
        label_data = Variable(label_data)

        optimizer.zero_grad()  # zero the gradient buffer
        outputs = net(fm_data)
        loss = criterion(outputs, label_data)
        loss.backward()
        optimizer.step()

        if (i + 1) % 100 == 0:
            print ('Epoch [%d/%d], Step [%d/%d], Loss: %.4f'
                   %(epoch+1, num_epochs, i+1, len(train_data)//batch_size, loss.data[0]))

The error is:
Traceback (most recent call last):
File “feed_forward.py”, line 64, in 
loss = criterion(outputs, label_data)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py”, line 224, in call
result = self.forward(*input, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/loss.py”, line 272, in forward
return F.mse_loss(input, target, size_average=self.size_average)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/functional.py”, line 819, in mse_loss
return _functions.thnn.MSELoss.apply(input, target, size_average)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/_functions/thnn/auto.py”, line 47, in forward
output, *ctx.additional_args)
RuntimeError: input and target have different number of elements: input[6060 x 3] has 18180 elements, while target[6060] has 6060 elements at /pytorch/torch/lib/THCUNN/generic/MSECriterion.cu:12
could you give me an advice to solve this problem? Thank you very much!