{"cells":[{"metadata":{"_cell_guid":"582b8200-b0f4-4d22-8d53-e6ca16f42448","_uuid":"35c49e298c366f2bc92496d5599302f860cea24c"},"cell_type":"markdown","source":"### Table of Contents\n\n1. Overview of the Problem set\n\n2. Load and prep the data\n\n3. Building the parts of our algorithm.\n\n4. Merge all functions into a model\n\n5. Visualizing and Analysis\n\n6. Lab"},{"metadata":{"collapsed":true,"_cell_guid":"5d2b419a-782c-4e88-8a0e-029bc370a4f7","_uuid":"3f8d9ebfebb6284901972fa4784aea55d56461e9","trusted":true},"cell_type":"code","source":"import os\nimport random\nimport sys\nimport datetime\n## pip3 install opencv-python\nimport cv2\nimport numpy as np\n\n\nimport matplotlib.pyplot as plt\n\n%matplotlib inline","execution_count":1,"outputs":[]},{"metadata":{"collapsed":true,"_cell_guid":"988e7a87-a84e-4c4d-a04e-f235744d2719","_uuid":"d8e9bbd59c0d4e414d6347eebf89b446bd0fbce2","trusted":true},"cell_type":"code","source":"## constants\nTRAIN_DIR = \"../input/train/\"\nTEST_DIR = \"../input/test/\"\nTRAIN_SIZE = 25000\nTEST_SIZE = 12500\nDEV_RATIO = 0.1\nIMAGE_HEIGHT = IMAGE_WIDTH = 128\n\nLEARNING_RATE = 0.0001\nMINIBATCH_SIZE = 32\nINPUT_SIZE = IMAGE_HEIGHT * IMAGE_WIDTH * 3\nOUTPUT_SIZE = 2","execution_count":2,"outputs":[]},{"metadata":{"collapsed":true,"_cell_guid":"cdd3ecf1-c7e7-4c30-8f91-c9330c69576d","_uuid":"bfd4d4eafe5cd53f8b0468ce8adf125ca521f34e","trusted":false},"cell_type":"code","source":"TRAIN_DIR","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"d963047b-6da5-4105-acc8-61e9ab517d73","_uuid":"f9620920ff201325c902eadedeb038cd75001600"},"cell_type":"markdown","source":"### Overview of the Problem set\nA fun project to differentiate dogs from cats. Dataset is from Kaggle: https://www.kaggle.com/c/dogs-vs-cats-redux-kernels-edition.\n\nThe ./input/train/ dir contains 12500 cat images and 12500 dog images. Each filename contains \"cat\" or \"dog\" as label.\n\nThe ./input/test/ dir contains 12500 images to classify\n"},{"metadata":{"_cell_guid":"eb738ee9-f45d-40fe-912b-a451356bf26a","_uuid":"ecc4bd971a49290696a875867cd67651a48e8887"},"cell_type":"markdown","source":"### Load and prep the data"},{"metadata":{"collapsed":true,"_cell_guid":"e8b9f49f-b223-4077-8fbc-ef28e0000235","_uuid":"66cfd34f2267c11a5e8aa0c2b3e81012a970ab27","trusted":true},"cell_type":"code","source":"def load_data(dirname=TRAIN_DIR, file_count=1000, shuffle=True):\n    all_filenames = os.listdir(dirname)\n    random.shuffle(all_filenames)\n    filenames = all_filenames[:file_count]\n    \n    ## images\n    images = np.zeros((file_count, IMAGE_HEIGHT*IMAGE_WIDTH*3))\n    for i in range(file_count):\n        imgnd_origin = cv2.imread(dirname+filenames[i])\n        imgnd_resized = cv2.resize(imgnd_origin, (IMAGE_HEIGHT, IMAGE_WIDTH), interpolation=cv2.INTER_CUBIC)\n        imgnd_flatten = imgnd_resized.reshape(1,-1)\n        images[i] = imgnd_flatten\n    \n    ## labels from filenames\n    labels_list = [\"dog\" in filename for filename in filenames]\n    labels = np.array(labels_list, dtype='int8').reshape(file_count, 1)\n    \n    ## shuffle\n    if shuffle:\n        permutation = list(np.random.permutation(labels.shape[0]))\n        labels = labels[permutation, :]\n        images = images[permutation, :]\n\n    ## normalization\n    images = images/255.0\n    \n    return images.T, labels.T","execution_count":4,"outputs":[]},{"metadata":{"_cell_guid":"3e93f445-d7c9-432c-beda-440c63e18bf1","_uuid":"eb37bba8e617a8a60e64abc5fadbe4fb477c5ae1","trusted":true,"collapsed":true},"cell_type":"code","source":"images, labels = load_data(file_count=200)\ndev_images, train_images = split_data(images)\ndev_labels, train_labels = split_data(labels)","execution_count":5,"outputs":[]}],"metadata":{"language_info":{"name":"python","version":"3.6.5","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}},"nbformat":4,"nbformat_minor":1}