Skip to content

Instantly share code, notes, and snippets.

View surmenok's full-sized avatar

Pavel Surmenok surmenok

View GitHub Profile
learn.unfreeze()
learn.fit(0.01, 3, wds=wd)
log_preds,_ = learn.TTA(n_aug=20, is_test=True)
preds = np.mean(np.exp(log_preds),0)
accuracy_np(preds, y_true)
log_preds,y = learn.predict_with_targs()
preds = np.exp(log_preds)
pred_labels = np.argmax(preds, axis=1)
results = ImageModelResults(data.val_ds, log_preds)
results.plot_most_incorrect(1)
learn.unfreeze()
lr=np.array([1e-4,1e-3,1e-2])
learn.fit(lr, 5, cycle_len=1, cycle_mult=2)
learn.fit(lr, 4, cycle_len=1, cycle_mult=2, wds=wd)
wd = 5e-4
learn.fit(0.01, 1, wds=wd)
arch = resnet34
learn = ConvLearner.pretrained(arch, data, precompute=False)
def plot_loss_change(sched, sma=1, n_skip=20, y_lim=(-0.01,0.01)):
"""
Plots rate of change of the loss function.
Parameters:
sched - learning rate scheduler, an instance of LR_Finder class.
sma - number of batches for simple moving average to smooth out the curve.
n_skip - number of batches to skip on the left.
y_lim - limits for the y axis.
"""
derivatives = [0] * (sma + 1)
sz = 96
# Look at examples of image augmentation
def get_augs():
x,_ = next(iter(data.aug_dl))
return data.trn_ds.denorm(x)[1]
aug_tfms = [RandomRotate(20), RandomLighting(0.8, 0.8)]
tfms = tfms_from_model(arch, sz, aug_tfms=aug_tfms, max_zoom=1.2)
data = ImageClassifierData.from_paths(path, tfms=tfms, test_name='test')
# learn is an instance of Learner class or one of derived classes like ConvLearner
learn.lr_find()
learn.sched.plot_lr()