我正在使用的pytorch转移学习inception_v3程序在这里:https://drive.google.com/file/d/1zn4z7nOp_wJne0En6zq4WJfwHVVftERT/view?usp=sharing
运行程序时出现以下错误:
Epoch 0/24
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-20-cc88ea5f8bd3> in <module>()
1 model_ft = train_model(model_ft, criterion, optimizer_ft, exp_lr_scheduler,
----> 2 num_epochs=25)
<ipython-input-17-812cf3c4576a> in train_model(model, criterion, optimizer, scheduler, num_epochs)
33 outputs = model(inputs)
34 print(outputs)
---> 35 _, preds = torch.max(outputs, 1)
36 loss = criterion(outputs, labels)
37
TypeError: max() received an invalid combination of arguments - got (tuple, int), but expected one of:
* (Tensor input)
* (Tensor input, Tensor other, Tensor out)
* (Tensor input, int dim, bool keepdim, tuple of Tensors out)
如何解决? 谢谢
答案 0 :(得分:0)
该行应如下所示:
_, preds = torch.max(outputs.data, 1)
答案 1 :(得分:0)
我从这里发现问题:pytorch inceptionv3 int第125行。错误是在train mod和aux_logits打开时,它返回(x,aux)。 我通过
解决了使用output, aux = model(input_var)
如果phase =='train': 输出,aux =模型(输入) 其他: 输出=模型(输入)
答案 2 :(得分:0)
在这种情况下,我更改了以下代码,并为我工作了, 教程https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html
model_ft = models.inception_v3(pretrained=True)
model_ft.aux_logits=False
答案 3 :(得分:0)
model_ft.aux_logits=False
model_ft.fc = nn.Linear(2048, 2)