{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b90e2af0-5007-0063-7f34-b355f9aa2033"},"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":"cd9a746b-a930-ee82-9179-f255b902036a"},"outputs":[],"source":"import cv2\nimport numpy as np\nimport os\nfrom random import shuffle\nfrom tqdm import tqdm\n\nTRAIN_DIR = '../input/train'\nTEST_DIR = '../input/test'\nIMG_SIZE = 50\nLR  = 1e-3\n\nMODEL_NAME = 'dogvscat-{}-{}.model'.format(LR, '2conv-basic')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"30bc1b77-23ab-71d7-2977-99133269c570"},"outputs":[],"source":"def label_img(img):\n    word_label = img.split('.')[-3]\n    if word_label == 'cat': return [1,0]\n    elif world_label == 'dog' : return [0,1]"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"7b89b7b5-6199-a4f9-790b-2eb65c220f42"},"outputs":[],"source":"def create_train_data():\n    train_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.resize(cv2.imread(path,cv2.IMREAD_GRAYSCALE), (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":"ecfe9f81-416e-596c-4bfb-a9e4c381eb50"},"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.resize(cv2.imread(path, cv2.IMREAD_GRAYSCALE), (IMG_SIZE,IMG_SIZE))\n        testing_data.append([np.array(img), img_num])\n    np.save('test.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}