{"metadata":{"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,"cells":[{"metadata":{"_cell_guid":"c0f0ea27-9899-b2e9-28f9-d48c6242b650","_active":false,"collapsed":false},"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 BA1/4hler for this suggestion\n\nTRAIN_DIR = 'C:/Users/jagrati.shivhare.ITLINFOSYS/Desktop/train'\nTEST_DIR = 'C:/Users/jagrati.shivhare.ITLINFOSYS/Desktop/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","execution_count":6,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"34b2fde4-cd82-f3be-927d-fa6ced31bf13","_active":false,"collapsed":false},"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]","execution_count":7,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"b4679e20-c2ed-019f-38a1-c1bfd8066c17","_active":true,"collapsed":false},"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('C:/Users/jagrati.shivhare.ITLINFOSYS/Desktop/train_data.npy', training_data)\n    return training_data","execution_count":8,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"8ff31f08-eb69-bff6-632d-685f4050a739","_active":false,"collapsed":false},"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('C:/Users/jagrati.shivhare.ITLINFOSYS/Desktop/test_data.npy', testing_data)\n    return testing_data","execution_count":9,"cell_type":"code","outputs":[],"execution_state":"idle"},{"metadata":{"_cell_guid":"613f29f0-9f70-7da6-4d0d-3dc45c1eee29","_active":false,"collapsed":false},"source":"train_data = create_train_data()","execution_count":10,"cell_type":"code","outputs":[],"execution_state":"idle"}]}