Kaggle competition: Cassava Leaf Disease Classification
del_cols=[item for item in df_train.columns if "Date" in item]
df_train=df_train.drop(del_cols,axis=1 ).copy()
df_test=df_test.drop(del_cols,axis=1 ).copy() 
<concatenate>
CFG = {
'model_arch': 'tf_efficientnet_b5_ns',
'img_size': 456,
'valid_bs': 32,
'num_workers': 4,
'device': 'cuda:0',
'tta': 3,
'used_epochs': [3,11,9,9,5],
'weights': [1,1,1,1,1]
}
submission = pd.read_csv('.. /input/cassava-leaf-disease-classification/sample_submission.csv')
 submission.head()
df_all = pd.concat([df_train,df_test] ).reset_index(drop=True )<count_missing_values>
class CassvaImgClassifier(nn.Module):
def __init__(self, model_arch, n_class, pretrained=False):
super().__init__()
self.model = timm.create_model(model_arch, pretrained=pretrained)
 n_features = self.model.classifier.in_features
self.model.classifier = nn.Linear(n_features, n_class)
 def forward(self, x):
x = self.model(x)
 return x
print(f'<prepare_x_and_y>
test = pd.DataFrame()
test['image_id'] = list(os.listdir('.. /input/cassava-leaf-disease-classification/test_images/'))
test_ds = CassavaDataset(test, '.. /input/cassava-leaf-disease-classification/test_images/', transforms=get_inference_transforms() , output_label=False)
 tst_loader = torch.utils.data.DataLoader(
 test_ds,
batch_size=CFG['valid_bs'],
num_workers=CFG['num_workers'],
shuffle=False,
pin_memory=False, 
)
 device = torch.device(CFG['device'])
 model = CassvaImgClassifier(CFG['model_arch'], 5 ).to(device )
df_train_x = df_all[df_all.date <= "2018-06-30"].copy()
df_train_y = df_all[df_all.date >= "2018-08-15"].copy()
id_train = df_all[(df_all.date >= "2018-01-15")&(df_all.date <= "2018-06-30")].fullVisitorId.drop_duplicates()
df_train_x = df_train_x[df_train_x.fullVisitorId.isin(id_train)].copy()
df_train_y = df_train_y[df_train_y.fullVisitorId.isin(id_train)].copy()
df_test_x = df_all[(df_all.date >= "2016-11-15")&(df_all.date <= "2018-10-15")].copy()
id_test = df_all[(df_all.date >= "2018-05-01")&(df_all.date <= "2018-10-15")].fullVisitorId.drop_duplicates()
df_test_x = df_test_x[df_test_x.fullVisitorId.isin(id_test)].copy()<data_type_conversions>
val_preds = []
tst_preds = []
for fold, epoch in enumerate(CFG['used_epochs']):
model.load_state_dict(torch.load('.. /input/b5-weight/{}_fold_{}_{}'.format(CFG['model_arch'], fold, epoch)))
 with torch.no_grad() :
for _ in range(CFG['tta']):
tst_preds += [CFG['weights'][fold]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, tst_loader, device)]
tst_preds = np.sum(tst_preds, axis=0)
 del model
torch.cuda.empty_cache()
<categorify><EOS> 
test['label'] = np.argmax(tst_preds, axis=1)
 test.to_csv('submission.csv', index=False)
 test.head()