{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"38867759-872f-47d2-dd5a-8edaf00210be"},"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":"868b9570-4450-a639-fedf-17f72e10fc4b"},"outputs":[],"source":"import cv2\nimport numpy as np\nimport os\nfrom random import shuffle\nfrom tqdm import tqdm"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"1e67b6b9-3b20-3551-3da7-a20f932e36e5"},"outputs":[],"source":"TRAIN_DIR = '../input/train'\nTEST_DIR = '../input/test'\nIMG_SIZE = 50\nLR = 1e-3\nMODEL_NAME = 'dogsvscats-{}-{}.model'.format(LR, '2conv-basic')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ff754c55-cbd7-0a85-6fa8-3c4cd8a592f8"},"outputs":[],"source":"def label_img(img):\n    word_label = img.split('.')[-3]\n    # conversion to one-hot array [cat,dog]\n    #                            [much cat, no dog]\n    if word_label == 'cat': return [1,0]\n    #                             [no cat, very doggo]\n    elif word_label == 'dog': return [0,1]"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"54403bc8-d84f-2862-7b75-33a948ff1fbd"},"outputs":[],"source":"def create_train_data():\n    training_data = []\n    for img in tqdm(os.listdir(TRAIN_DIR)):\n        label = label_img(img)\n        path = os.path.join(TRAIN_DIR,img)\n        img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)\n        img = cv2.resize(img, (IMG_SIZE,IMG_SIZE))\n        training_data.append([np.array(img),np.array(label)])\n    shuffle(training_data)\n    np.save('train_data.npy', training_data)\n    return training_data"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"0dfdcb74-72b2-40b7-8052-b3c4f95d9783"},"outputs":[],"source":"def process_test_data():\n    testing_data = []\n    for img in tqdm(os.listdir(TEST_DIR)):\n        path = os.path.join(TEST_DIR,img)\n        img_num = img.split('.')[0]\n        img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)\n        img = cv2.resize(img, (IMG_SIZE,IMG_SIZE))\n        testing_data.append([np.array(img), img_num])\n        \n    shuffle(testing_data)\n    np.save('test_data.npy', testing_data)\n    return testing_data"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ac6746bb-ce46-1c7b-0f29-dc079123a1d6"},"outputs":[],"source":"train_data = create_train_data()"}],"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}