【问题标题】:AttributeError: 'tuple' object has no attribute 'log_softmax'AttributeError:“元组”对象没有属性“log_softmax”
【发布时间】:2019-04-27 19:32:43
【问题描述】:

同时尝试通过更改最后一个 fc 层来为我自己的数据集微调 inception_V3,例如

last_layer =nn.Linear(n_inputs, len(classes))
inception_v3.fc = last_layer

之后,当我训练它时,它在这个位置上出现了这个错误

    # on training loop
    output = inception_v3(data)
    # calculate the batch loss
    loss = criterion(output, target)

错误是

 AttributeError: 'tuple' object has no attribute 'log_softmax'

【问题讨论】:

    标签: python deep-learning pytorch


    【解决方案1】:

    这个问题对我来说就像你定义F

    import torch.nn.functional as F
    

    你意外地将F 设置为一些元组

    F=(1,2)
    

    然后当您调用F.log_softmax 时,您会得到这个错误。

    【讨论】:

      【解决方案2】:

      这是一个众所周知的问题。

      尝试以下解决方案之一:

      1. 在此处创建模型时禁用 aux_logits,同时将 aux_logits=False 传递给 inception_v3 函数。

      2. 编辑您的 train 函数以接受并解压缩返回的元组,使其类似于:output, aux = model(input_var)

      查看以下link 了解更多信息。

      【讨论】:

      • 解决了 inception_v3 = models.inception_v3(pretrained=True) inception_v3.aux_logits=False
      猜你喜欢
      • 2021-09-30
      • 2013-06-21
      • 2021-07-30
      • 2013-07-29
      • 2020-08-29
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多