Kaggle competition: Kannada MNIST
<SOS> metric: CategorizationAccuracy Kaggle data source: kannada-mnist<set_options>
import numpy as np
import pandas as pd
import datetime
from sklearn.model_selection import train_test_split
from keras.utils.np_utils import to_categorical
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Dense, Flatten, Dropout, Conv2D, MaxPooling2D, Lambda, LeakyReLU
from keras.layers.normalization import BatchNormalization
from keras.optimizers import Adam
from keras.callbacks import LearningRateScheduler
warnings.filterwarnings("ignore")
<define_variables>
train = pd.read_csv("/kaggle/input/Kannada-MNIST/train.csv")
 Dig = pd.read_csv("/kaggle/input/Kannada-MNIST/Dig-MNIST.csv")
 train_data = train.append(Dig)
 y_train = np.array(train_data["label"])
 y_train = to_categorical(y_train)
 x_train = train_data.drop("label",axis=1 ).values
x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
 x_train.shape, y_train.shape
def seed_everything(seed=2020):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 tf.random.set_seed(seed)
 seed_everything(42 )<define_variables>
X_train, X_valid, Y_train, Y_valid = train_test_split(x_train, y_train, test_size = 0.10, random_state=0)
 train_datagen = ImageDataGenerator(rescale = 1./255.,
rotation_range = 10,
width_shift_range = 0.25,
height_shift_range = 0.25,
shear_range = 0.1,
zoom_range = 0.25,
horizontal_flip = False)
 valid_datagen = ImageDataGenerator(rescale=1./255 )
ROOT = ".. /input/osic-pulmonary-fibrosis-progression"
BATCH_SIZE= 130<load_from_csv>
model = Sequential()
model.add(Conv2D(64,(3,3), padding='same', input_shape=(28, 28, 1)))
 model.add(BatchNormalization(momentum=0.5, epsilon=1e-5, gamma_initializer="uniform"))
model.add(LeakyReLU(alpha=0.1))
model.add(Conv2D(64,(3,3), padding='same'))
model.add(BatchNormalization(momentum=0.1, epsilon=1e-5, gamma_initializer="uniform"))
model.add(LeakyReLU(alpha=0.1))
model.add(MaxPooling2D(2, 2))
model.add(Dropout(0.2))
model.add(Conv2D(128,(3,3), padding='same'))
model.add(BatchNormalization(momentum=0.2, epsilon=1e-5, gamma_initializer="uniform"))
model.add(LeakyReLU(alpha=0.1))
model.add(Conv2D(128,(3,3), padding='same'))
model.add(BatchNormalization(momentum=0.1, epsilon=1e-5, gamma_initializer="uniform"))
model.add(LeakyReLU(alpha=0.1))
model.add(MaxPooling2D(2, 2))
model.add(Dropout(0.2))
model.add(Conv2D(256,(3,3), padding='same'))
model.add(BatchNormalization(momentum=0.2, epsilon=1e-5, gamma_initializer="uniform"))
model.add(LeakyReLU(alpha=0.1))
model.add(Conv2D(128,(3,3), padding='same'))
model.add(BatchNormalization(momentum=0.1, epsilon=1e-5, gamma_initializer="uniform"))
model.add(LeakyReLU(alpha=0.1))
model.add(MaxPooling2D(2, 2))
model.add(Dropout(0.2))
model.add(Flatten())
 model.add(Dense(256,activation='relu',name='dense1'))
model.add(LeakyReLU(alpha=0.1))
model.add(BatchNormalization())
 model.add(Dense(10,activation='softmax'))
train = pd.read_csv(f"{ROOT}/train.csv")
 train.drop_duplicates(keep=False, inplace=True, subset=['Patient','Weeks'])
 test = pd.read_csv(f"{ROOT}/test.csv" )<merge>

 initial_learningrate=2e-3
def lr_decay(epoch):
return initial_learningrate * 0.99 ** epoch
model.compile(loss="categorical_crossentropy", optimizer=Adam(lr=initial_learningrate), metrics=["acc"])
 model.fit_generator(train_datagen.flow(X_train, Y_train, batch_size=2048),
steps_per_epoch=300,
epochs=10,
callbacks=[LearningRateScheduler(lr_decay,verbose=1)],
validation_data=valid_datagen.flow(X_valid,Y_valid),
validation_steps=50,
verbose=1 )
<concatenate><EOS> 
X_test = pd.read_csv("/kaggle/input/Kannada-MNIST/test.csv")
 X_test = X_test.drop("id", axis=1 ).values
submission = pd.read_csv("/kaggle/input/Kannada-MNIST/sample_submission.csv")
 X_test = X_test.reshape(X_test.shape[0], 28, 28, 1)
 X_test = X_test.astype(np.float32)/ 255
predictions = model.predict_classes(X_test)
 submissions=pd.DataFrame({"id": submission["id"], "label": predictions})
 submissions.to_csv("sUbmission.csv", index=False)
 print("FINISH" )