{"nbformat": 4, "cells": [{"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", "from array import array\n", "import numpy as np\n", "import graphlab as gl\n", "gl.canvas.set_target('ipynb')"], "outputs": [], "metadata": {"_cell_guid": "190cb7a5-f6b8-471e-8951-3dc417d25b7b", "collapsed": true, "_uuid": "816e8ac3dcf679e2603a8ae3b8027d99a8dbd7f9"}, "execution_count": null, "cell_type": "code"}, {"source": ["## constants\n", "TRAIN_DIR = \"../input/train/\"\n", "TEST_DIR = \"../input/test/\"\n", "TRAIN_SIZE = 22500\n", "TEST_SIZE = 2500\n", "DEV_RATIO = 0.1\n", "IMAGE_HEIGHT = IMAGE_WIDTH = 128\n", "CHANNELS = 3\n", "OUTPUT_SIZE = 2"], "outputs": [], "metadata": {"_cell_guid": "6af43ef7-dbd4-4b86-a0c8-4c58951cad80", "collapsed": true, "_uuid": "3f970207c76ea4db203e9d384e3e53e39495d21c"}, "execution_count": null, "cell_type": "code"}, {"source": ["# Data preparation\n", "To start, we read provided data. \n", "\n", "The *../input/train/* dir contains 12500 cat images and 12500 dog images.\n", "Each filename contains \"cat\" or \"dog\" as label."], "metadata": {"_cell_guid": "1ff26ed6-bcf4-4c0d-b656-679092098bff", "_uuid": "12e4f1a6fe204e35500a17fcea8bcebda7481586"}, "cell_type": "markdown"}, {"source": ["image_sframe = gl.image_analysis.load_images(TRAIN_DIR)"], "outputs": [], "metadata": {"scrolled": true}, "execution_count": null, "cell_type": "code"}, {"source": ["image_sarray = image_sframe['image']"], "outputs": [], "metadata": {"collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["resized_image_sarry = gl.image_analysis.resize(image_sarray, IMAGE_HEIGHT, IMAGE_WIDTH, CHANNELS)"], "outputs": [], "metadata": {"collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["img1 = resized_image_sarry[0]"], "outputs": [], "metadata": {"collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["img1.pixel_data"], "outputs": [], "metadata": {}, "execution_count": null, "cell_type": "code"}, {"source": ["data = np.zeros((1000, IMAGE_HEIGHT*IMAGE_WIDTH*CHANNELS))\n", "for i in range(1000):\n", "    img = resized_image_sarry[i]\n", "    px_data = img1.pixel_data.reshape(1, IMAGE_HEIGHT*IMAGE_WIDTH*CHANNELS)\n", "    data[i] = px_data"], "outputs": [], "metadata": {"collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["# Analysis"], "metadata": {}, "cell_type": "markdown"}, {"source": ["<img src=\"../output/mems_cpu02.png\" style=\"width: 100%\">"], "metadata": {}, "cell_type": "markdown"}, {"source": ["* less memory and cpu than cv2\n"], "metadata": {}, "cell_type": "markdown"}, {"source": ["# Next"], "metadata": {}, "cell_type": "markdown"}, {"source": ["Explore TensorFlow.image"], "metadata": {}, "cell_type": "markdown"}], "nbformat_minor": 1, "metadata": {"kernelspec": {"display_name": "Python 2", "language": "python", "name": "python2"}, "language_info": {"pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}, "file_extension": ".py", "version": "2.7.10", "name": "python", "mimetype": "text/x-python", "nbconvert_exporter": "python"}}}