{"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 # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\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 pathlib import Path\n\n%matplotlib inline\nimport matplotlib.pyplot as plt\n\nimport tensorflow as tf\nfrom tensorflow import keras\nimport numpy as np\nimport pandas as pd\n\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D, Dropout, Dense, Flatten, BatchNormalization, MaxPooling2D, GlobalMaxPooling2D\nfrom tensorflow.keras.optimizers import Adam\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.callbacks import LearningRateScheduler","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def build_model(optimizer=Adam()):\n    model = Sequential()\n\n    model.add(Conv2D(64, kernel_size=3, padding='same', activation='relu', input_shape=(28, 28, 1)))\n    model.add(BatchNormalization())\n    model.add(Conv2D(64, kernel_size=3, padding='same', activation='relu'))\n    model.add(BatchNormalization())\n    model.add(Conv2D(64, kernel_size=5, padding='same', activation='relu'))\n    model.add(BatchNormalization())\n    model.add(MaxPooling2D(pool_size=(2, 2)))\n    model.add(Dropout(0.2))\n\n    model.add(Conv2D(128, kernel_size=3, activation='relu'))\n    model.add(BatchNormalization())\n    model.add(Conv2D(128, kernel_size=3, activation='relu'))\n    model.add(BatchNormalization())\n    model.add(Conv2D(128, kernel_size=5, padding='same', activation='relu'))\n    model.add(BatchNormalization())\n    model.add(MaxPooling2D(pool_size=(2, 2)))\n    model.add(Dropout(0.2))\n\n    model.add(Conv2D(256, kernel_size=3, activation='relu'))\n    model.add(BatchNormalization())\n    model.add(GlobalMaxPooling2D())\n    model.add(Dropout(0.2))\n\n    model.add(Flatten())\n    model.add(Dense(1024))\n    model.add(BatchNormalization())\n    model.add(Dense(1024))\n    model.add(BatchNormalization())\n    model.add(Dense(512))\n    model.add(BatchNormalization())\n    model.add(Dense(256))\n    model.add(BatchNormalization())\n    model.add(Dense(128))\n    model.add(BatchNormalization())\n    model.add(Dense(10, activation='softmax'))\n    \n    model.compile(loss='sparse_categorical_crossentropy',\n              optimizer=optimizer,\n              metrics=['accuracy'])\n    \n    return model","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model = build_model(Adam(learning_rate=1e-3))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"weightspath = Path.cwd()/'..'/'input'/'pretrained-larger-classifier-kannadamnist'/'model_fullTraining_initialPadding.h5'\nmodel.load_weights(str(weightspath))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_path = Path.cwd()/'..'/'input'/'Kannada-MNIST'/'test.csv'\n\nall_data_test = pd.read_csv(test_path)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"x_test = all_data_test.iloc[:,1:].values\nx_test = x_test.reshape(x_test.shape[0], 28, 28, 1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"predictions = model.predict_classes(x_test/255.)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"predictions[:10]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"output = pd.DataFrame({'id': all_data_test.id,\n                       'label': predictions})\noutput.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}