Hello ,can someone helps me ,when I run my code I got this error
AttributeError: ‘list’ object has no attribute ‘size’
#rpm
for epoch in range(300):
for x,y in enumerate(train_loader):
y = torch.zeros(y.size(0),4).scatter_(1,y.view(-1,1),1.)
x,y = x.to(device),y.to(device)
output,_ = rpm_nn(x,y) # cnn output
loss = loss_func(output) # cross entropy loss# clear gradients for this training step
optimizer_rpm.zero_grad()
loss.backward()
optimizer_rpm.step()
test_out,_=rpm_nn(test_x,test_y)
pred_z=torch.max(test_out,1)[1].cpu().data.numpy()
accuracy = float((pred_z == test_z.cpu().numpy()).astype(int).sum()) / float(test_y.size(0))
print('Epoch: ', epoch, ‘| train loss: %.4f’ % loss.cpu().data.numpy(), ‘| test accuracy: %.2f’ % accuracy)