{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np \nimport pandas as pd \nimport tensorflow as tf\nfrom tensorflow.keras.callbacks import ReduceLROnPlateau, EarlyStopping\nfrom sklearn.model_selection import train_test_split\nfrom tensorflow.keras import layers, models\nfrom tensorflow import keras\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"from __future__ import absolute_import, division, print_function, unicode_literals\n\ntf.keras.backend.clear_session() ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data = pd.read_csv(\"/kaggle/input/Kannada-MNIST/train.csv\")\n\ntarget = train_data['label']\ntrain_vars = train_data.drop(['label'],axis=1)\n\nX_train = train_vars/255\ny = target\n\nX_train = X_train.values.reshape(X_train.shape[0],28,28,1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"inputs = keras.Input(shape=(28, 28, 1), name='img')\nx = layers.Conv2D(32, 3, activation='relu')(inputs)\nx = layers.BatchNormalization()(x)\nx = layers.Conv2D(64, 3, activation='relu')(x)\nx = layers.BatchNormalization()(x)\nblock_1_output = layers.MaxPooling2D(3)(x)\n\nx = layers.Conv2D(64, 3, activation='relu', padding='same')(block_1_output)\nx = layers.BatchNormalization()(x)\nx = layers.Conv2D(64, 3, activation='relu', padding='same')(x)\nx = layers.BatchNormalization()(x)\nblock_2_output = layers.add([x, block_1_output])\n\nx = layers.Conv2D(64, 3, activation='relu', padding='same')(block_2_output)\nx = layers.BatchNormalization()(x)\nx = layers.Conv2D(64, 3, activation='relu', padding='same')(x)\nx = layers.BatchNormalization()(x)\nblock_3_output = layers.add([x, block_2_output])\n\nx = layers.Conv2D(64, 3, activation='relu', padding='same')(block_3_output)\nx = layers.BatchNormalization()(x)\nx = layers.Conv2D(64, 3, activation='relu', padding='same')(x)\nblock_4_output = layers.add([x, block_3_output])\n\n\n\nx = layers.Conv2D(64, 3, activation='relu')(block_4_output)\nx = layers.GlobalAveragePooling2D()(x)\nx = layers.Dense(256, activation='relu')(x)\nx = layers.Dropout(0.5)(x)\noutputs = layers.Dense(10, activation='softmax')(x)\n\nmodel = keras.Model(inputs, outputs, name='kannada_resnet')\nmodel.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])\n\nes = EarlyStopping(monitor='val_loss',mode='min',verbose=1,patience=8)\nlr_reduction = ReduceLROnPlateau(monitor='val_loss',patience=5,verbose=1,factor=0.2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model.fit(X_train,np.array(y),\n          epochs=50,validation_split=0.2,\n         batch_size=128, shuffle=True,callbacks =[lr_reduction,es])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_data = pd.read_csv('/kaggle/input/Kannada-MNIST/test.csv')\nImageId = test_data['id']\nNN_test = test_data.drop(['id'],axis=1)\nNN_test = NN_test/255\nNN_test = NN_test.values.reshape(NN_test.shape[0],28,28,1)\n\npredictions = np.argmax(model.predict(NN_test),axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub = pd.DataFrame({'id':ImageId, 'label':predictions})\nsub.to_csv(\"submission.csv\",index=False)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}