image_output_2.png image_output_1.png
import numpy as np # linear algebra

tfms = get_transforms(do_flip=True, flip_vert=True, max_warp=0)

data_path = '../input/aptos2019-blindness-detection'
train_label_file = 'train.csv'
train_images_folder = 'train_images'
test_label_file = 'test.csv'
test_images_folder = 'test_images'
image_suffix = '.png'

split_pct = 0.1
bs = 64
size = 224

np.random.seed(42)
src = ImageList.from_csv(data_path, train_label_file, folder=train_images_folder, suffix=image_suffix).split_by_rand_pct(split_pct).label_from_df()
src

data = src.transform(tfms, size=size).databunch(bs=bs).normalize(imagenet_stats)
(data.c, data.classes)

arch = models.vgg16_bn

kappa = KappaScore()
kappa.weights = 'quadratic'

learn = cnn_learner(data, arch, metrics=[kappa], model_dir='../saved_models')
learn.model

learn.lr_find()

lr = 0.01 / 2

learn.fit_one_cycle(5, lr, callbacks=[SaveModelCallback(learn, monitor='kappa_score', mode='max', name='headonly_vgg16_bn')])

learn.load('headonly_vgg16_bn')

learn.unfreeze()

learn.lr_find()

learn.fit_one_cycle(5, slice(0.0001 / 2, lr / 10), callbacks=[SaveModelCallback(learn, monitor='kappa_score', mode='max', name='best_model_vgg16_bn_224')])