{"cells": [{"cell_type": "code", "outputs": [], "metadata": {"_uuid": "9d53efb9620c3d9afd9dcbdd31cdcbe7efd66071", "trusted": false, "_cell_guid": "505058ca-c090-7072-5160-05de4d0bd203"}, "execution_count": null, "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", "outputs": [], "metadata": {"_uuid": "f26b38711366fede562bd32d314a2aa8f47403f8", "trusted": false, "_cell_guid": "0553b215-97e5-2068-c59d-242b59f8cd01"}, "execution_count": null, "source": "import keras\nfrom keras.models import Sequential, Model\nfrom keras.layers.core import Flatten, Dense, Dropout, Lambda\nfrom keras.layers import Input\nfrom keras.layers.convolutional import Convolution2D, MaxPooling2D, ZeroPadding2D"}, {"cell_type": "code", "outputs": [], "metadata": {"_uuid": "c20b5c511d174769e8499ce5c7b132c3dd7081c7", "trusted": false, "_cell_guid": "ef119a29-fc79-b697-e0ae-1074bbfb5059"}, "execution_count": null, "source": "def ConvBlock(layers, model, filters):\n    for i in range(layers): \n        model.add(ZeroPadding2D((1,1)))\n        model.add(Convolution2D(filters, 3, 3, activation='relu'))\n    model.add(MaxPooling2D((2,2), strides=(2,2), dim_ordering=\"th\"))\n"}, {"cell_type": "code", "outputs": [], "metadata": {"_uuid": "1ddd19610b5ada38ae30ffd4f7e7079d86e1212f", "trusted": false, "_cell_guid": "4214712d-1ee1-e48f-769c-6ffb7dae3e71"}, "execution_count": null, "source": "Untitled Folderdef FCBlock(model):\n    model.add(Dense(4096, activation='relu'))\n    model.add(Dropout(0.5))"}, {"cell_type": "code", "outputs": [], "metadata": {"_uuid": "fd765fb77d5b94123e2b1fddef05c7e6e436effb", "trusted": false, "_cell_guid": "1d64921f-671a-0aa6-27c1-43d1908b6631"}, "execution_count": null, "source": "# Mean of each channel as provided by VGG researchers\nvgg_mean = np.array([123.68, 116.779, 103.939]).reshape((3,1,1))\n\ndef vgg_preprocess(x):\n    x = x - vgg_mean     # subtract mean\n    return x[:, ::-1]    # reverse axis bgr->rgb"}, {"cell_type": "code", "outputs": [], "metadata": {"_uuid": "d6f9cb17b929a0a99e645965b02112bc31ad40d3", "trusted": false, "_cell_guid": "6035c92b-9d44-16b9-02c0-b2f0d26a4d22"}, "execution_count": null, "source": "def VGG_16():\n    model = Sequential()\n    model.add(Lambda(vgg_preprocess, input_shape=(3,224,224)))\n\n    ConvBlock(2, model, 64)\n    ConvBlock(2, model, 128)\n    ConvBlock(3, model, 256)\n    ConvBlock(3, model, 512)\n    ConvBlock(3, model, 512)\n\n    model.add(Flatten())\n    FCBlock(model)\n    FCBlock(model)\n    model.add(Dense(1000, activation='softmax'))\n    return model"}, {"cell_type": "code", "outputs": [], "metadata": {"_uuid": "ece986637b3af398851ea361b8193f35e972c24a", "trusted": false, "_cell_guid": "ac43eac7-2d1f-cd84-fe00-83ea66bd26aa"}, "execution_count": null, "source": "model = VGG_16()"}, {"cell_type": "code", "outputs": [], "metadata": {"_uuid": "b0323d1c6ef68797ca6798ea1e19e4f99d9e8e5f", "trusted": false, "_cell_guid": "574c7647-6441-8fef-26dd-8578097eb1cd"}, "execution_count": null, "source": ""}], "nbformat": 4, "metadata": {"_change_revision": 0, "_is_fork": false, "kernelspec": {"language": "python", "display_name": "Python 3", "name": "python3"}, "language_info": {"nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1", "mimetype": "text/x-python", "codemirror_mode": {"name": "ipython", "version": 3}, "name": "python", "file_extension": ".py"}}, "nbformat_minor": 0}