text_html_output_1.png image_output_2.png image_output_1.png
from sklearn.metrics import cohen_kappa_score

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import torch

SIZE = 224
train_df = pd.read_csv(PATH + '/train.csv')
test_df = pd.read_csv(PATH + '/sample_submission.csv')

train = ImageList.from_df(train_df, path=PATH, cols='id_code', folder='train_images', suffix='.png')
test = ImageList.from_df(test_df, path=PATH, cols='id_code', folder='test_images', suffix='.png')

def quadratic_kappa(y_hat, y):
    return torch.tensor(cohen_kappa_score(torch.round(y_hat), y, weights='quadratic'), device='cuda:0')

from sklearn.metrics import cohen_kappa_score
data = train.split_by_rand_pct(0.2).label_from_df(cols='diagnosis', label_cls=FloatList).add_test(test).transform(get_transforms(), size=SIZE).databunch(path=Path('.'), bs=32).normalize(imagenet_stats)

learn = cnn_learner(data, models.resnet101, metrics=[quadratic_kappa], pretrained=True)

learn.fit_one_cycle(6, slice(0.00275, 0.0275))

learn.save('stage1')

learn.unfreeze()
learn.lr_find()

lr = 0.00275
learn.fit_one_cycle(4, slice(1.5e-06, lr / 8), wd=0.05)