Kaggle competition: Cassava Leaf Disease Classification
<SOS> metric: CategorizationAccuracy Kaggle data source: cassava-leaf-disease-classification<define_search_model>
package_path = '.. /input/pytorch-image-models/pytorch-image-models-master'
class enet_v2(nn.Module):
def __init__(self, backbone, out_dim, pretrained=False):
super(enet_v2, self ).__init__()
self.enet = timm.create_model(backbone, pretrained=pretrained)
 in_ch = self.enet.classifier.in_features
self.myfc = nn.Linear(in_ch, out_dim)
 self.enet.classifier = nn.Identity()
def forward(self, x):
x = self.enet(x)
 x = self.myfc(x)
 return x<load_pretrained>
from glob import glob
from sklearn.model_selection import GroupKFold, StratifiedKFold
import cv2
from skimage import io
import torch
from torch import nn
import os
from datetime import datetime
import time
import random
import cv2
import torchvision
from torchvision import transforms
import pandas as pd
import numpy as np
from tqdm import tqdm
import matplotlib.pyplot as plt
from torch.utils.data import Dataset,DataLoader
from torch.utils.data.sampler import SequentialSampler, RandomSampler
from torch.cuda.amp import autocast, GradScaler
import sklearn
import warnings
import joblib
from sklearn.metrics import roc_auc_score, log_loss
from sklearn import metrics
import warnings
import cv2
import pydicom
import timm
from scipy.ndimage.interpolation import zoom
from sklearn.metrics import log_loss
def load_state(model_path):
model = CustomResNext(CFG.model_name, pretrained=False)
 try:
model.load_state_dict(torch.load(model_path)['model'], strict=True)
 state_dict = torch.load(model_path)['model']
except:
state_dict = torch.load(model_path)['model']
state_dict = {k[7:] if k.startswith('module.')else k: state_dict[k] for k in state_dict.keys() }
return state_dict
def inference(model, states, test_loader, device):
model.to(device)
 tk0 = tqdm(enumerate(test_loader), total=len(test_loader))
probs = []
for i,(images)in tk0:
images = images.to(device)
 avg_preds = []
for state in states:
model.load_state_dict(state)
 model.eval()
with torch.no_grad() :
y_preds = model(images)
 avg_preds.append(y_preds.softmax(1 ).to('cpu' ).numpy())
 avg_preds = np.mean(avg_preds, axis=0)
 probs.append(avg_preds)
 probs = np.concatenate(probs)
 return probs<create_dataframe>
CFG = {
'fold_num': 5,
'seed': 719,
'model_arch': 'tf_efficientnet_b4_ns',
'img_size': 512,
'epochs': 10,
'train_bs': 32,
'valid_bs': 32,
'lr': 1e-4,
'num_workers': 4,
'accum_iter': 1,
'verbose_step': 1,
'device': 'cuda:0',
'tta': 3,
'used_epochs': [4,5,6,7],
'weights': [1,1,1,1]
}
model = CustomResNext(CFG.model_name, pretrained=False)
 states = [load_state(MODEL_DIR+f'{CFG.model_name}_fold{fold}.pth')for fold in CFG.trn_fold]
test_dataset = TestDataset(test, transform=get_transforms(data='valid'))
test_loader = DataLoader(test_dataset, batch_size=CFG.batch_size, shuffle=False,
num_workers=CFG.num_workers, pin_memory=True)
 predictions = inference(model, states, test_loader, device)
 test_preds = []
for i in range(len(enet_type)) :
model = enet_v2(enet_type[i], out_dim=5)
 model = model.to(device)
 model.load_state_dict(torch.load(model_path[i]))
test_preds += [tta_inference_func(test_loader_efficient)]
pred = 0.5*predictions + 0.5*np.mean(test_preds, axis=0)
 test['label'] = softmax(pred ).argmax(1)
 test[['image_id', 'label']].to_csv(OUTPUT_DIR+'submission.csv', index=False)
 test.head()<set_options>
train = pd.read_csv('.. /input/cassava-leaf-disease-classification/train.csv')
 train.head()
plt.style.use('seaborn-white')
 sns.set_style('white')
 plt.rcParams['figure.figsize'] = [16, 10]
plt.rcParams['font.size'] = 14
%matplotlib inline
warnings.filterwarnings("ignore")
 BatchNormalization, Activation, GlobalAveragePooling2D,
MaxPooling2D, concatenate, Reshape, Add, multiply)
 t_start = time.time()<define_variables>
train.label.value_counts()
basic_name = f'Unet_resnet'
save_model_name = basic_name + '.model'
submission_file = basic_name + '.csv'
TRAIN_IMAGE_DIR = '.. /input/train/images/'
TRAIN_MASK_DIR = '.. /input/train/masks/'
TEST_IMAGE_DIR = '.. /input/test/images/'
img_size = 101
seed=1994
batch_size = 128
epochs = 120<compute_train_metric>
submission = pd.read_csv('.. /input/cassava-leaf-disease-classification/sample_submission.csv')
 submission.head()
def get_iou_vector(A, B):
batch_size = A.shape[0]
metric = []
for batch in range(batch_size):
t, p = A[batch]>0, B[batch]>0
intersection = np.logical_and(t, p)
 union = np.logical_or(t, p)
 iou =(np.sum(intersection > 0)+ 1e-10)/(np.sum(union > 0)+ 1e-10)
 thresholds = np.arange(0.5, 1, 0.05)
 s = []
for thresh in thresholds:
s.append(iou > thresh)
 metric.append(np.mean(s))
return np.mean(metric)
 def my_iou_metric(label, pred):
return tf.py_func(get_iou_vector, [label, pred>0.5], tf.float64)
 def my_iou_metric_2(label, pred):
return tf.py_func(get_iou_vector, [label, pred >0], tf.float64)
 def iou_metric(y_true_in, y_pred_in, print_table=False):
labels = y_true_in
y_pred = y_pred_in
true_objects = 2
pred_objects = 2
temp1 = np.histogram2d(labels.flatten() , y_pred.flatten() , bins=([0,0.5,1], [0,0.5, 1]))
intersection = temp1[0]
area_true = np.histogram(labels,bins=[0,0.5,1])[0]
area_pred = np.histogram(y_pred, bins=[0,0.5,1])[0]
area_true = np.expand_dims(area_true, -1)
 area_pred = np.expand_dims(area_pred, 0)
 union = area_true + area_pred - intersection
intersection = intersection[1:,1:]
intersection[intersection == 0] = 1e-9
union = union[1:,1:]
union[union == 0] = 1e-9
iou = intersection / union
def precision_at(threshold, iou):
matches = iou > threshold
true_positives = np.sum(matches, axis=1)== 1
false_positives = np.sum(matches, axis=0)== 0
false_negatives = np.sum(matches, axis=1)== 0
tp, fp, fn = np.sum(true_positives), np.sum(false_positives), np.sum(false_negatives)
 return tp, fp, fn
prec = []
if print_table:
print("Thresh\tTP\tFP\tFN\tPrec.")
 for t in np.arange(0.5, 1.0, 0.05):
tp, fp, fn = precision_at(t, iou)
 if(tp + fp + fn)> 0:
p = tp /(tp + fp + fn)
 else:
p = 0
if print_table:
print("{:1.3f}\t{}\t{}\t{}\t{:1.3f}".format(t, tp, fp, fn, p))
prec.append(p)
 if print_table:
print("AP\t-\t-\t-\t{:1.3f}".format(np.mean(prec)))
 return np.mean(prec)
 def iou_metric_batch(y_true_in, y_pred_in):
batch_size = y_true_in.shape[0]
metric = []
for batch in range(batch_size):
value = iou_metric(y_true_in[batch], y_pred_in[batch])
 metric.append(value)
 return np.mean(metric)
 def lovasz_grad(gt_sorted):

 gts = tf.reduce_sum(gt_sorted)
 intersection = gts - tf.cumsum(gt_sorted)
 union = gts + tf.cumsum(1.- gt_sorted)
 jaccard = 1.- intersection / union
jaccard = tf.concat(( jaccard[0:1], jaccard[1:] - jaccard[:-1]), 0)
 return jaccard
def lovasz_hinge(logits, labels, per_image=True, ignore=None):

 if per_image:
def treat_image(log_lab):
log, lab = log_lab
log, lab = tf.expand_dims(log, 0), tf.expand_dims(lab, 0)
 log, lab = flatten_binary_scores(log, lab, ignore)
 return lovasz_hinge_flat(log, lab)
 losses = tf.map_fn(treat_image,(logits, labels), dtype=tf.float32)
 loss = tf.reduce_mean(losses)
 else:
loss = lovasz_hinge_flat(*flatten_binary_scores(logits, labels, ignore))
return loss
def lovasz_hinge_flat(logits, labels):

 def compute_loss() :
labelsf = tf.cast(labels, logits.dtype)
 signs = 2.* labelsf - 1.
 errors = 1.- logits * tf.stop_gradient(signs)
 errors_sorted, perm = tf.nn.top_k(errors, k=tf.shape(errors)[0], name="descending_sort")
 gt_sorted = tf.gather(labelsf, perm)
 grad = lovasz_grad(gt_sorted)
 loss = tf.tensordot(tf.nn.elu(errors_sorted), tf.stop_gradient(grad), 1, name="loss_non_void")
 return loss
loss = tf.cond(tf.equal(tf.shape(logits)[0], 0),
lambda: tf.reduce_sum(logits)* 0.,
compute_loss, strict=True, name="loss")
 return loss
def flatten_binary_scores(scores, labels, ignore=None):

 scores = tf.reshape(scores,(-1,))
labels = tf.reshape(labels,(-1,))
if ignore is None:
return scores, labels
valid = tf.not_equal(labels, ignore)
 vscores = tf.boolean_mask(scores, valid, name='valid_scores')
 vlabels = tf.boolean_mask(labels, valid, name='valid_labels')
 return vscores, vlabels
def lovasz_loss(y_true, y_pred):
y_true, y_pred = K.cast(K.squeeze(y_true, -1), 'int32'), K.cast(K.squeeze(y_pred, -1), 'float32')
 logits = y_pred
loss = lovasz_hinge(logits, y_true, per_image = True, ignore = None)
 return loss
def symmetric_lovasz(y_true, y_pred):
y_true, y_pred = K.cast(K.squeeze(y_true, -1), 'int32'), K.cast(K.squeeze(y_pred, -1), 'float32')
 loss =(( lovasz_hinge(y_pred, y_true, per_image = True, ignore = None)) + \ 
(lovasz_hinge(-y_pred, 1 - y_true, per_image = True, ignore = None)))/2
return loss<feature_engineering>
def seed_everything(seed):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 torch.manual_seed(seed)
 torch.cuda.manual_seed(seed)
 torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = True
def get_img(path):
im_bgr = cv2.imread(path)
 im_rgb = im_bgr[:, :, ::-1]
return im_rgb
train_df = pd.read_csv(".. /input/train.csv", index_col="id", usecols=[0])
 train_df["images"] = [np.array(load_img(TRAIN_IMAGE_DIR + "{}.png".format(idx), color_mode = "grayscale")) / 255
for idx in tqdm_notebook(train_df.index)]
train_df["masks"] = [np.array(load_img(TRAIN_MASK_DIR + "{}.png".format(idx), color_mode = "grayscale")) / 255
for idx in tqdm_notebook(train_df.index)]
train_df["coverage"] = train_df.masks.map(np.sum)/ pow(img_size, 2)
 def cov_to_class(val):
for i in range(0, 11):
if val * 10 <= i : return i
train_df["coverage_class"] = train_df.coverage.map(cov_to_class)
 train_df.head()<split>
class CassavaDataset(Dataset):
def __init__(
 self, df, data_root, transforms=None, output_label=True 
):
super().__init__()
self.df = df.reset_index(drop=True ).copy()
self.transforms = transforms
self.data_root = data_root
self.output_label = output_label
def __len__(self):
return self.df.shape[0]
def __getitem__(self, index: int):
if self.output_label:
target = self.df.iloc[index]['label']
path = "{}/{}".format(self.data_root, self.df.iloc[index]['image_id'])
 img = get_img(path)
 if self.transforms:
img = self.transforms(image=img)['image']
if self.output_label == True:
return img, target
else:
return img
X = np.array(train_df.images.tolist() ).reshape(-1, img_size, img_size, 1)
 y = np.array(train_df.masks.tolist() ).reshape(-1, img_size, img_size, 1)
 x_train, x_valid, y_train, y_valid = \
train_test_split(
 X, y,
test_size=0.2,
stratify=train_df.coverage_class,
random_state=seed
)<define_search_model>
HorizontalFlip, VerticalFlip, IAAPerspective, ShiftScaleRotate, CLAHE, RandomRotate90,
Transpose, ShiftScaleRotate, Blur, OpticalDistortion, GridDistortion, HueSaturationValue,
IAAAdditiveGaussianNoise, GaussNoise, MotionBlur, MedianBlur, IAAPiecewiseAffine, RandomResizedCrop,
IAASharpen, IAAEmboss, RandomBrightnessContrast, Flip, OneOf, Compose, Normalize, Cutout, CoarseDropout, ShiftScaleRotate, CenterCrop, Resize 
)
 HorizontalFlip, VerticalFlip, IAAPerspective, ShiftScaleRotate, CLAHE, RandomRotate90,
Transpose, ShiftScaleRotate, Blur, OpticalDistortion, GridDistortion, HueSaturationValue,
IAAAdditiveGaussianNoise, GaussNoise, MotionBlur, MedianBlur, IAAPiecewiseAffine, RandomResizedCrop,
IAASharpen, IAAEmboss, RandomBrightnessContrast, Flip, OneOf, Compose, Normalize, Cutout, CoarseDropout, ShiftScaleRotate, CenterCrop, Resize 
)
 def get_train_transforms() :
return Compose([
RandomResizedCrop(CFG['img_size'], CFG['img_size']),
Transpose(p=0.5),
HorizontalFlip(p=0.5),
VerticalFlip(p=0.5),
ShiftScaleRotate(p=0.5),
HueSaturationValue(hue_shift_limit=0.2, sat_shift_limit=0.2, val_shift_limit=0.2, p=0.5),
RandomBrightnessContrast(brightness_limit=(-0.1,0.1), contrast_limit=(-0.1, 0.1), p=0.5),
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], max_pixel_value=255.0, p=1.0),
CoarseDropout(p=0.5),
Cutout(p=0.5),
ToTensorV2(p=1.0),
], p=1.)
def get_valid_transforms() :
return Compose([
CenterCrop(CFG['img_size'], CFG['img_size'], p=1.) ,
Resize(CFG['img_size'], CFG['img_size']),
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], max_pixel_value=255.0, p=1.0),
ToTensorV2(p=1.0),
], p=1.)
def get_inference_transforms() :
return Compose([
RandomResizedCrop(CFG['img_size'], CFG['img_size']),
Transpose(p=0.5),
HorizontalFlip(p=0.5),
VerticalFlip(p=0.5),
HueSaturationValue(hue_shift_limit=0.2, sat_shift_limit=0.2, val_shift_limit=0.2, p=0.5),
RandomBrightnessContrast(brightness_limit=(-0.1,0.1), contrast_limit=(-0.1, 0.1), p=0.5),
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], max_pixel_value=255.0, p=1.0),
ToTensorV2(p=1.0),
], p=1.)
def BatchActivate(x):
x = BatchNormalization()(x)
 x = Activation('elu' )(x)
 return x
def convolution_block(x, filters, size, strides=(1,1), padding='same', activation=True):
x = Conv2D(filters, size, strides=strides, padding=padding )(x)
 if activation==True: x = BatchActivate(x)
 return x
def residual_block(blockInput, num_filters=16, batch_activate=False):
x = BatchActivate(blockInput)
 x = convolution_block(x, num_filters,(3,3))
x = convolution_block(x, num_filters,(3,3), activation=False)
 x = Add()([x, blockInput])
 if batch_activate: x = BatchActivate(x)
 return x
def squeeze_excite_block_cSE(input_, ratio=2):
init = input_
filters = K.int_shape(init)[-1]
se_shape =(1, 1, filters)
 se = GlobalAveragePooling2D()(init)
 se = Reshape(se_shape )(se)
 se = Dense(filters // ratio, activation='relu', kernel_initializer='he_normal', use_bias=True )(se)
 se = Dense(filters, activation='sigmoid', kernel_initializer='he_normal', use_bias=True )(se)
 x = multiply([init, se])
 return x
def squeeze_excite_block_sSE(input_):
sSE_scale = Conv2D(1,(1, 1), activation='sigmoid', padding="same", use_bias = True )(input_)
 return multiply([input_, sSE_scale])
 def unet_layer(blockInput, num_filters, use_csSE_ratio = 2):
x = Conv2D(num_filters,(3, 3), activation=None, padding="same" )(blockInput)
 x = residual_block(x, num_filters)
 x = residual_block(x, num_filters , batch_activate = True)
 if use_csSE_ratio > 0:
sSEx = squeeze_excite_block_sSE(x)
 cSEx = squeeze_excite_block_cSE(x,ratio = use_csSE_ratio)
 x = Add()([sSEx, cSEx])
 return x<choose_model_class>
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
def build_model(input_layer, start_neurons, DropoutRatio=0.5):
conv1 = unet_layer(input_layer,start_neurons * 1,use_csSE_ratio=2)
 pool1 = MaxPooling2D(( 2,2))(conv1)
 pool1 = Dropout(DropoutRatio/3 )(pool1)
 conv2 = unet_layer(pool1, start_neurons * 2,use_csSE_ratio=2)
 pool2 = MaxPooling2D(( 2,2))(conv2)
 pool2 = Dropout(DropoutRatio/2 )(pool2)
 conv3 = unet_layer(pool2, start_neurons * 4,use_csSE_ratio=2)
 pool3 = MaxPooling2D(( 2,2))(conv3)
 pool3 = Dropout(DropoutRatio )(pool3)
 conv4 = unet_layer(pool3, start_neurons * 8,use_csSE_ratio=2)
 pool4 = MaxPooling2D(( 2,2))(conv4)
 pool4 = Dropout(DropoutRatio )(pool4)
 convm = Conv2D(start_neurons*16,(3,3), activation=None, padding='same' )(pool4)
 convm = residual_block(convm, start_neurons*16)
 convm = residual_block(convm, start_neurons*16, True)
 deconv4 = Conv2DTranspose(start_neurons*8,(3,3), strides=(2,2), padding='same' )(convm)
 uconv4 = concatenate([deconv4, conv4])
 uconv4 = Dropout(DropoutRatio )(uconv4)
 uconv4 = Conv2D(start_neurons*8,(3,3), activation=None, padding='same' )(uconv4)
 uconv4 = residual_block(uconv4, start_neurons*8)
 uconv4 = residual_block(uconv4, start_neurons*8, True)
 deconv3 = Conv2DTranspose(start_neurons*4,(3,3), strides=(2,2), padding='valid' )(uconv4)
 uconv3 = concatenate([deconv3, conv3])
 uconv3 = Dropout(DropoutRatio )(uconv3)
 uconv3 = Conv2D(start_neurons*4,(3,3), activation=None, padding='same' )(uconv3)
 uconv3 = residual_block(uconv3, start_neurons*4)
 uconv3 = residual_block(uconv3, start_neurons*4, True)
 deconv2 = Conv2DTranspose(start_neurons*2,(3,3), strides=(2,2), padding='same' )(uconv3)
 uconv2 = concatenate([deconv2, conv2])
 uconv2 = Dropout(DropoutRatio )(uconv2)
 uconv2 = Conv2D(start_neurons*2,(3,3), activation=None, padding='same' )(uconv2)
 uconv2 = residual_block(uconv2, start_neurons*2)
 uconv2 = residual_block(uconv2, start_neurons*2, True)
 deconv1 = Conv2DTranspose(start_neurons*1,(3,3), strides=(2,2), padding='valid' )(uconv2)
 uconv1 = concatenate([deconv1, conv1])
 uconv1 = Dropout(DropoutRatio )(uconv1)
 uconv1 = Conv2D(start_neurons*1,(3,3), activation=None, padding='same' )(uconv1)
 uconv1 = residual_block(uconv1, start_neurons*1)
 uconv1 = residual_block(uconv1, start_neurons*1, True)
 output_layer_noActi = Conv2D(1,(1,1), padding='same', activation=None )(uconv1)
 output_layer = Activation('sigmoid' )(output_layer_noActi)
 return output_layer<normalization>
if __name__ == '__main__':
seed_everything(CFG['seed'])
 folds = StratifiedKFold(n_splits=CFG['fold_num'] ).split(np.arange(train.shape[0]), train.label.values)
 for fold,(trn_idx, val_idx)in enumerate(folds):
if fold > 0:
break
print('Inference fold {} started'.format(fold))
valid_ = train.loc[val_idx,:].reset_index(drop=True)
 valid_ds = CassavaDataset(valid_, '.. /input/cassava-leaf-disease-classification/train_images/', transforms=get_inference_transforms() , output_label=False)
 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)
 val_loader = torch.utils.data.DataLoader(
 valid_ds,
batch_size=CFG['valid_bs'],
num_workers=CFG['num_workers'],
shuffle=False,
pin_memory=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'], train.label.nunique() ).to(device)
 val_preds = []
tst_preds = []
for i, epoch in enumerate(CFG['used_epochs']):
model.load_state_dict(torch.load('.. /input/eb33333smooth/{}_fold_{}_{}'.format(CFG['model_arch'], fold, epoch)))
 with torch.no_grad() :
for _ in range(CFG['tta']):
val_preds += [CFG['weights'][i]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, val_loader, device)]
tst_preds += [CFG['weights'][i]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, tst_loader, device)]
val_preds = np.mean(val_preds, axis=0)
 tst_preds = np.mean(tst_preds, axis=0)
 print('fold {} validation loss = {:.5f}'.format(fold, log_loss(valid_.label.values, val_preds)))
 print('fold {} validation accuracy = {:.5f}'.format(fold,(valid_.label.values==np.argmax(val_preds, axis=1)).mean()))
del model
torch.cuda.empty_cache()
def do_augmentation(seqs, seq2_train, X_train, y_train):
seq_det = seqs.to_deterministic()
X_train_aug = seq_det.augment_image(X_train)
 X_train_aug = seq2_train.augment_image(X_train_aug)
 y_train_aug = seq_det.augment_image(y_train)
 if y_train_aug.shape !=(101, 101):
X_train_aug = ia.imresize_single_image(X_train_aug,(101, 101), interpolation="linear")
 y_train_aug = ia.imresize_single_image(y_train_aug,(101, 101), interpolation="nearest")
 return np.array(X_train_aug), np.array(y_train_aug)
 sometimes = lambda aug: iaa.Sometimes(0.5, aug)
 seq = iaa.Sequential([
iaa.Fliplr(0.5),
iaa.OneOf([
iaa.Noop() ,
iaa.Affine(rotate=(-10, 10), translate_percent={"x":(-0.25, 0.25)}, mode='symmetric', cval=(0), backend="cv2"),
iaa.Noop() ,
iaa.CropAndPad(
 percent=(-0.2, 0.2),
pad_mode="reflect",
pad_cval=0,
keep_size=False 
),
])
 ])
 seq_train = iaa.Sequential(
 sometimes(iaa.Multiply(( 0.8, 1.2))),
sometimes(iaa.Add(( -0.2, 0.2))),
sometimes(iaa.OneOf([
iaa.AdditiveGaussianNoise(scale=(0, 0.05)) ,
iaa.GaussianBlur(sigma=(0.0, 1.0)) ,
])) 
)
 def make_image_gen(features, labels, batch_size=32):
all_batches_index = np.arange(0, features.shape[0])
 out_images = []
out_masks = []
while True:
np.random.shuffle(all_batches_index)
 for index in all_batches_index:
c_img, c_mask = do_augmentation(seq, seq_train, features[index], labels[index])
 out_images += [c_img]
out_masks += [c_mask]
if len(out_images)>= batch_size:
yield np.stack(out_images, 0), np.stack(out_masks, 0)
 out_images, out_masks = [], []<choose_model_class>
OUTPUT_DIR = './'
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
 test['label'] = np.argmax(tst_preds, axis=1)
 test.head()
<train_model><EOS> 
test.to_csv(OUTPUT_DIR+'submission.csv', index=False )