{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"cebfc412-9cd3-64c9-6fff-e62a87391843"},"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# 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\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"9869d6b3-9d71-9727-b7ba-5cc79d0f5311"},"outputs":[],"source":"\nimport numpy as np \nimport pandas as pd \n\nfrom subprocess import check_output\n\nimport os, cv2, random\nimport numpy as np\nimport pandas as pd\n\nfrom keras.models import Sequential\nfrom keras.layers import Input, Dropout, Flatten, Convolution2D, MaxPooling2D, Dense, Activation\nfrom keras.optimizers import RMSprop\nfrom keras.callbacks import ModelCheckpoint, Callback, EarlyStopping\nfrom keras.utils import np_utils\n\n\nTRAIN_DIR = '../input/train/'\nTEST_DIR = '../input/test/'\n\nROWS = 32\nCOLS = 32\nCHANNELS = 1\n\ntrain_images = [TRAIN_DIR+i for i in os.listdir(TRAIN_DIR)] \n\n\ntest_images =  [TEST_DIR+i for i in os.listdir(TEST_DIR)]\n\n\ndef read_image(file_path):\n    img = cv2.imread(file_path, cv2.IMREAD_GRAYSCALE) #cv2.IMREAD_GRAYSCALE\n    return cv2.resize(img, (ROWS, COLS), interpolation=cv2.INTER_CUBIC)\n\n\ndef prep_data(images):\n    count = len(images)\n    data = np.ndarray((count, CHANNELS, ROWS, COLS), dtype=np.uint8)\n\n    for i, image_file in enumerate(images):\n        image = read_image(image_file)\n        data[i] = image.T\n        \n    \n    return data\n\ntrain = prep_data(train_images)\ntest = prep_data(test_images)\n\n\n\nlabels = []\nfor i in train_images:\n    if 'dog' in i:\n        labels.append(1)\n    else:\n        labels.append(0)\n        \ntrain = train.reshape(-1, 32,32,1)\ntest = test.reshape(-1, 32,32,1)\nX_train = train.astype('float32')\nX_test = test.astype('float32')\nX_train /= 255\nX_test /= 255\nY_train=labels\n\nx=np.array(X_train)\nprint(x.shape)\nX_valid = X_train[:5000,:,:,:]\nY_valid =   Y_train[:5000]\nX_train = X_train[5001:25000,:,:,:]\nY_train  = Y_train[5001:25000]"}],"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}