错误1:
Expected object of backend CPU but got backend CUDA for argument #2 'weight'
#之前: model = model.cuda() #之后: model = torch.nn.DataParallel(model).cuda()
错误2:
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)
#之前: # 前向传播计算输出 outputs = model(input) label = label.squeeze() outputs.detach_() # 计算准确率,记录损失 loss = criterion(outputs[i], label) #之后: loss = criterion(outputs, label)
#之前label有一个维度问题 label.size()=tensor([16,1]) label = label.squeeze() label.size()=tensor([16])