{"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)\nimport matplotlib.pyplot as plt\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.\nfrom keras.preprocessing.image import ImageDataGenerator\n\nfrom tensorflow.python.keras.models import Sequential\nfrom tensorflow.python.keras.layers import Conv2D, MaxPooling2D,Dense, Flatten, GlobalAveragePooling2D, Activation, Flatten, Dropout, BatchNormalization\nfrom tensorflow.python.keras.applications.resnet50 import preprocess_input\n\nfrom keras.applications.resnet50 import ResNet50\nfrom keras.applications import xception\nfrom keras.applications import inception_v3\nfrom os.path import join, exists, expanduser\nfrom os import listdir, makedirs\nimport os\nfrom tqdm import tqdm\nfrom sklearn import preprocessing\nfrom sklearn.model_selection import train_test_split\nimport cv2\nimport keras as k","execution_count":38,"outputs":[{"output_type":"stream","text":"['train', 'labels.csv', 'sample_submission.csv', 'test']\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"#training_set = train_datagen.flow_from_directory('../input/train', target_size = (224, 224, 1),batch_size = 32)\n#test_set = test_datagen.flow_from_directory('../input/test', target_size = (224, 224, 1),batch_size = 32)\n\ndata_dir = '../input'\nlabels = pd.read_csv(join(data_dir, 'labels.csv'))\nTest_submission=pd.read_csv(join(data_dir, 'sample_submission.csv'))\n#train_dir=train_datagen.flow_from_directory('../input/train', target_size = (224, 224, 1),batch_size = 32)\n#test=test_datagen.flow_from_directory('../input/test', target_size = (224, 224, 1),batch_size = 32)","execution_count":39,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Test_submission.head(5)\n\n","execution_count":40,"outputs":[{"output_type":"execute_result","execution_count":40,"data":{"text/plain":"                                 id        ...          yorkshire_terrier\n0  000621fb3cbb32d8935728e48679680e        ...                   0.008333\n1  00102ee9d8eb90812350685311fe5890        ...                   0.008333\n2  0012a730dfa437f5f3613fb75efcd4ce        ...                   0.008333\n3  001510bc8570bbeee98c8d80c8a95ec1        ...                   0.008333\n4  001a5f3114548acdefa3d4da05474c2e        ...                   0.008333\n\n[5 rows x 121 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n      <th>affenpinscher</th>\n      <th>afghan_hound</th>\n      <th>african_hunting_dog</th>\n      <th>airedale</th>\n      <th>american_staffordshire_terrier</th>\n      <th>appenzeller</th>\n      <th>australian_terrier</th>\n      <th>basenji</th>\n      <th>basset</th>\n      <th>beagle</th>\n      <th>bedlington_terrier</th>\n      <th>bernese_mountain_dog</th>\n      <th>black-and-tan_coonhound</th>\n      <th>blenheim_spaniel</th>\n      <th>bloodhound</th>\n      <th>bluetick</th>\n      <th>border_collie</th>\n      <th>border_terrier</th>\n      <th>borzoi</th>\n      <th>boston_bull</th>\n      <th>bouvier_des_flandres</th>\n      <th>boxer</th>\n      <th>brabancon_griffon</th>\n      <th>briard</th>\n      <th>brittany_spaniel</th>\n      <th>bull_mastiff</th>\n      <th>cairn</th>\n      <th>cardigan</th>\n      <th>chesapeake_bay_retriever</th>\n      <th>chihuahua</th>\n      <th>chow</th>\n      <th>clumber</th>\n      <th>cocker_spaniel</th>\n      <th>collie</th>\n      <th>curly-coated_retriever</th>\n      <th>dandie_dinmont</th>\n      <th>dhole</th>\n      <th>dingo</th>\n      <th>doberman</th>\n      <th>...</th>\n      <th>norwegian_elkhound</th>\n      <th>norwich_terrier</th>\n      <th>old_english_sheepdog</th>\n      <th>otterhound</th>\n      <th>papillon</th>\n      <th>pekinese</th>\n      <th>pembroke</th>\n      <th>pomeranian</th>\n      <th>pug</th>\n      <th>redbone</th>\n      <th>rhodesian_ridgeback</th>\n      <th>rottweiler</th>\n      <th>saint_bernard</th>\n      <th>saluki</th>\n      <th>samoyed</th>\n      <th>schipperke</th>\n      <th>scotch_terrier</th>\n      <th>scottish_deerhound</th>\n      <th>sealyham_terrier</th>\n      <th>shetland_sheepdog</th>\n      <th>shih-tzu</th>\n      <th>siberian_husky</th>\n      <th>silky_terrier</th>\n      <th>soft-coated_wheaten_terrier</th>\n      <th>staffordshire_bullterrier</th>\n      <th>standard_poodle</th>\n      <th>standard_schnauzer</th>\n      <th>sussex_spaniel</th>\n      <th>tibetan_mastiff</th>\n      <th>tibetan_terrier</th>\n      <th>toy_poodle</th>\n      <th>toy_terrier</th>\n      <th>vizsla</th>\n      <th>walker_hound</th>\n      <th>weimaraner</th>\n      <th>welsh_springer_spaniel</th>\n      <th>west_highland_white_terrier</th>\n      <th>whippet</th>\n      <th>wire-haired_fox_terrier</th>\n      <th>yorkshire_terrier</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>000621fb3cbb32d8935728e48679680e</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>...</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>00102ee9d8eb90812350685311fe5890</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>...</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0012a730dfa437f5f3613fb75efcd4ce</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>...</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>001510bc8570bbeee98c8d80c8a95ec1</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>...</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>001a5f3114548acdefa3d4da05474c2e</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>...</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n      <td>0.008333</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"Test_submission.shape","execution_count":41,"outputs":[{"output_type":"execute_result","execution_count":41,"data":{"text/plain":"(10357, 121)"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels.head(5)","execution_count":42,"outputs":[{"output_type":"execute_result","execution_count":42,"data":{"text/plain":"                                 id             breed\n0  000bec180eb18c7604dcecc8fe0dba07       boston_bull\n1  001513dfcb2ffafc82cccf4d8bbaba97             dingo\n2  001cdf01b096e06d78e9e5112d419397          pekinese\n3  00214f311d5d2247d5dfe4fe24b2303d          bluetick\n4  0021f9ceb3235effd7fcde7f7538ed62  golden_retriever","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n      <th>breed</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>000bec180eb18c7604dcecc8fe0dba07</td>\n      <td>boston_bull</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>001513dfcb2ffafc82cccf4d8bbaba97</td>\n      <td>dingo</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>001cdf01b096e06d78e9e5112d419397</td>\n      <td>pekinese</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>00214f311d5d2247d5dfe4fe24b2303d</td>\n      <td>bluetick</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0021f9ceb3235effd7fcde7f7538ed62</td>\n      <td>golden_retriever</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels.breed.head(5)","execution_count":43,"outputs":[{"output_type":"execute_result","execution_count":43,"data":{"text/plain":"0         boston_bull\n1               dingo\n2            pekinese\n3            bluetick\n4    golden_retriever\nName: breed, dtype: object"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels.pivot_table(index='breed',aggfunc=len).sort_values('id',ascending=False)\n\n","execution_count":44,"outputs":[{"output_type":"execute_result","execution_count":44,"data":{"text/plain":"                                 id\nbreed                              \nscottish_deerhound              126\nmaltese_dog                     117\nafghan_hound                    116\nentlebucher                     115\nbernese_mountain_dog            114\nshih-tzu                        112\ngreat_pyrenees                  111\npomeranian                      111\nbasenji                         110\nsamoyed                         109\nairedale                        107\ntibetan_terrier                 107\nleonberg                        106\ncairn                           106\nbeagle                          105\njapanese_spaniel                105\naustralian_terrier              102\nblenheim_spaniel                102\nminiature_pinscher              102\nirish_wolfhound                 101\nlakeland_terrier                 99\nsaluki                           99\npapillon                         96\nwhippet                          95\nsiberian_husky                   95\nnorwegian_elkhound               95\npug                              94\nchow                             93\nitalian_greyhound                92\npembroke                         92\n...                             ...\ngerman_short-haired_pointer      75\nboxer                            75\nbull_mastiff                     75\nborzoi                           75\npekinese                         75\ncocker_spaniel                   74\namerican_staffordshire_terrier   74\ndoberman                         74\nbrittany_spaniel                 73\nmalinois                         73\nstandard_schnauzer               72\nflat-coated_retriever            72\nredbone                          72\nborder_collie                    72\ncurly-coated_retriever           72\nkuvasz                           71\nchihuahua                        71\nsoft-coated_wheaten_terrier      71\nfrench_bulldog                   70\nvizsla                           70\ntibetan_mastiff                  69\ngerman_shepherd                  69\ngiant_schnauzer                  69\nwalker_hound                     69\notterhound                       69\ngolden_retriever                 67\nbrabancon_griffon                67\nkomondor                         67\nbriard                           66\neskimo_dog                       66\n\n[120 rows x 1 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>id</th>\n    </tr>\n    <tr>\n      <th>breed</th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>scottish_deerhound</th>\n      <td>126</td>\n    </tr>\n    <tr>\n      <th>maltese_dog</th>\n      <td>117</td>\n    </tr>\n    <tr>\n      <th>afghan_hound</th>\n      <td>116</td>\n    </tr>\n    <tr>\n      <th>entlebucher</th>\n      <td>115</td>\n    </tr>\n    <tr>\n      <th>bernese_mountain_dog</th>\n      <td>114</td>\n    </tr>\n    <tr>\n      <th>shih-tzu</th>\n      <td>112</td>\n    </tr>\n    <tr>\n      <th>great_pyrenees</th>\n      <td>111</td>\n    </tr>\n    <tr>\n      <th>pomeranian</th>\n      <td>111</td>\n    </tr>\n    <tr>\n      <th>basenji</th>\n      <td>110</td>\n    </tr>\n    <tr>\n      <th>samoyed</th>\n      <td>109</td>\n    </tr>\n    <tr>\n      <th>airedale</th>\n      <td>107</td>\n    </tr>\n    <tr>\n      <th>tibetan_terrier</th>\n      <td>107</td>\n    </tr>\n    <tr>\n      <th>leonberg</th>\n      <td>106</td>\n    </tr>\n    <tr>\n      <th>cairn</th>\n      <td>106</td>\n    </tr>\n    <tr>\n      <th>beagle</th>\n      <td>105</td>\n    </tr>\n    <tr>\n      <th>japanese_spaniel</th>\n      <td>105</td>\n    </tr>\n    <tr>\n      <th>australian_terrier</th>\n      <td>102</td>\n    </tr>\n    <tr>\n      <th>blenheim_spaniel</th>\n      <td>102</td>\n    </tr>\n    <tr>\n      <th>miniature_pinscher</th>\n      <td>102</td>\n    </tr>\n    <tr>\n      <th>irish_wolfhound</th>\n      <td>101</td>\n    </tr>\n    <tr>\n      <th>lakeland_terrier</th>\n      <td>99</td>\n    </tr>\n    <tr>\n      <th>saluki</th>\n      <td>99</td>\n    </tr>\n    <tr>\n      <th>papillon</th>\n      <td>96</td>\n    </tr>\n    <tr>\n      <th>whippet</th>\n      <td>95</td>\n    </tr>\n    <tr>\n      <th>siberian_husky</th>\n      <td>95</td>\n    </tr>\n    <tr>\n      <th>norwegian_elkhound</th>\n      <td>95</td>\n    </tr>\n    <tr>\n      <th>pug</th>\n      <td>94</td>\n    </tr>\n    <tr>\n      <th>chow</th>\n      <td>93</td>\n    </tr>\n    <tr>\n      <th>italian_greyhound</th>\n      <td>92</td>\n    </tr>\n    <tr>\n      <th>pembroke</th>\n      <td>92</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>german_short-haired_pointer</th>\n      <td>75</td>\n    </tr>\n    <tr>\n      <th>boxer</th>\n      <td>75</td>\n    </tr>\n    <tr>\n      <th>bull_mastiff</th>\n      <td>75</td>\n    </tr>\n    <tr>\n      <th>borzoi</th>\n      <td>75</td>\n    </tr>\n    <tr>\n      <th>pekinese</th>\n      <td>75</td>\n    </tr>\n    <tr>\n      <th>cocker_spaniel</th>\n      <td>74</td>\n    </tr>\n    <tr>\n      <th>american_staffordshire_terrier</th>\n      <td>74</td>\n    </tr>\n    <tr>\n      <th>doberman</th>\n      <td>74</td>\n    </tr>\n    <tr>\n      <th>brittany_spaniel</th>\n      <td>73</td>\n    </tr>\n    <tr>\n      <th>malinois</th>\n      <td>73</td>\n    </tr>\n    <tr>\n      <th>standard_schnauzer</th>\n      <td>72</td>\n    </tr>\n    <tr>\n      <th>flat-coated_retriever</th>\n      <td>72</td>\n    </tr>\n    <tr>\n      <th>redbone</th>\n      <td>72</td>\n    </tr>\n    <tr>\n      <th>border_collie</th>\n      <td>72</td>\n    </tr>\n    <tr>\n      <th>curly-coated_retriever</th>\n      <td>72</td>\n    </tr>\n    <tr>\n      <th>kuvasz</th>\n      <td>71</td>\n    </tr>\n    <tr>\n      <th>chihuahua</th>\n      <td>71</td>\n    </tr>\n    <tr>\n      <th>soft-coated_wheaten_terrier</th>\n      <td>71</td>\n    </tr>\n    <tr>\n      <th>french_bulldog</th>\n      <td>70</td>\n    </tr>\n    <tr>\n      <th>vizsla</th>\n      <td>70</td>\n    </tr>\n    <tr>\n      <th>tibetan_mastiff</th>\n      <td>69</td>\n    </tr>\n    <tr>\n      <th>german_shepherd</th>\n      <td>69</td>\n    </tr>\n    <tr>\n      <th>giant_schnauzer</th>\n      <td>69</td>\n    </tr>\n    <tr>\n      <th>walker_hound</th>\n      <td>69</td>\n    </tr>\n    <tr>\n      <th>otterhound</th>\n      <td>69</td>\n    </tr>\n    <tr>\n      <th>golden_retriever</th>\n      <td>67</td>\n    </tr>\n    <tr>\n      <th>brabancon_griffon</th>\n      <td>67</td>\n    </tr>\n    <tr>\n      <th>komondor</th>\n      <td>67</td>\n    </tr>\n    <tr>\n      <th>briard</th>\n      <td>66</td>\n    </tr>\n    <tr>\n      <th>eskimo_dog</th>\n      <td>66</td>\n    </tr>\n  </tbody>\n</table>\n<p>120 rows × 1 columns</p>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"im_size = 224\n\nx_train = []\ny_train = []\n\ni = 0 \nfor f, breed in tqdm(labels.values):\n    img = cv2.imread('../input/train/{}.jpg'.format(f))\n    label = labels.breed[i]\n    x_train.append(cv2.resize(img, (im_size, im_size)))\n    y_train.append(label)\n    i += 1\n","execution_count":45,"outputs":[{"output_type":"stream","text":"100%|██████████| 10222/10222 [00:42<00:00, 240.11it/s]\n","name":"stderr"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"x_test = []\n\nfor f in tqdm(Test_submission['id'].values):\n    img = cv2.imread('../input/test/{}.jpg'.format(f))\n    x_test.append(cv2.resize(img, (im_size, im_size)))","execution_count":46,"outputs":[{"output_type":"stream","text":"100%|██████████| 10357/10357 [00:42<00:00, 246.57it/s]\n","name":"stderr"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#y_train=np.array(y_train)\nx_train_new=np.array(x_train)\n\nx_test_new=np.array(x_test)","execution_count":47,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"x_train_new.shape,x_test_new.shape","execution_count":48,"outputs":[{"output_type":"execute_result","execution_count":48,"data":{"text/plain":"((10222, 224, 224, 3), (10357, 224, 224, 3))"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"num_class=120\nle=preprocessing.LabelEncoder()\nY=le.fit_transform(y_train)\nY=k.utils.to_categorical(Y, num_class)","execution_count":49,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Y.shape","execution_count":50,"outputs":[{"output_type":"execute_result","execution_count":50,"data":{"text/plain":"(10222, 120)"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"\n#X_train, X_test, Y_test, Y_valid = train_test_split(x_train, Y, test_size=0.3, random_state=1)\n","execution_count":51,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#resnet_weights_path = '../input/resnet50/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5'","execution_count":52,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pretrained_model = ResNet50(weights='imagenet')","execution_count":53,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Output_layer_type= {}'.format(pretrained_model.layers[-1]))\nprint('Output_layer_shape= {}'.format(pretrained_model.layers[-1].output_shape))\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras.utils.vis_utils import plot_model\nfrom IPython.display import Image\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plot_model(pretrained_model, show_shapes=True, to_file='pretrained_model.png')\nImage(retina=True, filename='pretrained_model.png')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pretrained_model.layers.pop()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Output_layer_type= {}'.format(pretrained_model.layers[-1]))\nprint('Output_layer_shape= {}'.format(pretrained_model.layers[-1].output_shape))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for layer in pretrained_model.layers:\n    layer.trainable = False","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model = k.models.Sequential()\nmodel.add(pretrained_model)\n\nmodel.add(k.layers.Dense(num_class, activation='softmax'))\nmodel.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\nmodel.compile(loss='categorical_crossentropy',optimizer='adam', metrics=['accuracy'])\ncallbacks_list = [k.callbacks.EarlyStopping(monitor='val_acc', patience=3, verbose=1)]\nmodel.summary()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Input Shape = {}'.format(model.layers[0].input_shape))\nprint('Shape Shape = {}'.format(model.layers[-1].output_shape))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model_log=model.fit(\n    x=x_train_new, y=Y, batch_size=32,\n    epochs=20, verbose=1,validation_split=.2\n     \n)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# plotting the metrics\nfig = plt.figure()\nplt.subplot(2,1,1)\nplt.plot(model_log.history['acc'])\n#plt.plot(model_log.history['val_acc'])\nplt.title('model accuracy')\nplt.ylabel('accuracy')\nplt.xlabel('epoch')\nplt.legend(['train', 'test'], loc='lower right')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#model.save(\"model.h5\")\n\n#model.save_weights('model_weight.h5')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"prediction=model.predict(x_test_new, verbose=1)\n#prediction","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub = pd.DataFrame(prediction)\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.shape\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.shape,x_test_new.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Test_submission1=Test_submission","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Set column names to those generated by the one-hot encoding earlier\n\n# Insert the column id from the sample_submission at the start of the data frame\nsub.insert(0, 'id', Test_submission1['id'])\nsub.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"col_names = Test_submission1.columns.values\nsub.columns = col_names","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.to_csv('submission1.csv', index = False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\n","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}