gpt4 book ai didi

python - Pytorch inceptionV3 迁移学习给出错误 - max() 收到无效的参数组合

转载 作者:行者123 更新时间:2023-12-01 09:18:06 25 4
gpt4 key购买 nike

我正在使用的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)

如何解决这个问题?谢谢

最佳答案

在这种情况下,我更改了代码,如下所示,它对我有用,教程 https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html

model_ft = models.inception_v3(pretrained=True)
model_ft.aux_logits=False

关于python - Pytorch inceptionV3 迁移学习给出错误 - max() 收到无效的参数组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51045839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com