inwk
inwk

Reputation: 11

pytorch: inception v3 parameter empty error

I am using inception_v3 from torchvision.models as my base model and adding an FC layer at the end to get features. However, I am getting an empty parameter error.

import torch
import torch.nn as nn
import torchvision.models as models

class Baseline(nn.Module):
    def __init__(self, out_size):
        super().__init__()
        model = models.inception_v3(pretrained=True)
        model.fc = nn.Linear(2048, out_size)
        model.aux_logits = False

        # Freeze model weights
        for param in model.parameters():
            param.requires_grad = False



        self.parameters = nn.ParameterList()

    def forward(self, image):
        x = model(image)
        x = x.view(x.size(0), -1)
        x = model.fc = (x)
        return x

Upvotes: 1

Views: 180

Answers (1)

asymptote
asymptote

Reputation: 1402

My understanding is that you are updating self.parameters with an empty nn.ParameterList which is not required here.

self.parameters will already have all the parameters your Baseline class has, including those of inception_v3 and nn.Linear. When you are updating them at the end with an empty list, you are essentially deleting all of the previously stored parameters.

Upvotes: 2

Related Questions