Kaggle competition: APTOS 2019 Blindness Detection
maxlen = 120
embed_size = 300
max_features = 5000<string_transform>
def quadratic_kappa(y_hat, y):
return torch.tensor(cohen_kappa_score(torch.argmax(y_hat,1), y, weights='quadratic'),device='cuda:0' )
tokenizer = Tokenizer(num_words=max_features)
 tokenizer_list = list(train_X)
 tokenizer.fit_on_texts(tokenizer_list)
 train_X = tokenizer.texts_to_sequences(train_X)
 testA_X = tokenizer.texts_to_sequences(testA_X)
 testB_X = tokenizer.texts_to_sequences(testB_X)
 train_X = pad_sequences(train_X, maxlen=maxlen)
 testA_X = pad_sequences(testA_X, maxlen=maxlen)
 testB_X = pad_sequences(testB_X, maxlen=maxlen )<define_variables>
num_folds = 5
df = pd.read_csv('.. /input/aptos2019-blindness-detection/sample_submission.csv')
 base_image_dir = os.path.join('.. ', 'input/aptos2019-blindness-detection/')
 test_dir = os.path.join(base_image_dir,'test_images/')
 df['path'] = df['id_code'].map(lambda x: os.path.join(test_dir,'{}.png'.format(x)))
 df = df.sample(frac=1 ).reset_index(drop=True)
 df.head(10)
 for i in range(num_folds):
copyfile(".. /input/aptos-4fold-models/model" + str(i)+".pkl",".. /model" + str(i)+".pkl")
 test = ImageList.from_df(df,Path('.'),cols='path')
 predictions = torch.from_numpy(np.zeros(( len(df))))
for i in range(num_folds):
learn = load_learner('.. /',file = 'model'+str(i)+'.pkl',test=test)
 preds, _ = learn.get_preds(ds_type=DatasetType.Test)
 predictions = predictions + preds.argmax(dim=-1 ).double()
word_index = tokenizer.word_index
max_features = len(word_index )<load_from_url>
predictions = torch.round(predictions/num_folds)
 print(predictions )
!wget http://nlp.stanford.edu/data/glove.840B.300d.zip<load_pretrained>
df = df.drop(columns=['path'])
 df.diagnosis = predictions.numpy().astype(int)
 df.head(10)
 df.to_csv('submission.csv',index=False )