报错TypeError: conv2d() received an invalid combination of arguments - got (tuple, Parameter, Parameter, tuple, tuple, tuple, int), but expected one of:
- (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
didn’t match because some of the arguments have invalid types: (!tuple!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int) - (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
didn’t match because some of the arguments have invalid types: (!tuple!, !Parameter!, !Parameter!, !tuple!, !tuple!, !tuple!, int)
手写数字识别MNIST
代码
def train(epoch_num):
# 循环外可以自行添加必要内容
running_loss = 0.0
train_loss=[]
#device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
for index, data in enumerate(data_loader_train, 0):
optimizer.zero_grad()
#data = data.cpu().data.numpy()
images, true_labels = data
# 该部分添加训练的主要内容
# 必要的时候可以添加损失函数值的信息,即训练到现在的平均损失或最后一次的损失,下面两行不必保留
#print(images)
#print(true_labels)
optimizer.zero_grad()
label = model(images)
loss = loss_function(label,true_labels)
running_loss += loss.item()
loss.backward()
optimizer.step()
'''
if(index%300 == 0):
print('[%d, %5d] loss = %.3f' % (epoch_num + 1, index, running_loss / 300))
running_loss = 0.0
'''
if index%100 == 99:
print('[%d,%5d] loss :%.3f' %
(epoch+1,index+1,running_loss/100))
running_loss = 0.0
train_loss.append(loss.item())
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)