Kaggle competition: Digit Recognizer
<SOS> metric: categorizationaccuracy Kaggle data source: digit-recognizer<concatenate>
%matplotlib inline
np.random.seed(2)
 print(os.listdir(".. /input"))
Y_train = tf.keras.utils.to_categorical(Y_train, num_classes = 10 )<split>
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )
X_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size = 0.1, random_state=0 )<init_hyperparams>
train = pd.read_csv(".. /input/train.csv")
 test = pd.read_csv(".. /input/test.csv" )
efficientnet_size = 7
weights = "imagenet"
size = 56<choose_model_class>
X_train = X_train / 255.0
test = test / 255.0
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Conv2D(filters = 3, kernel_size = 1, padding = 'Same',
activation ='relu', input_shape =(size,size,1)))
 model.add(getattr(efn, f"EfficientNetB{efficientnet_size}" )(
 weights=weights, include_top=False, input_shape=(size, size, 3)))
 model.add(tf.keras.layers.GlobalAveragePooling2D())
 model.add(tf.keras.layers.Flatten())
 model.add(tf.keras.layers.Dense(10, activation = "softmax"))<choose_model_class>
X_train = X_train.values.reshape(-1, 28, 28, 1)
 test = test.values.reshape(-1, 28, 28, 1 )
optimizer = tf.keras.optimizers.Adam(lr=0.0001 )<choose_model_class>
Y_train = to_categorical(Y_train, num_classes = 10 )
model.compile(optimizer = optimizer , loss = "categorical_crossentropy", metrics=["accuracy"] )<train_model>
random_seed = 2
tf.random.set_seed(0)
 history = model.fit(X_train,
Y_train,
epochs=10,
batch_size=128,
validation_data=(X_val, Y_val),
)<predict_on_test>
X_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size = 0.05, random_state = random_seed )
pred = model.predict_classes(test )<load_from_csv>
model = Sequential()
model.add(Conv2D(filters = 32, kernel_size =(5, 5), padding = 'Same', activation = 'relu', input_shape =(28, 28, 1)))
 model.add(BatchNormalization())
 model.add(Conv2D(filters = 32, kernel_size =(5, 5), padding = 'Same', activation = 'relu'))
model.add(BatchNormalization())
 model.add(MaxPool2D(pool_size =(2, 2)))
 model.add(Dropout(0.25))
model.add(Conv2D(filters = 64, kernel_size =(3, 3), padding = 'Same', activation = 'relu'))
model.add(BatchNormalization())
 model.add(Conv2D(filters = 64, kernel_size =(3, 3), padding = 'Same', activation = 'relu'))
model.add(BatchNormalization())
 model.add(MaxPool2D(pool_size =(2, 2), strides =(2, 2)))
 model.add(Dropout(0.25))
model.add(Flatten())
 model.add(Dense(256, activation = 'relu'))
model.add(Dropout(0.25))
model.add(Dense(10, activation = 'softmax'))
submission = pd.read_csv(".. /input/digit-recognizer/sample_submission.csv" )<prepare_output>
optimizer = RMSprop(lr = 0.001, rho = 0.9, epsilon = 1e-08, decay = 0.0 )
submission["Label"] = pred<save_to_csv>
learning_rate_reduction = ReduceLROnPlateau(monitor = 'val_acc', patience = 3, verbose = 1, factor = 0.5, min_lr = 0.00001 )
submission.to_csv("submission.csv",index=False )<define_variables>
epochs = 30
batch_size = 86
mod_path = '/kaggle/input/04-04/'
THRESHOLD = 0.4
WINDOW = 1024
MIN_OVERLAP = 300
NEW_SIZE = 512
SUBMISSION_MODE = 'FULL'
CHECKSUM = False 
<import_modules>
datagen = ImageDataGenerator(
 featurewise_center = False,
samplewise_center = False,
featurewise_std_normalization = False,
samplewise_std_normalization = False,
zca_whitening = False,
rotation_range = 10,
zoom_range = 0.1,
width_shift_range = 0.1,
height_shift_range = 0.1,
horizontal_flip = False,
vertical_flip = False)
 datagen.fit(X_train )
import numpy as np
import pandas as pd
import os
import glob
import gc
import rasterio
from rasterio.windows import Window
import pathlib
from tqdm.notebook import tqdm
import cv2
import tensorflow as tf 
<install_modules>
history = model.fit_generator(datagen.flow(X_train, Y_train, batch_size = batch_size), epochs = epochs, validation_data =(X_val, Y_val),
verbose = 2, steps_per_epoch = X_train.shape[0] // batch_size, callbacks = [learning_rate_reduction] )
!pip install -U.. /input/kerasapplications/Keras_Applications-1.0.8-py3-none-any.whl
!pip install.. /input/qubvel/efficientnet-1.0.0-py3-none-any.whl
!pip install.. /input/qubvel/image_classifiers-1.0.0-py3-none-any.whl
!pip install.. /input/qubvel-segmentation-model-keras-v101/segmentation_models-master
%env SM_FRAMEWORK=tf.keras<categorify>
results = model.predict(test)
 results = np.argmax(results,axis = 1)
 results = pd.Series(results,name="Label" )
<load_pretrained><EOS> 
submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1)
 submission.to_csv("submission.csv",index=False )