I have created a torchvision
model for transfer learning, using the pre-built ResNet50 base model, like this:
# Create base model from torchvision.models
model = resnet50(pretrained=True)
num_features = model.fc.in_features
# Define the network head and attach it to the model
model_head = nn.Sequential(
nn.Linear(num_features, 512),
nn.ReLU(),
nn.Dropout(0.25),
nn.Linear(512, 256),
nn.ReLU(),
nn.Dropout(0.5),
nn.Linear(256, num_classes),
)
model.fc = model_head
Now I wanted to use the Ineception v3 model instead as base, so I switched from resnet50()
above to inception_v3()
, the rest stayed as is. However, during training I get the following error:
TypeError: cross_entropy_loss(): argument ‘input’ (position 1) must be Tensor, not InceptionOutputs
So how can one use the Inception v3 model from torchvision.models
as base model for transfer learning?