Kaggle competition: Cassava Leaf Disease Classification
<SOS> metric: CategorizationAccuracy Kaggle data source: cassava-leaf-disease-classification<feature_engineering>
import os
import tensorflow as tf
from tensorflow import keras
from keras.preprocessing.image import load_img,img_to_array,smart_resize
import matplotlib.pyplot as plt
import cv2
import pandas as pd
import json
import numpy as np
X = new_features(X)
 X_test = new_features(X_test )<train_model>
model1=keras.models.load_model('.. /input/notebook841c84bbfb/IncepResNetV2.h5')
 model2=keras.models.load_model('.. /input/notebook841c84bbfb/EfficientNetB_V2.h5' )
oof_lgb, prediction_lgb, _ = train_model(X, X_test, y, params=params, model_type='lgb', plot_feature_importance=True )<train_model>
train_dir='.. /input/cassava-leaf-disease-classification/train_images'
test_dir='.. /input/cassava-leaf-disease-classification/test_images'
train=pd.read_csv('.. /input/cassava-leaf-disease-classification/train.csv')
 sample_sub=pd.read_csv('.. /input/cassava-leaf-disease-classification/sample_submission.csv')
 sample_sub
xgb_params = {'eta': 0.01,
'objective': 'reg:linear',
'max_depth': 7,
'subsample': 0.8,
'colsample_bytree': 0.8,
'eval_metric': 'rmse',
'seed': 11,
'silent': True}
oof_xgb, prediction_xgb= train_model(X, X_test, y, params=xgb_params, model_type='xgb', plot_feature_importance=True )<define_variables>
def sample_df(sample_size=100):
df= train.sample(sample_size)
 df=df.reset_index()
return df
dfs=sample_df(sample_size=50)
 preds=[]
y_true=dfs['label']
for im_id in dfs.image_id:
img=load_img(train_dir + '/' + im_id)
 img=img_to_array(img)
 img=smart_resize(img,(512,512))
img=np.expand_dims(img,axis=0)
 img=img/255
pred=np.argmax(( 0.5*model1.predict(img)) +(0.5 * model2.predict(img)))
 preds.append(pred)
cat_params = {'learning_rate': 0.002,
'depth': 5,
'l2_leaf_reg': 10,
'colsample_bylevel': 0.8,
'bagging_temperature': 0.2,
'od_type': 'Iter',
'od_wait': 100,
'random_seed': 11,
'allow_writing_files': False}
oof_cat, prediction_cat = train_model(X, X_test, y, params=cat_params, model_type='cat' )<create_dataframe>
sample_test=pd.DataFrame({'Prediction':preds, 'Actual':y_true})
 sample_test.head(30 )
<train_on_grid><EOS> 
predictions=[]
for img_id in sample_sub.image_id:
img=load_img(test_dir + '/' + img_id)
 img=img_to_array(img)
 img=smart_resize(img,(512,512))
img=np.expand_dims(img,axis=0)
 img=img/255
lab=np.argmax(( model1.predict(img)* 0.5)+(model2.predict(img)*0.5))
predictions.append(lab)
 submission=pd.DataFrame({'image_id':sample_sub.image_id , 'label':predictions})
 print(submission)
 submission.to_csv('submission.csv',index=False )