{"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":1,"outputs":[{"output_type":"stream","text":"['wildcam-reduced', 'wildcamfiles', 'iwildcam-2019-fgvc6']\n","name":"stdout"}]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"import cv2\n%matplotlib inline\nimport matplotlib.pyplot as plt\nimport keras\nimport keras.backend as K\nfrom keras.layers import Input,Dense,Conv2D,MaxPooling2D,Dropout,Flatten,BatchNormalization,Activation\nfrom keras.layers.merge import add\nfrom keras.models import Model,Sequential\nfrom sklearn.model_selection import train_test_split","execution_count":3,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"CHANNEL_AXIS = 3\nstride = 1","execution_count":4,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#This is a basic Residual Layer\n\n\ndef res_layer(x,temp,filters,pooling = False,dropout = 0.0):\n    temp = Conv2D(filters,(3,3),strides = stride,padding = \"same\")(temp)\n    temp = BatchNormalization(axis = CHANNEL_AXIS)(temp)\n    temp = Activation(\"relu\")(temp)\n    temp = Conv2D(filters,(3,3),strides = stride,padding = \"same\")(temp)\n\n    x = add([temp,Conv2D(filters,(3,3),strides = stride,padding = \"same\")(x)])\n    if pooling:\n        x = MaxPooling2D((2,2))(x)\n    if dropout != 0.0:\n        x = Dropout(dropout)(x)\n    temp = BatchNormalization(axis = CHANNEL_AXIS)(x)\n    temp = Activation(\"relu\")(temp)\n    return x,temp","execution_count":38,"outputs":[]},{"metadata":{"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"inp = Input(shape = (32,32,3))\nx = inp\nx = Conv2D(16,(3,3),strides = stride,padding = \"same\")(x)\nx = BatchNormalization(axis = CHANNEL_AXIS)(x)\nx = Activation(\"relu\")(x)\ntemp = x\n#from here on stack the residual layers remember to use padding only while increasing no. of filters.\nx,temp = res_layer(x,temp,32,dropout = 0.2)\nx,temp = res_layer(x,temp,32,dropout = 0.3)\nx,temp = res_layer(x,temp,32,dropout = 0.4,pooling = True)\nx,temp = res_layer(x,temp,64,dropout = 0.2)\nx,temp = res_layer(x,temp,64,dropout = 0.2,pooling = True)\nx,temp = res_layer(x,temp,256,dropout = 0.4)\nx = temp\nx = Flatten()(x)\nx = Dropout(0.4)(x)\nx = Dense(256,activation = \"relu\")(x)\nx = Dropout(0.23)(x)\nx = Dense(128,activation = \"relu\")(x)\nx = Dropout(0.3)(x)\nx = Dense(64,activation = \"relu\")(x)\nx = Dropout(0.2)(x)\nx = Dense(32,activation = \"relu\")(x)\nx = Dropout(0.2)(x)\nx = Dense(14,activation = \"softmax\")(x)\n\nresnet_model = Model(inp,x,name = \"Resnet\")\nresnet_model.summary()\n","execution_count":39,"outputs":[{"output_type":"stream","text":"__________________________________________________________________________________________________\nLayer (type)                    Output Shape         Param #     Connected to                     \n==================================================================================================\ninput_3 (InputLayer)            (None, 32, 32, 3)    0                                            \n__________________________________________________________________________________________________\nconv2d_21 (Conv2D)              (None, 32, 32, 16)   448         input_3[0][0]                    \n__________________________________________________________________________________________________\nbatch_normalization_15 (BatchNo (None, 32, 32, 16)   64          conv2d_21[0][0]                  \n__________________________________________________________________________________________________\nactivation_15 (Activation)      (None, 32, 32, 16)   0           batch_normalization_15[0][0]     \n__________________________________________________________________________________________________\nconv2d_22 (Conv2D)              (None, 32, 32, 32)   4640        activation_15[0][0]              \n__________________________________________________________________________________________________\nbatch_normalization_16 (BatchNo (None, 32, 32, 32)   128         conv2d_22[0][0]                  \n__________________________________________________________________________________________________\nactivation_16 (Activation)      (None, 32, 32, 32)   0           batch_normalization_16[0][0]     \n__________________________________________________________________________________________________\nconv2d_23 (Conv2D)              (None, 32, 32, 32)   9248        activation_16[0][0]              \n__________________________________________________________________________________________________\nconv2d_24 (Conv2D)              (None, 32, 32, 32)   4640        activation_15[0][0]              \n__________________________________________________________________________________________________\nadd_7 (Add)                     (None, 32, 32, 32)   0           conv2d_23[0][0]                  \n                                                                 conv2d_24[0][0]                  \n__________________________________________________________________________________________________\ndropout_12 (Dropout)            (None, 32, 32, 32)   0           add_7[0][0]                      \n__________________________________________________________________________________________________\nbatch_normalization_17 (BatchNo (None, 32, 32, 32)   128         dropout_12[0][0]                 \n__________________________________________________________________________________________________\nactivation_17 (Activation)      (None, 32, 32, 32)   0           batch_normalization_17[0][0]     \n__________________________________________________________________________________________________\nconv2d_25 (Conv2D)              (None, 32, 32, 32)   9248        activation_17[0][0]              \n__________________________________________________________________________________________________\nbatch_normalization_18 (BatchNo (None, 32, 32, 32)   128         conv2d_25[0][0]                  \n__________________________________________________________________________________________________\nactivation_18 (Activation)      (None, 32, 32, 32)   0           batch_normalization_18[0][0]     \n__________________________________________________________________________________________________\nconv2d_26 (Conv2D)              (None, 32, 32, 32)   9248        activation_18[0][0]              \n__________________________________________________________________________________________________\nconv2d_27 (Conv2D)              (None, 32, 32, 32)   9248        dropout_12[0][0]                 \n__________________________________________________________________________________________________\nadd_8 (Add)                     (None, 32, 32, 32)   0           conv2d_26[0][0]                  \n                                                                 conv2d_27[0][0]                  \n__________________________________________________________________________________________________\ndropout_13 (Dropout)            (None, 32, 32, 32)   0           add_8[0][0]                      \n__________________________________________________________________________________________________\nbatch_normalization_19 (BatchNo (None, 32, 32, 32)   128         dropout_13[0][0]                 \n__________________________________________________________________________________________________\nactivation_19 (Activation)      (None, 32, 32, 32)   0           batch_normalization_19[0][0]     \n__________________________________________________________________________________________________\nconv2d_28 (Conv2D)              (None, 32, 32, 32)   9248        activation_19[0][0]              \n__________________________________________________________________________________________________\nbatch_normalization_20 (BatchNo (None, 32, 32, 32)   128         conv2d_28[0][0]                  \n__________________________________________________________________________________________________\nactivation_20 (Activation)      (None, 32, 32, 32)   0           batch_normalization_20[0][0]     \n__________________________________________________________________________________________________\nconv2d_29 (Conv2D)              (None, 32, 32, 32)   9248        activation_20[0][0]              \n__________________________________________________________________________________________________\nconv2d_30 (Conv2D)              (None, 32, 32, 32)   9248        dropout_13[0][0]                 \n__________________________________________________________________________________________________\nadd_9 (Add)                     (None, 32, 32, 32)   0           conv2d_29[0][0]                  \n                                                                 conv2d_30[0][0]                  \n__________________________________________________________________________________________________\nmax_pooling2d_3 (MaxPooling2D)  (None, 16, 16, 32)   0           add_9[0][0]                      \n__________________________________________________________________________________________________\ndropout_14 (Dropout)            (None, 16, 16, 32)   0           max_pooling2d_3[0][0]            \n__________________________________________________________________________________________________\nbatch_normalization_21 (BatchNo (None, 16, 16, 32)   128         dropout_14[0][0]                 \n__________________________________________________________________________________________________\nactivation_21 (Activation)      (None, 16, 16, 32)   0           batch_normalization_21[0][0]     \n__________________________________________________________________________________________________\nconv2d_31 (Conv2D)              (None, 16, 16, 64)   18496       activation_21[0][0]              \n__________________________________________________________________________________________________\nbatch_normalization_22 (BatchNo (None, 16, 16, 64)   256         conv2d_31[0][0]                  \n__________________________________________________________________________________________________\nactivation_22 (Activation)      (None, 16, 16, 64)   0           batch_normalization_22[0][0]     \n__________________________________________________________________________________________________\nconv2d_32 (Conv2D)              (None, 16, 16, 64)   36928       activation_22[0][0]              \n__________________________________________________________________________________________________\nconv2d_33 (Conv2D)              (None, 16, 16, 64)   18496       dropout_14[0][0]                 \n__________________________________________________________________________________________________\nadd_10 (Add)                    (None, 16, 16, 64)   0           conv2d_32[0][0]                  \n                                                                 conv2d_33[0][0]                  \n__________________________________________________________________________________________________\ndropout_15 (Dropout)            (None, 16, 16, 64)   0           add_10[0][0]                     \n__________________________________________________________________________________________________\nbatch_normalization_23 (BatchNo (None, 16, 16, 64)   256         dropout_15[0][0]                 \n__________________________________________________________________________________________________\nactivation_23 (Activation)      (None, 16, 16, 64)   0           batch_normalization_23[0][0]     \n__________________________________________________________________________________________________\nconv2d_34 (Conv2D)              (None, 16, 16, 64)   36928       activation_23[0][0]              \n__________________________________________________________________________________________________\nbatch_normalization_24 (BatchNo (None, 16, 16, 64)   256         conv2d_34[0][0]                  \n__________________________________________________________________________________________________\nactivation_24 (Activation)      (None, 16, 16, 64)   0           batch_normalization_24[0][0]     \n__________________________________________________________________________________________________\nconv2d_35 (Conv2D)              (None, 16, 16, 64)   36928       activation_24[0][0]              \n__________________________________________________________________________________________________\nconv2d_36 (Conv2D)              (None, 16, 16, 64)   36928       dropout_15[0][0]                 \n__________________________________________________________________________________________________\nadd_11 (Add)                    (None, 16, 16, 64)   0           conv2d_35[0][0]                  \n                                                                 conv2d_36[0][0]                  \n__________________________________________________________________________________________________\nmax_pooling2d_4 (MaxPooling2D)  (None, 8, 8, 64)     0           add_11[0][0]                     \n__________________________________________________________________________________________________\ndropout_16 (Dropout)            (None, 8, 8, 64)     0           max_pooling2d_4[0][0]            \n__________________________________________________________________________________________________\nbatch_normalization_25 (BatchNo (None, 8, 8, 64)     256         dropout_16[0][0]                 \n__________________________________________________________________________________________________\nactivation_25 (Activation)      (None, 8, 8, 64)     0           batch_normalization_25[0][0]     \n__________________________________________________________________________________________________\nconv2d_37 (Conv2D)              (None, 8, 8, 256)    147712      activation_25[0][0]              \n__________________________________________________________________________________________________\nbatch_normalization_26 (BatchNo (None, 8, 8, 256)    1024        conv2d_37[0][0]                  \n__________________________________________________________________________________________________\nactivation_26 (Activation)      (None, 8, 8, 256)    0           batch_normalization_26[0][0]     \n__________________________________________________________________________________________________\nconv2d_38 (Conv2D)              (None, 8, 8, 256)    590080      activation_26[0][0]              \n__________________________________________________________________________________________________\nconv2d_39 (Conv2D)              (None, 8, 8, 256)    147712      dropout_16[0][0]                 \n__________________________________________________________________________________________________\nadd_12 (Add)                    (None, 8, 8, 256)    0           conv2d_38[0][0]                  \n                                                                 conv2d_39[0][0]                  \n__________________________________________________________________________________________________\ndropout_17 (Dropout)            (None, 8, 8, 256)    0           add_12[0][0]                     \n__________________________________________________________________________________________________\nbatch_normalization_27 (BatchNo (None, 8, 8, 256)    1024        dropout_17[0][0]                 \n__________________________________________________________________________________________________\nactivation_27 (Activation)      (None, 8, 8, 256)    0           batch_normalization_27[0][0]     \n__________________________________________________________________________________________________\nflatten_2 (Flatten)             (None, 16384)        0           activation_27[0][0]              \n__________________________________________________________________________________________________\ndropout_18 (Dropout)            (None, 16384)        0           flatten_2[0][0]                  \n__________________________________________________________________________________________________\ndense_6 (Dense)                 (None, 256)          4194560     dropout_18[0][0]                 \n__________________________________________________________________________________________________\ndropout_19 (Dropout)            (None, 256)          0           dense_6[0][0]                    \n__________________________________________________________________________________________________\ndense_7 (Dense)                 (None, 128)          32896       dropout_19[0][0]                 \n__________________________________________________________________________________________________\ndropout_20 (Dropout)            (None, 128)          0           dense_7[0][0]                    \n__________________________________________________________________________________________________\ndense_8 (Dense)                 (None, 64)           8256        dropout_20[0][0]                 \n__________________________________________________________________________________________________\ndropout_21 (Dropout)            (None, 64)           0           dense_8[0][0]                    \n__________________________________________________________________________________________________\ndense_9 (Dense)                 (None, 32)           2080        dropout_21[0][0]                 \n__________________________________________________________________________________________________\ndropout_22 (Dropout)            (None, 32)           0           dense_9[0][0]                    \n__________________________________________________________________________________________________\ndense_10 (Dense)                (None, 14)           462         dropout_22[0][0]                 \n==================================================================================================\nTotal params: 5,386,830\nTrainable params: 5,384,878\nNon-trainable params: 1,952\n__________________________________________________________________________________________________\n","name":"stdout"}]},{"metadata":{},"cell_type":"markdown","source":"[https://www.kaggle.com/xhlulu/reducing-image-sizes-to-32x32](http://) reduced dataset from this kernel"},{"metadata":{"trusted":true},"cell_type":"code","source":"\n\nX_train = np.load(\"../input/wildcam-reduced/X_train.npy\")\nY_train = np.load(\"../input/wildcam-reduced/y_train.npy\")\nX_test = np.load(\"../input/wildcam-reduced/X_test.npy\")","execution_count":9,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"X_train = X_train.astype(\"float32\")/255.0\nX_test = X_test.astype(\"float32\")/255.0","execution_count":10,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras.callbacks import ReduceLROnPlateau\n\nreduce_lr = ReduceLROnPlateau(monitor='val_acc', factor=0.2,patience=5, min_lr=1e-5)\ncallbacks = [reduce_lr]\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"resnet_model.compile(optimizer=\"adam\",loss = \"categorical_crossentropy\",metrics = [\"accuracy\"])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"resnet_model.fit(X_train,Y_train,batch_size=200,epochs = 15,validation_split=0.18,callbacks = callbacks)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"resnet_model.fit(X_train,Y_train,batch_size=350,epochs = 10,validation_split=0.5,callbacks = callbacks)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"os.listdir(\"../input\")","execution_count":14,"outputs":[{"output_type":"execute_result","execution_count":14,"data":{"text/plain":"['wildcam-reduced', 'wildcamfiles', 'iwildcam-2019-fgvc6']"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"pred = resnet_model.predict(X_test)","execution_count":16,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission_df = pd.read_csv(\"../input/iwildcam-2019-fgvc6/sample_submission.csv\")\nsubmission_df.head()","execution_count":18,"outputs":[{"output_type":"execute_result","execution_count":18,"data":{"text/plain":"                                     Id  Predicted\n0  b005e5b2-2c0b-11e9-bcad-06f10d5896c4          0\n1  f2347cfe-2c11-11e9-bcad-06f10d5896c4          0\n2  27cf8d26-2c0e-11e9-bcad-06f10d5896c4          0\n3  f82f52c7-2c1d-11e9-bcad-06f10d5896c4          0\n4  e133f50d-2c1c-11e9-bcad-06f10d5896c4          0","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>Predicted</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>b005e5b2-2c0b-11e9-bcad-06f10d5896c4</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>f2347cfe-2c11-11e9-bcad-06f10d5896c4</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>27cf8d26-2c0e-11e9-bcad-06f10d5896c4</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>f82f52c7-2c1d-11e9-bcad-06f10d5896c4</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>e133f50d-2c1c-11e9-bcad-06f10d5896c4</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_df = pd.read_csv(\"../input/iwildcam-2019-fgvc6/train.csv\")\ntrain_df.describe()","execution_count":22,"outputs":[{"output_type":"execute_result","execution_count":22,"data":{"text/plain":"         category_id      frame_num      ...           width         height\ncount  196299.000000  196299.000000      ...        196299.0  196299.000000\nmean        4.085069       1.404047      ...          1024.0     747.486600\nstd         6.749477       0.739637      ...             0.0       3.128948\nmin         0.000000       1.000000      ...          1024.0     747.000000\n25%         0.000000       1.000000      ...          1024.0     747.000000\n50%         0.000000       1.000000      ...          1024.0     747.000000\n75%         8.000000       2.000000      ...          1024.0     747.000000\nmax        22.000000       5.000000      ...          1024.0     768.000000\n\n[8 rows x 6 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>category_id</th>\n      <th>frame_num</th>\n      <th>location</th>\n      <th>seq_num_frames</th>\n      <th>width</th>\n      <th>height</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>count</th>\n      <td>196299.000000</td>\n      <td>196299.000000</td>\n      <td>196299.00000</td>\n      <td>196299.000000</td>\n      <td>196299.0</td>\n      <td>196299.000000</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>4.085069</td>\n      <td>1.404047</td>\n      <td>65.83003</td>\n      <td>1.793494</td>\n      <td>1024.0</td>\n      <td>747.486600</td>\n    </tr>\n    <tr>\n      <th>std</th>\n      <td>6.749477</td>\n      <td>0.739637</td>\n      <td>34.35272</td>\n      <td>1.026838</td>\n      <td>0.0</td>\n      <td>3.128948</td>\n    </tr>\n    <tr>\n      <th>min</th>\n      <td>0.000000</td>\n      <td>1.000000</td>\n      <td>0.00000</td>\n      <td>1.000000</td>\n      <td>1024.0</td>\n      <td>747.000000</td>\n    </tr>\n    <tr>\n      <th>25%</th>\n      <td>0.000000</td>\n      <td>1.000000</td>\n      <td>30.00000</td>\n      <td>1.000000</td>\n      <td>1024.0</td>\n      <td>747.000000</td>\n    </tr>\n    <tr>\n      <th>50%</th>\n      <td>0.000000</td>\n      <td>1.000000</td>\n      <td>70.00000</td>\n      <td>1.000000</td>\n      <td>1024.0</td>\n      <td>747.000000</td>\n    </tr>\n    <tr>\n      <th>75%</th>\n      <td>8.000000</td>\n      <td>2.000000</td>\n      <td>96.00000</td>\n      <td>3.000000</td>\n      <td>1024.0</td>\n      <td>747.000000</td>\n    </tr>\n    <tr>\n      <th>max</th>\n      <td>22.000000</td>\n      <td>5.000000</td>\n      <td>138.00000</td>\n      <td>5.000000</td>\n      <td>1024.0</td>\n      <td>768.000000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"d = {i:0 for i in range(23)}","execution_count":23,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for c in train_df[\"category_id\"]:\n    d[c]+=1\nd","execution_count":25,"outputs":[{"output_type":"execute_result","execution_count":25,"data":{"text/plain":"{0: 131457,\n 1: 6102,\n 2: 0,\n 3: 3398,\n 4: 2210,\n 5: 0,\n 6: 0,\n 7: 0,\n 8: 6938,\n 9: 0,\n 10: 1093,\n 11: 7209,\n 12: 0,\n 13: 8623,\n 14: 1361,\n 15: 0,\n 16: 5975,\n 17: 4759,\n 18: 3035,\n 19: 14106,\n 20: 0,\n 21: 0,\n 22: 33}"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"matched_dict = {i:0 for i in range(14)}\nk = 0\nfor i in range(23):\n    if d[i] > 0:\n        matched_dict[k] = i\n        k+=1\nmatched_dict","execution_count":27,"outputs":[{"output_type":"execute_result","execution_count":27,"data":{"text/plain":"{0: 0,\n 1: 1,\n 2: 3,\n 3: 4,\n 4: 8,\n 5: 10,\n 6: 11,\n 7: 13,\n 8: 14,\n 9: 16,\n 10: 17,\n 11: 18,\n 12: 19,\n 13: 22}"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"submittable = pred.argmax(axis = 1)\nprint(submittable.shape)","execution_count":29,"outputs":[{"output_type":"stream","text":"(153730,)\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"for i in range(submittable.shape[0]):\n    submittable[i] = matched_dict[submittable[i]]","execution_count":30,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission_df[\"Predicted\"] = submittable\nsubmission_df.head()","execution_count":31,"outputs":[{"output_type":"execute_result","execution_count":31,"data":{"text/plain":"                                     Id  Predicted\n0  b005e5b2-2c0b-11e9-bcad-06f10d5896c4          0\n1  f2347cfe-2c11-11e9-bcad-06f10d5896c4          0\n2  27cf8d26-2c0e-11e9-bcad-06f10d5896c4          0\n3  f82f52c7-2c1d-11e9-bcad-06f10d5896c4          0\n4  e133f50d-2c1c-11e9-bcad-06f10d5896c4          0","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>Predicted</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>b005e5b2-2c0b-11e9-bcad-06f10d5896c4</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>f2347cfe-2c11-11e9-bcad-06f10d5896c4</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>27cf8d26-2c0e-11e9-bcad-06f10d5896c4</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>f82f52c7-2c1d-11e9-bcad-06f10d5896c4</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>e133f50d-2c1c-11e9-bcad-06f10d5896c4</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission_df.describe()","execution_count":32,"outputs":[{"output_type":"execute_result","execution_count":32,"data":{"text/plain":"           Predicted\ncount  153730.000000\nmean        3.064138\nstd         5.566472\nmin         0.000000\n25%         0.000000\n50%         0.000000\n75%         1.000000\nmax        19.000000","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>Predicted</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>count</th>\n      <td>153730.000000</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>3.064138</td>\n    </tr>\n    <tr>\n      <th>std</th>\n      <td>5.566472</td>\n    </tr>\n    <tr>\n      <th>min</th>\n      <td>0.000000</td>\n    </tr>\n    <tr>\n      <th>25%</th>\n      <td>0.000000</td>\n    </tr>\n    <tr>\n      <th>50%</th>\n      <td>0.000000</td>\n    </tr>\n    <tr>\n      <th>75%</th>\n      <td>1.000000</td>\n    </tr>\n    <tr>\n      <th>max</th>\n      <td>19.000000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"est = {i:0 for i in range(23)}\nfor i in submittable:\n    est[i]+=1\nest","execution_count":35,"outputs":[{"output_type":"execute_result","execution_count":35,"data":{"text/plain":"{0: 100137,\n 1: 16246,\n 2: 0,\n 3: 1582,\n 4: 735,\n 5: 0,\n 6: 0,\n 7: 0,\n 8: 4753,\n 9: 0,\n 10: 4830,\n 11: 10184,\n 12: 0,\n 13: 4792,\n 14: 0,\n 15: 0,\n 16: 2606,\n 17: 555,\n 18: 3547,\n 19: 3763,\n 20: 0,\n 21: 0,\n 22: 0}"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"resnet_model.save(\"resnet.h5\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"resnet_model.save_weights(\"resnet_weights.h5\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"from keras.preprocessing.image import ImageDataGenerator\ndatagen = ImageDataGenerator(\n    featurewise_center=True,\n    featurewise_std_normalization=True,\n    rotation_range=20,\n    width_shift_range=0.2,\n    height_shift_range=0.2,\n    horizontal_flip=True)\ndatagen.fit(X_train)\nX_batch = datagen.flow(X_train, Y_train, batch_size=1000)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"history = resnet_model.history\nhistory.history.keys()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.plot(history.epoch,history.history[\"val_acc\"])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission_df.to_csv('submission_resnet2.csv',index=False)\n","execution_count":36,"outputs":[]},{"metadata":{"trusted":true},"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.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}