Kaggle competition: APTOS 2019 Blindness Detection
<SOS> metric: QuadraticWeightedKappa Kaggle data source: aptos-2019-blindness-detection<save_to_csv>
from fastai import *
from fastai.vision import *
import pandas as pd
import matplotlib.pyplot as plt
import pandas as pd
import os
import numpy as np
import pandas as pd
import glob
import matplotlib.pyplot as plt
import imagehash
import psutil
from PIL import Image
from joblib import Parallel, delayed
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from IPython import display
import time
xgb_df = pd.DataFrame({
"image_name": test["image_name"],
"target": xgb_pred_result
})
 xgb_df.to_csv('tuned_XGBClassifier_submission.csv', index=False )<load_from_csv>
base_image_dir = os.path.join('.. ', 'input/aptos2019-blindness-detection/')
 train_dir = os.path.join(base_image_dir,'train_images/')
 df = pd.read_csv(os.path.join(base_image_dir, 'train.csv'))
df['path'] = df['id_code'].map(lambda x: os.path.join(train_dir,'{}.png'.format(x)))
 df = df.drop(columns=['id_code'])
 df = df.sample(frac=1 ).reset_index(drop=True)
 df.head()
main_submission = pd.read_csv('.. /input/my-siim-isic-submissions/my_siim_isic_main_submission.csv')
 efficient_b7 = pd.read_csv('.. /input/my-siim-isic-submissions/EfficientNetB7_submission.csv')
 efficient_b7_blend_6 = pd.read_csv('.. /input/my-siim-isic-submissions/EfficientNetB7_submission_Blend_6.csv')
 model_blend_0_6 = pd.read_csv('.. /input/my-siim-isic-submissions/submission_models_blended_0-6.csv' )<define_variables>
bs = 32
sz=140
final_target = main_submission.target *0.85 + efficient_b7.target *0.05 + xgb_df.target *0.10<save_to_csv>
def quadratic_kappa(y_hat, y):
return torch.tensor(cohen_kappa_score(torch.argmax(y_hat,1), y, weights='quadratic'),device='cuda:0' )
result = pd.DataFrame({
"image_name": test["image_name"],
"target": final_target
})
 result.to_csv('final_submission_blend.csv', index=False )<define_variables>
learn= cnn_learner(data, base_arch=models.vgg19_bn, metrics = [accuracy,quadratic_kappa] )
DEVICE = "TPU"
CFG = dict(
 batch_size = 16,
read_size = 256,
crop_size = 250,
net_size = 248,
LR_START = 0.000003,
LR_MAX = 0.000020,
LR_MIN = 0.000001,
LR_RAMPUP_EPOCHS = 5,
LR_SUSTAIN_EPOCHS = 0,
LR_EXP_DECAY = 0.8,
epochs = 13,
rot = 180.0,
shr = 1.5,
hzoom = 6.0,
wzoom = 6.0,
hshift = 6.0,
wshift = 6.0,
optimizer = 'adam',
label_smooth_fac = 0.05,
tta_steps = 25
)<install_modules>
learn.fit_one_cycle(7)
 learn.lr_find()
learn.recorder.plot()
!pip install -q efficientnet<set_options>
learn.data = data =(
 src.transform(get_transforms(tfms),size=255)
.databunch(bs=bs,num_workers=4)
.normalize() 
)
 learn.freeze()
random.seed(a=42)
<load_from_csv>
learn.unfreeze()
learn.fit_one_cycle(9,slice(1e-4,1e-3))
BASEPATH = ".. /input/siim-isic-melanoma-classification"
df_train = pd.read_csv(os.path.join(BASEPATH, 'train.csv'))
df_test = pd.read_csv(os.path.join(BASEPATH, 'test.csv'))
df_sub = pd.read_csv(os.path.join(BASEPATH, 'sample_submission.csv'))
GCS_PATH = KaggleDatasets().get_gcs_path('melanoma-256x256')
 files_train = np.sort(np.array(tf.io.gfile.glob(GCS_PATH + '/train*.tfrec')))
 files_test = np.sort(np.array(tf.io.gfile.glob(GCS_PATH + '/test*.tfrec')) )<choose_model_class>
sample_df = pd.read_csv('.. /input/aptos2019-blindness-detection/sample_submission.csv')
 learn.data.add_test(ImageList.from_df(sample_df,'.. /input/aptos2019-blindness-detection/',folder='test_images',suffix='.png'))
preds,y = learn.get_preds(DatasetType.Test )
<normalization><EOS> 
sample_df.diagnosis = preds.argmax(1)
 sample_df.head()
sample_df.to_csv('submission.csv',index=False )