我遇到了
错误
我应该更改哪一个来解决此错误?
输入类型(torch.cuda.DoubleTensor)和重量类型 (torch.cuda.FloatTensor)应该相同
for i in range(num_epoch):
model.train()
for j,[image,label] in enumerate(train_loader):
x = Variable(image.float().cuda())
y_= Variable(label.long().cuda())
optimizer.zero_grad()
output = model.forward(x)
loss = loss_func(output,y_)
loss.backward()
optimizer.step()
top_1_count = torch.FloatTensor([0])
total = torch.FloatTensor([0])
model.eval()
for image,label in test_loader:
x = Variable(image,volatile=True).cuda()
y_= Variable(label).cuda()
output = model.forward(x)
values,idx = output.max(dim=1)
top_1_count += torch.sum(y_==idx).float().cpu().data
total += label.size(0)
print("Test Data Accuracy: {}%".format(100*(top_1_count/total).numpy()))
if (top_1_count/total).numpy() > 0.98:
break