{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"60340853-5fc3-2fe8-67f8-0caeb598d72f"},"outputs":[],"source":"import cv2                 # working with, mainly resizing, images\nimport numpy as np         # dealing with arrays\nimport os                  # dealing with directories\nfrom random import shuffle # mixing up or currently ordered data that might lead our network astray in training.\nfrom tqdm import tqdm      # a nice pretty percentage bar for tasks. Thanks to viewer Daniel Bühler for this suggestion\n\nTRAIN_DIR = '../input/train'\nTEST_DIR = '../input/test'\nIMG_SIZE = 50\nLR = 1e-3\n\nMODEL_NAME = 'dogsvscats-{}-{}.model'.format(LR, '2conv-basic') # just so we remember which saved model is which, sizes must match"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"750b3879-67d9-bf2b-c8d4-4562ebf69749"},"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":"d04a9dba-5ffc-378f-105a-f3812f732251"},"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":"f6b4d563-d6a6-14e8-5e19-502c9029fc9b"},"outputs":[],"source":"#path = \"data/dogscats/sample/\"\npath = \"data/dogscats/\"\nmodel_path = path + 'models/'\nif not os.path.exists(model_path): os.mkdir(model_path)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"194e7889-06bd-2138-95f7-8f2391221865"},"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}