Multi-label classification example using fastai v1

Simple example of multi-label classification using fastai v1.

%reload_ext autoreload
%autoreload 2

from fastai import *
from fastai.vision import *

In [43]:

path = untar_data(URLs.PLANET_SAMPLE)
path

Out[43]:

PosixPath('/home/ubuntu/.fastai/data/planet_sample')

In [44]:

data = ImageDataBunch.from_csv(path, folder='train', sep=' ', suffix='.jpg', ds_tfms=get_transforms(), tfms=imagenet_norm, size=224)
img,labels = data.valid_ds[-1]
img.show(title=" ".join(np.array(data.classes)[labels.astype(bool)]))

Train last layer:

learn = ConvLearner(data, models.resnet34, metrics=Fbeta(beta=2))
learn.fit_one_cycle(1)
Total time: 00:10
epoch train loss valid loss fbeta
1 0.748020 0.649659 0.365789 (00:10)

Unfreeze and finetune:

learn.unfreeze()
learn.fit_one_cycle(1)
Total time: 00:10
epoch train loss valid loss fbeta
1 0.621923 0.705165 0.380751 (00:10)

Software Engineering SMTS at Salesforce Commerce Cloud Einstein

Software Engineering SMTS at Salesforce Commerce Cloud Einstein