Tutorials

Learning tasks

How To

Reference

Background

Finetuning a pretrained model

using FastAI
using Zygote
using CUDA
CUDA.allowscalar(false)

Choose any image classification dataset out of

Datasets.DATASETS_IMAGECLASSIFICATION
DATASETNAME = "imagenette2-160";
taskdata = Datasets.loadtaskdata(Datasets.datasetpath(DATASETNAME), ImageClassificationTask)
classes = Datasets.getclassesclassification(DATASETNAME)
image, class = getobs(taskdata, 1)
@show class
image
method = ImageClassification(classes, (128, 128))

Now we load a pretrained model backbone:

# load model with pretrained weights 
backbone = Models.resnet50(pretrained = true);

We pass it to methodlearner which will call methodmodel to stack a classification head on top of the backbone:

learner = methodlearner(method, taskdata, backbone, ToGPU(), Metrics(accuracy))

The fine-tuning itself is done with finetune!. It follows the same protocol as the fastai implementation.

finetune!(learner, 3)