%reload_ext autoreload
%autoreload 2
%matplotlib inline
from fastai.vision import *
from fastai.metrics import accuracy
PATH = "/home/katey/DeepLearning/Data/HistoCancer/"
sz = 96
bs = 128
tfms = get_transforms(flip_vert = True)
data = ImageDataBunch.from_csv(path = PATH, folder = 'train', valid_pct = 0.2,
csv_labels = f'{PATH}train_labels.csv',
suffix='.tif',ds_tfms=tfms, size=sz).normalize(imagenet_stats)
data.show_batch(rows=5, figsize=(12,10))
learn = create_cnn(data, models.resnet34, metrics=accuracy)
Tune the head of the network
learn.lr_find()
learn.recorder.plot()
lr = 1e-3
learn.fit_one_cycle(5, slice(lr))
Tune the entire network
learn.unfreeze()
learn.lr_find()
learn.recorder.plot()
learn.fit_one_cycle(5, slice(1e-5, 1e-4))
learn.fit_one_cycle(10, slice(1e-5, 1e-4/2))
learn.lr_find()
learn.recorder.plot()
learn.fit_one_cycle(5, slice(1e-4))
learn.save('mod-resnet34')
Try a larger architecture - Resnet 50
learn = create_cnn(data, models.resnet50, metrics=accuracy)
learn.lr_find()
learn.recorder.plot()
lr = 1e-2
learn.fit_one_cycle(5, slice(lr))
learn.unfreeze()
learn.lr_find()
learn.recorder.plot()
learn.fit_one_cycle(5, slice(1e-5, 1e-4))
learn.save('mod-resnet50')
learn.fit_one_cycle(10, slice(1e-5, 1e-4/2))
learn.save('mod-resnet50')
interp = ClassificationInterpretation.from_learner(learn)
losses,idxs = interp.top_losses()
len(data.valid_ds)==len(losses)==len(idxs)
interp.plot_top_losses(16, figsize=(12,10))
interp.plot_confusion_matrix(figsize=(3,3), dpi=100)