# Put these at the top of every notebook, to get automatic reloading and inline plotting
%reload_ext autoreload
%autoreload 2
%matplotlib inline
# This file contains all the main external libs we'll use
from fastai.imports import *
from fastai.transforms import *
from fastai.conv_learner import *
from fastai.model import *
from fastai.dataset import *
from fastai.sgdr import *
from fastai.plots import *
PATH = "data/dogscats/"
sz=224
arch=vgg16
bs=64
# Uncomment the below if you need to reset your precomputed activations
# !rm -rf {PATH}tmp
data = ImageClassifierData.from_paths(PATH, bs=bs, tfms=tfms_from_model(arch, sz))
learn = ConvLearner.pretrained(arch, data, precompute=True)
100%|██████████| 360/360 [01:21<00:00, 4.44it/s] 100%|██████████| 32/32 [00:12<00:00, 2.64it/s]
learn.fit(0.01, 3, cycle_len=1)
A Jupyter Widget
[ 0. 0.05266 0.02898 0.99072] [ 1. 0.04534 0.02512 0.99023] [ 2. 0.04645 0.02377 0.99121]
tfms = tfms_from_model(arch, sz, aug_tfms=transforms_side_on, max_zoom=1.1)
data = ImageClassifierData.from_paths(PATH, tfms=tfms, bs=bs, num_workers=4)
learn = ConvLearner.pretrained(arch, data, precompute=True)
learn.fit(1e-2, 2)
A Jupyter Widget
[ 0. 0.05622 0.0268 0.98926] [ 1. 0.04222 0.02508 0.99072]
learn.precompute=False
learn.fit(1e-2, 1, cycle_len=1)
A Jupyter Widget
[ 0. 0.05511 0.02654 0.98909]
learn.unfreeze()
lr=np.array([1e-4,1e-3,1e-2])
learn.fit(lr, 1, cycle_len=1)
A Jupyter Widget
[ 0. 0.05664 0.0245 0.99023]
learn.fit(lr, 3, cycle_len=1, cycle_mult=2)
A Jupyter Widget
[ 0. 0.05955 0.02217 0.9917 ] [ 1. 0.03902 0.0181 0.99414] [ 2. 0.03676 0.0168 0.99414] [ 3. 0.03097 0.01607 0.99316] [ 4. 0.02823 0.01574 0.99316] [ 5. 0.02663 0.01448 0.99316] [ 6. 0.03113 0.01642 0.99414]
learn.fit(lr, 3, cycle_len=3)
A Jupyter Widget
[ 0. 0.02769 0.01896 0.99268] [ 1. 0.01939 0.01417 0.99365] [ 2. 0.01935 0.0142 0.99414] [ 3. 0.02465 0.01641 0.99316] [ 4. 0.02753 0.01376 0.99365] [ 5. 0.01721 0.01413 0.99414] [ 6. 0.0221 0.01317 0.99365] [ 7. 0.01789 0.01379 0.99268] [ 8. 0.01861 0.0139 0.99316]
log_preds,y = learn.TTA()
probs = np.mean(np.exp(log_preds),0)accuracy_np(probs,y)
0.995