Kaggle competition: Cassava Leaf Disease Classification
<SOS> metric: CategorizationAccuracy Kaggle data source: cassava-leaf-disease-classification<load_from_csv>
print("Tensorflow version " + tf.__version__ )
df_train = pd.read_csv('.. /input/cat-in-the-dat/train.csv',index_col=0)
 df_test = pd.read_csv('.. /input/cat-in-the-dat/test.csv',index_col=0)
 print('There are no missing values in the dataset.')
 print(f"There are {df_train.shape[1]} features and {df_train.shape[0]:,} observation.")
 d = df_train.astype('str' ).describe().T
d['top, %'] = d['freq']/df_train.shape[0]*100
d.drop(['count','freq'],axis=1 )<define_variables>
IMAGE_SIZE = 512
BATCH_SIZE = 64
target = 'target'
bin_cols = [col for col in df_train.columns if 'bin' in col]
cyclic_cols = ['day','month']
ord_cols = [col for col in df_train.columns if 'ord' in col]
nom_cols = [col for col in df_train.columns if 'nom' in col]
no_target = [col for col in df_train.columns if 'target' not in col]<compute_test_metric>
test_dir = ".. /input/cassava-leaf-disease-classification/test_images"
mean_1_contrast(df_train,bin_cols )<compute_test_metric>
def get_preds_model_list_norm_inds(image_dir, model_obj_list, TTA=True, aug_num=5, normalize_indices=None):

 preds = []
img_ids = []
for i in glob.glob(image_dir+"/*.jpg"):
print(i)
 image = Image.open(i)
 image = image.resize(( IMAGE_SIZE, IMAGE_SIZE))
aug_imgs = [seq(image=np.array(image)) *(( 1-g)+g/255)for j in range(aug_num)for g in normalize_indices]
avg_pred = np.concatenate([mod.predict(np.expand_dims(aug_imgs[i], axis = 0)) for i in range(aug_num)for mod in model_obj_list] ).mean(0)
 preds.append(np.argmax(avg_pred))
img_ids.append(i.replace(image_dir+"/", ""))
return(pd.DataFrame({'image_id':img_ids,
'label':preds}))
mean_1_contrast(df_train,cyclic_cols )<compute_test_metric>
def get_preds_model_list(image_dir, model_obj_list, TTA=True, aug_num=5, normalize=True):
preds = []
img_ids = []
for i in glob.glob(image_dir+"/*.jpg"):
print(i)
 image = Image.open(i)
 image = image.resize(( IMAGE_SIZE, IMAGE_SIZE))
if(TTA):
if normalize:
aug_imgs = [seq(image=np.array(image)) /255 for j in range(aug_num)]
else:
aug_imgs = [seq(image=np.array(image)) for j in range(aug_num)]
avg_pred = np.concatenate([mod.predict(np.expand_dims(aug_imgs[i], axis = 0)) for i in range(aug_num)for mod in model_obj_list] ).mean(0)
 else:
image = image/255
avg_pred = np.concatenate([mod.predict(image)for mod in model_obj_list] ).mean(0)
 preds.append(np.argmax(avg_pred))
img_ids.append(i.replace(image_dir+"/", ""))
return(pd.DataFrame({'image_id':img_ids,
'label':preds}))
mean_1_contrast(df_train,ord_cols )<compute_train_metric>
def get_preds(image_dir, model_obj, normalize=True):
preds = []
img_ids = []
for i in glob.glob(image_dir+"/*.jpg"):
image = Image.open(i)
 image = image.resize(( IMAGE_SIZE, IMAGE_SIZE))
image = np.expand_dims(image, axis = 0)
 if normalize:
image = image/255
preds.append(np.argmax(model_obj.predict(image)))
 img_ids.append(i.replace(image_dir+"/", ""))
return(pd.DataFrame({'image_id':img_ids,
'label':preds}))
<compute_train_metric><EOS> 
predict_df = get_preds_model_list(test_dir, mod_lst, normalize=False, aug_num=5)
 predict_df.to_csv("submission.csv", index=False )