{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","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\nimport numpy as np # linear algebra\nimport 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\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true,"scrolled":true},"cell_type":"code","source":"from keras.preprocessing.image import ImageDataGenerator \nfrom keras.models import Sequential \nfrom keras.layers import Conv2D, MaxPooling2D \nfrom keras.layers import Activation, Dropout, Flatten, Dense \nfrom keras import backend as K \nimport numpy as np \nfrom keras.preprocessing import image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"087ef3fcff57366aea92238a4f69a2127c5564d3"},"cell_type":"code","source":"img_width, img_height = 150,150\n\ntrain_data_dir = \"../input/train\"\ntest_data_dir = \"../input/test\"\n\nnum_train_samples = 1000\nnum_val_samples = 100\nepochs = 50\nbatch_size = 20\n\n#if K.common.image_data_format() =='channels_first':\n #   input_shape = (3, img_height, img_height)\n#else:\ninput_shape = (img_width, img_height,3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8261512b310a05ee954fe10567f2966249bef6c0"},"cell_type":"code","source":"train_datagen = ImageDataGenerator(\n        rescale=1./255,\n        zoom_range=0.2,\n        horizontal_flip=True,\n        shear_range=0.2)\n\ntest_datagen = ImageDataGenerator(rescale=1./255)\n\ntrain_generator = train_datagen.flow_from_directory(\n    train_data_dir,\n    target_size = (img_width, img_height),\n    batch_size = batch_size,\n    class_mode = 'binary')\n\nvalidation_generator = test_datagen.flow_from_directory(\n    test_data_dir,\n    target_size = (img_width, img_height),\n    batch_size = batch_size,\n    class_mode = 'binary')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":false,"_uuid":"d3a94963f28238f34a243b70e672047252f742ca"},"cell_type":"code","source":"model = Sequential()\nmodel.add(Conv2D(32, kernel_size=(3,3), activation='relu', input_shape=input_shape))\nmodel.add(MaxPooling2D(2,2))\n\nmodel.summary()\nprint('\\n')\n\nmodel.add(Conv2D(32, kernel_size=(3,3), activation='relu'))\nmodel.add(MaxPooling2D(2,2))\n\nmodel.summary()\nprint('\\n')\n\nmodel.add(Conv2D(64, kernel_size=(3,3), activation='relu'))\nmodel.add(MaxPooling2D(2,2))\n\nmodel.summary()\nprint('\\n')\n\nmodel.add(Flatten())\nmodel.add(Dense(64, activation='relu'))\nmodel.add(Dropout(0.5))\nmodel.add(Dense(1, activation='relu'))\n\nmodel.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1c9928e5630454d697f83e4c447a7baad706e07e"},"cell_type":"code","source":"model.compile(loss='binary_crossentropy',\n             optimizer='rmsprop',\n             metrics=['accuracy'])\n\nmodel.fit_generator(train_generator, \n                   steps_per_epoch=num_train_samples // batch_size,\n                   epochs=epochs,\n                   validation_data=validation_generator,\n                   validation_steps=num_val_samples // batch_size)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cc155e7d9404f19a51f6c168361745356ecd1dfe"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"21919c394368332f185b0ee60c5393b8344bd2e4"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}