Fine-tune pretrained Convolutional Neural Networks with PyTorch
MIT License
resnet18
, resnet34
, resnet50
, resnet101
, resnet152
)resnext50_32x4d
, resnext101_32x8d
)densenet121
, densenet169
, densenet201
, densenet161
)inception_v3
)vgg11
, vgg11_bn
, vgg13
, vgg13_bn
, vgg16
, vgg16_bn
, vgg19
, vgg19_bn
)squeezenet1_0
, squeezenet1_1
)mobilenet_v2
)shufflenet_v2_x0_5
, shufflenet_v2_x1_0
)alexnet
)googlenet
)resnext101_32x4d
, resnext101_64x4d
)nasnetalarge
)nasnetamobile
)inceptionresnetv2
)dpn68
, dpn68b
, dpn92
, dpn98
, dpn131
, dpn107
)inception_v4
)xception
)senet154
, se_resnet50
, se_resnet101
, se_resnet152
, se_resnext50_32x4d
, se_resnext101_32x4d
)pnasnet5large
)polynet
)pip install cnn_finetune
pretrained
argument in make_model
is changed from False
to True
. Now call make_model('resnet18', num_classes=10)
is equal to make_model('resnet18', num_classes=10, pretrained=True)
from cnn_finetune import make_model
model = make_model('resnet18', num_classes=10, pretrained=True)
model = make_model('nasnetalarge', num_classes=10, pretrained=True, dropout_p=0.5)
import torch.nn as nn
model = make_model('inceptionresnetv2', num_classes=10, pretrained=True, pool=nn.AdaptiveMaxPool2d(1))
VGG and AlexNet models use fully-connected layers, so you have to additionally pass the input size of images when constructing a new model. This information is needed to determine the input size of fully-connected layers.
model = make_model('vgg16', num_classes=10, pretrained=True, input_size=(256, 256))
import torch.nn as nn
def make_classifier(in_features, num_classes):
return nn.Sequential(
nn.Linear(in_features, 4096),
nn.ReLU(inplace=True),
nn.Linear(4096, num_classes),
)
model = make_model('vgg16', num_classes=10, pretrained=True, input_size=(256, 256), classifier_factory=make_classifier)
>> model = make_model('resnext101_64x4d', num_classes=10, pretrained=True)
>> print(model.original_model_info)
ModelInfo(input_space='RGB', input_size=[3, 224, 224], input_range=[0, 1], mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
>> print(model.original_model_info.mean)
[0.485, 0.456, 0.406]
See examples/cifar10.py file (requires PyTorch 1.1+).