{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"3ede82eb-e79a-3ca3-bc36-25fc3ed2af65"},"outputs":[],"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%matplotlib inline\nimport matplotlib.pyplot as plt\nimport matplotlib.cm as cm\n\nimport tensorflow as tf\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 the files in the input directory\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"662ee0fb-96a2-2c2f-2684-f6450228880f"},"outputs":[],"source":"train = pd.read_csv(\"../input/train.csv\")\ntest = pd.read_csv(\"../input/test.csv\")\ntrain.describe()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"2700dfe7-6d20-8c70-c0fc-b851c3a72636"},"outputs":[],"source":"LEARNING_RATE = 1e-3\nTRAIN_ITERATION = 100\nBATCH_SIZE = 50\nVALIDATION_SIZE = 2000\nIMAGE_TO_DISPLAY = 10"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ad965425-f3f2-3101-3062-23ad1adf7746"},"outputs":[],"source":"imgs = train.iloc[:, 1:].values\nimgs = imgs.astype(np.float)\nimgs = np.multiply(imgs, 1. / 255.)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"d76ee44c-fc54-778f-b098-4c929e83f6e6"},"outputs":[],"source":"def display(img):\n    h = np.ceil(np.sqrt(img.shape[0])).astype(np.uint8)\n    w = np.ceil(img.shape[0]/h).astype(np.uint8)\n    tmp_img = img.reshape(w, h)\n    plt.axis(\"off\")\n    plt.imshow(tmp_img, cmap=cm.binary)\ndisplay(imgs[6])"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"af62f261-5332-fa08-ea4c-2ba647144170"},"outputs":[],"source":"labels = train.iloc[:, 0].values.ravel()\nlabels"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"3c6ccdbc-3c96-895b-57d6-f951fc8ad987"},"outputs":[],"source":"def dense_to_onehot(dense):\n    count = dense.shape[0]\n    onehot = np.zeros((count, 10))\n    index = np.arange(count) * 10\n    onehot.flat[index + dense] = 1\n    return onehot\n\nonehot_labels = dense_to_onehot(labels)\nprint(labels[:5])\nprint(onehot[:5])"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"38ab5738-a32b-3c68-358e-b7ed93254012"},"outputs":[],"source":"valid_imgs = imgs[:VALIDATION_SIZE]\nvalid_labels = onehot_labels[:VALIDATION_SIZE]\ntrain_imgs = imgs[VALIDATION_SIZE:]\ntrain_labels = onehot_label[VALIDATION_SIZE:]\n\nprint(train_imgs.shape)\nprint(valid_imgs.shape)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"073327a4-2bf8-a266-e457-951e7f03fbc8"},"outputs":[],"source":"def weight_variable(shape):\n    init = tf.truncated_normal(shape, stddev=.1)\n    return tf.Variable(init)\ndef bias_variable(shape):\n    init = tf.constant(0.1, shape=shape)\n    return tf.Variable(init)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"fec96198-8ec6-3fd7-d966-3dc5f15ec688"},"outputs":[],"source":"def conv2d(x, W):\n    return tf.nn.conv2d(x, W, [1,1,1,1], padding='SAME')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"1db6b942-1b3d-d277-86c2-454e2ac0bf7e"},"outputs":[],"source":"def max_pool_2x2(x):\n    return tf.nn.max_pool(x, ksize=[1,2,2,1], strides=[1,2,2,1], padding='SAME')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"66cf1b44-56a5-dd5b-3a8e-4d51de001283"},"outputs":[],"source":""}],"metadata":{"_change_revision":0,"_is_fork":false,"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.6.0"}},"nbformat":4,"nbformat_minor":0}