Harshit Nagar
Harshit Nagar

Reputation: 438

Pytorch inceptionV3 transfer learning gives error - max() received an invalid combination of arguments

The program for transfer learning inception_v3 in pytorch that i am using is here : https://drive.google.com/file/d/1zn4z7nOp_wJne0En6zq4WJfwHVVftERT/view?usp=sharing

I am getting the following error upon running the program :

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)

How can this be fixed ? Thank you

Upvotes: 3

Views: 4610

Answers (4)

Farzad Amirjavid
Farzad Amirjavid

Reputation: 705

model_ft.aux_logits=False

model_ft.fc = nn.Linear(2048, 2)

Upvotes: 1

Lanka
Lanka

Reputation: 357

in this case, I have changed the code as below and its worked for me, Tutorial https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html

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

Upvotes: 4

TanLingxiao
TanLingxiao

Reputation: 412

I found the problem from here: pytorch inceptionv3 int line 125.The error is when in train mod and aux_logits opening,it return (x, aux). I solved it by

  1. use output, aux = model(input_var)

  2. if phase=='train': outputs,aux= model(inputs) else: outputs=model(inputs)

Upvotes: 1

Harshit Nagar
Harshit Nagar

Reputation: 438

The line should be as shown below :

_, preds = torch.max(outputs.data, 1)

Upvotes: 0

Related Questions