{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "1217c59f-1de0-7189-ffa3-34e0826b0dd5"
      },
      "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",
        "\n",
        "import numpy as np # linear algebra\n",
        "import 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",
        "\n",
        "from subprocess import check_output\n",
        "print(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": "f18c39b8-8e0e-0bb8-1fba-ea0d340cd4fc"
      },
      "outputs": [],
      "source": [
        "train_data_dir = './data/train'\n",
        "validation_data_dir = './data/validation'"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "7500254a-02c4-33c6-3eb9-44f7f9eeb22f"
      },
      "outputs": [],
      "source": [
        "import os\n",
        "import h5py\n",
        "import numpy as np\n",
        "from keras.preprocessing.image import ImageDataGenerator\n",
        "from keras.models import Sequential\n",
        "from keras.layers import Convolution2D, MaxPooling2D, ZeroPadding2D\n",
        "from keras.layers import Activation, Dropout, Flatten, Dense"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "3920cb13-88d6-9ef1-2f47-7bbc68339487"
      },
      "outputs": [],
      "source": [
        "%matplotlib inline\n",
        "\n",
        "import glob\n",
        "import os\n",
        "import re\n",
        "\n",
        "import matplotlib.image as mpimg\n",
        "import matplotlib.pyplot as plt\n",
        "import numpy as np\n",
        "import pandas as pd\n",
        "import PIL\n",
        "from PIL import Image"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "0edaaf81-8bfc-8c37-567f-d4f916b51b59"
      },
      "source": [
        "Lets Explore the images first:"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "317abe37-8f89-7e22-4ffb-69ea8e10d1ff"
      },
      "outputs": [],
      "source": [
        "os.listdir()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "e2076245-3ef1-bb11-4811-f874fd6f6192"
      },
      "outputs": [],
      "source": ""
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "909935a0-06ab-1061-69d1-8e61acaa0958"
      },
      "outputs": [],
      "source": [
        "cat_img = plt.imread('../input/train/cat.10.jpg')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "3ffd0c8b-8111-7bf3-ee69-698b2a8c33a4"
      },
      "outputs": [],
      "source": [
        "plt.imshow(cat_img)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "42bf1134-5cb0-e4a4-8d7b-8aedcf8b2bc2"
      },
      "source": [
        "First we are going to preprocess our data. which is required for image net. i.e first we need to create a separate directory for both cats and dogs. And also we need to do resizing the images.Then we'll use image net model which is available in keras for the modeling part.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "167fbc05-fe03-db6d-d3b9-b189f2329116"
      },
      "outputs": [],
      "source": [
        "from __future__ import division, print_function\n",
        "\n",
        "import os, json\n",
        "from glob import glob\n",
        "import numpy as np\n",
        "from scipy import misc, ndimage\n",
        "from scipy.ndimage.interpolation import zoom\n",
        "\n",
        "from keras.utils.data_utils import get_file\n",
        "from keras import backend as K\n",
        "from keras.layers.normalization import BatchNormalization\n",
        "from keras.utils.data_utils import get_file\n",
        "from keras.models import Sequential\n",
        "from keras.layers.core import Flatten, Dense, Dropout, Lambda\n",
        "from keras.layers.convolutional import Convolution2D, MaxPooling2D, ZeroPadding2D\n",
        "from keras.layers.pooling import GlobalAveragePooling2D\n",
        "from keras.optimizers import SGD, RMSprop, Adam\n",
        "from keras.preprocessing import image\n",
        "\n",
        "vgg_mean = np.array([123.68, 116.779, 103.939], dtype=np.float32).reshape((3,1,1))\n",
        "def vgg_preprocess(x):\n",
        "    x = x - vgg_mean\n",
        "    return x[:, ::-1] # reverse axis rgb->bgr\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "3264b2e4-038a-79fd-d87a-14d4b0e4633d"
      },
      "outputs": [],
      "source": ""
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "00142f96-c5d7-b51f-e79e-0e6dd1013c6f"
      },
      "outputs": [],
      "source": [
        "def pre_process()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "3ee5fb39-6819-e3ea-9c0f-fb8680ef8a25"
      },
      "outputs": [],
      "source": [
        "import h5py\n",
        "from keras import backend as K\n",
        "K.set_image_dim_ordering('th')\n",
        "\n",
        "weights_path = './vgg16_weights.h5'\n",
        "top_model_weights_path = 'bottleneck_fc_model.h5'"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "236689a0-ebca-fc65-0474-2467e6490264"
      },
      "outputs": [],
      "source": [
        "path = '../inpu'"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "ab2f1384-26b2-9782-2add-54d015e32936"
      },
      "outputs": [],
      "source": [
        "from keras.applications.vgg16 import VGG16\n",
        "from keras.preprocessing import image\n",
        "from keras.applications.vgg16 import preprocess_input\n",
        "from keras.applications.resnet50 import preprocess_input, decode_predictions\n",
        "import numpy as np\n",
        "\n",
        "model = VGG16(weights='imagenet', include_top=False)\n",
        "\n",
        "\n",
        "img = image.load_img(cat_img, target_size=(224, 224))\n",
        "x = image.img_to_array(img)\n",
        "x = np.expand_dims(x, axis=0)\n",
        "x = preprocess_input(x)\n",
        "\n",
        "features = model.predict(x)\n",
        "print('Predicted:', decode_predictions(features, top=3)[0])"
      ]
    }
  ],
  "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.5.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}