{"cells":[{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2021-03-15T05:43:37.148947Z","iopub.status.busy":"2021-03-15T05:43:37.148293Z","iopub.status.idle":"2021-03-15T05:44:03.819453Z","shell.execute_reply":"2021-03-15T05:44:03.823232Z"},"papermill":{"duration":26.706683,"end_time":"2021-03-15T05:44:03.82367","exception":false,"start_time":"2021-03-15T05:43:37.116987","status":"completed"},"tags":[],"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\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 read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:04.389274Z","iopub.status.busy":"2021-03-15T05:44:04.388439Z","iopub.status.idle":"2021-03-15T05:44:09.907958Z","shell.execute_reply":"2021-03-15T05:44:09.908931Z"},"papermill":{"duration":5.765021,"end_time":"2021-03-15T05:44:09.909166","exception":false,"start_time":"2021-03-15T05:44:04.144145","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"%%time\nimport tensorflow as tf\nfrom keras_preprocessing.image import ImageDataGenerator\nfrom mpl_toolkits.axes_grid1 import ImageGrid\nimport itertools \nimport re\nimport matplotlib.pyplot as plt\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:10.507521Z","iopub.status.busy":"2021-03-15T05:44:10.506798Z","iopub.status.idle":"2021-03-15T05:44:10.510569Z","shell.execute_reply":"2021-03-15T05:44:10.51115Z"},"papermill":{"duration":0.077005,"end_time":"2021-03-15T05:44:10.511328","exception":false,"start_time":"2021-03-15T05:44:10.434323","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"%%time\ntrain_dir = '../input/dog-breed-identification/train'\ntest_dir ='../input/dog-breed-identification/test'","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:10.6534Z","iopub.status.busy":"2021-03-15T05:44:10.652903Z","iopub.status.idle":"2021-03-15T05:44:11.329964Z","shell.execute_reply":"2021-03-15T05:44:11.329335Z"},"papermill":{"duration":0.750963,"end_time":"2021-03-15T05:44:11.330104","exception":false,"start_time":"2021-03-15T05:44:10.579141","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"%%time\ndef append_ext(fn):\n    return fn+\".jpg\"\ntraindf = pd.read_csv('../input/dog-breed-identification/labels.csv',dtype=str)\ntestdf = pd.read_csv('../input/dog-breed-identification/sample_submission.csv',dtype=str)\ntraindf[\"id\"] = traindf[\"id\"].apply(append_ext)\ntestdf[\"id\"] = testdf[\"id\"].apply(append_ext)\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Training Labels"},{"metadata":{"trusted":true},"cell_type":"code","source":"traindf.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Test id or Sample Submission"},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:11.642551Z","iopub.status.busy":"2021-03-15T05:44:11.641111Z","iopub.status.idle":"2021-03-15T05:44:11.645489Z","shell.execute_reply":"2021-03-15T05:44:11.645895Z"},"papermill":{"duration":0.092662,"end_time":"2021-03-15T05:44:11.646026","exception":false,"start_time":"2021-03-15T05:44:11.553364","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"testdf.head()","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.066081,"end_time":"2021-03-15T05:44:11.776839","exception":false,"start_time":"2021-03-15T05:44:11.710758","status":"completed"},"tags":[]},"cell_type":"markdown","source":"# Training Images"},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:11.913675Z","iopub.status.busy":"2021-03-15T05:44:11.913137Z","iopub.status.idle":"2021-03-15T05:44:12.853557Z","shell.execute_reply":"2021-03-15T05:44:12.853981Z"},"papermill":{"duration":1.011672,"end_time":"2021-03-15T05:44:12.854132","exception":false,"start_time":"2021-03-15T05:44:11.84246","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"\nsrc_path = \"../input/dog-breed-identification/train\"\nsub_class = os.listdir(src_path)\n\nfig = plt.figure(figsize=(10,5))\nfor e in range(len(sub_class[:8])):\n    plt.subplot(2,4,e+1)\n    img = plt.imread(os.path.join(src_path,sub_class[e]))\n    plt.imshow(img, cmap=plt.get_cmap('gray'))","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-output":true,"papermill":{"duration":0.071261,"end_time":"2021-03-15T05:44:12.998505","exception":false,"start_time":"2021-03-15T05:44:12.927244","status":"completed"},"tags":[]},"cell_type":"markdown","source":"# Data preprocessing"},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:13.149033Z","iopub.status.busy":"2021-03-15T05:44:13.148206Z","iopub.status.idle":"2021-03-15T05:44:13.153691Z","shell.execute_reply":"2021-03-15T05:44:13.152978Z"},"papermill":{"duration":0.083162,"end_time":"2021-03-15T05:44:13.153888","exception":false,"start_time":"2021-03-15T05:44:13.070726","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"%%time\ntrain_datagen=ImageDataGenerator( rescale=1./255.,\n                                  #rotation_range = 20,\n                                  #brightness_range=[0.2,1.0],\n                                  #width_shift_range = 0.2,\n                                  #height_shift_range = 0.2,\n                                  #shear_range = 0.2,\n                                  #zoom_range = [0.7,1],\n                                  horizontal_flip = True,\n                                  #Setting validation split to 2% \n                                  validation_split=0.02 \n                                  )","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:13.303373Z","iopub.status.busy":"2021-03-15T05:44:13.302726Z","iopub.status.idle":"2021-03-15T05:44:13.305737Z","shell.execute_reply":"2021-03-15T05:44:13.30523Z"},"papermill":{"duration":0.080005,"end_time":"2021-03-15T05:44:13.305855","exception":false,"start_time":"2021-03-15T05:44:13.22585","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"BATCH_SIZE = 32","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image_size=(299,299)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:13.482342Z","iopub.status.busy":"2021-03-15T05:44:13.479256Z","iopub.status.idle":"2021-03-15T05:44:19.476579Z","shell.execute_reply":"2021-03-15T05:44:19.475961Z"},"papermill":{"duration":6.099537,"end_time":"2021-03-15T05:44:19.476747","exception":false,"start_time":"2021-03-15T05:44:13.37721","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"train_generator=train_datagen.flow_from_dataframe(\ndataframe=traindf,\ndirectory=train_dir,\nx_col=\"id\",\ny_col=\"breed\",\nsubset=\"training\",\nbatch_size=BATCH_SIZE,\nseed=42,\nshuffle=True,\nclass_mode=\"categorical\",\ntarget_size=image_size,\ncolor_mode=\"rgb\" \n)","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.071845,"end_time":"2021-03-15T05:44:19.62185","exception":false,"start_time":"2021-03-15T05:44:19.550005","status":"completed"},"tags":[]},"cell_type":"markdown","source":"# Plotting Augmented images"},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:19.770383Z","iopub.status.busy":"2021-03-15T05:44:19.769801Z","iopub.status.idle":"2021-03-15T05:44:20.375052Z","shell.execute_reply":"2021-03-15T05:44:20.373983Z"},"papermill":{"duration":0.681159,"end_time":"2021-03-15T05:44:20.375195","exception":false,"start_time":"2021-03-15T05:44:19.694036","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"x,y = next(train_generator)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:20.52621Z","iopub.status.busy":"2021-03-15T05:44:20.525518Z","iopub.status.idle":"2021-03-15T05:44:20.529559Z","shell.execute_reply":"2021-03-15T05:44:20.530099Z"},"papermill":{"duration":0.082174,"end_time":"2021-03-15T05:44:20.530291","exception":false,"start_time":"2021-03-15T05:44:20.448117","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"print(type(x))\nprint(x.shape)\nprint(y.shape)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:20.684818Z","iopub.status.busy":"2021-03-15T05:44:20.684122Z","iopub.status.idle":"2021-03-15T05:44:20.687053Z","shell.execute_reply":"2021-03-15T05:44:20.686538Z"},"papermill":{"duration":0.083348,"end_time":"2021-03-15T05:44:20.687163","exception":false,"start_time":"2021-03-15T05:44:20.603815","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"def show_grid(image_list,nrows,ncols,figsize=(10,10),showaxis='off'):\n    if type(image_list) is not list:\n        if(image_list.shape[-1]==1):\n            image_list = [image_list[i,:,:,0] for i in range(image_list.shape[0])]\n        elif(image_list.shape[-1]==3):\n            image_list = [image_list[i,:,:,:] for i in range(image_list.shape[0])]\n    fig = plt.figure(None, figsize,frameon=False)\n    grid = ImageGrid(fig, 111,  # similar to subplot(111)\n                     nrows_ncols=(nrows, ncols),  # creates 2x2 grid of axes\n                     axes_pad=0.3,  # pad between axes in inch.\n                     share_all=True,\n                     )\n    for i in range(nrows*ncols):\n        ax = grid[i]\n        ax.imshow(image_list[i],cmap='Greys_r')  # The AxesGrid object work as a list of axes.\n        ax.axis('off')\n        ","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:20.851253Z","iopub.status.busy":"2021-03-15T05:44:20.838503Z","iopub.status.idle":"2021-03-15T05:44:24.175435Z","shell.execute_reply":"2021-03-15T05:44:24.175932Z"},"papermill":{"duration":3.416416,"end_time":"2021-03-15T05:44:24.176152","exception":false,"start_time":"2021-03-15T05:44:20.759736","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"%%time\nshow_grid(x,4,8,figsize=(25,25))\n","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.115424,"end_time":"2021-03-15T05:44:24.410614","exception":false,"start_time":"2021-03-15T05:44:24.29519","status":"completed"},"tags":[]},"cell_type":"markdown","source":"# Validation Data"},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:24.676148Z","iopub.status.busy":"2021-03-15T05:44:24.675603Z","iopub.status.idle":"2021-03-15T05:44:30.064951Z","shell.execute_reply":"2021-03-15T05:44:30.064533Z"},"papermill":{"duration":5.538435,"end_time":"2021-03-15T05:44:30.065071","exception":false,"start_time":"2021-03-15T05:44:24.526636","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"valid_generator=train_datagen.flow_from_dataframe(\ndataframe=traindf,\ndirectory=train_dir,\nx_col=\"id\",\ny_col=\"breed\",\nsubset=\"validation\",\nbatch_size=BATCH_SIZE,\nseed=42,\nshuffle=True,\nclass_mode=\"categorical\",\ntarget_size=image_size,\ncolor_mode=\"rgb\")\n","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.115387,"end_time":"2021-03-15T05:44:30.29507","exception":false,"start_time":"2021-03-15T05:44:30.179683","status":"completed"},"tags":[]},"cell_type":"markdown","source":"# Test Data"},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:30.533266Z","iopub.status.busy":"2021-03-15T05:44:30.532367Z","iopub.status.idle":"2021-03-15T05:44:35.165681Z","shell.execute_reply":"2021-03-15T05:44:35.166894Z"},"papermill":{"duration":4.757366,"end_time":"2021-03-15T05:44:35.167065","exception":false,"start_time":"2021-03-15T05:44:30.409699","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"test_datagen=ImageDataGenerator(rescale=1./255.)\n\ntest_generator=test_datagen.flow_from_dataframe(\ndataframe=testdf,\ndirectory=test_dir,\nx_col=\"id\",\ny_col=None,\nbatch_size=BATCH_SIZE,\nseed=42,\nshuffle=False,\nclass_mode=None,\ntarget_size=image_size,\ncolor_mode=\"rgb\")","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.114386,"end_time":"2021-03-15T05:44:35.643563","exception":false,"start_time":"2021-03-15T05:44:35.529177","status":"completed"},"tags":[]},"cell_type":"markdown","source":"# Pretrained model InceptionV3"},{"metadata":{"trusted":true},"cell_type":"code","source":"shape=[299,299,3]","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:35.883728Z","iopub.status.busy":"2021-03-15T05:44:35.883108Z","iopub.status.idle":"2021-03-15T05:44:41.349413Z","shell.execute_reply":"2021-03-15T05:44:41.348909Z"},"papermill":{"duration":5.591536,"end_time":"2021-03-15T05:44:41.349572","exception":false,"start_time":"2021-03-15T05:44:35.758036","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"pretrained_model = tf.keras.applications.InceptionV3(\n        weights='imagenet',\n        include_top=False ,\n        input_shape=shape\n    )\npretrained_model.trainable = False\n    \nmodel = tf.keras.Sequential([ \n        pretrained_model,   \n        tf.keras.layers.GlobalAveragePooling2D(),\n        #tf.keras.layers.Dense(256, activation='relu'),\n        #tf.keras.layers.Dropout(0.5),\n        tf.keras.layers.Dense(120, activation='softmax')\n    ])","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:41.604374Z","iopub.status.busy":"2021-03-15T05:44:41.603504Z","iopub.status.idle":"2021-03-15T05:44:41.622787Z","shell.execute_reply":"2021-03-15T05:44:41.622317Z"},"papermill":{"duration":0.15379,"end_time":"2021-03-15T05:44:41.622908","exception":false,"start_time":"2021-03-15T05:44:41.469118","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"#opt = tf.keras.optimizers.Adam(learning_rate=0.001)\nopt=tf.keras.optimizers.SGD(lr=1e-3, momentum=0.9)\nmodel.compile(optimizer = opt ,\n              loss=\"categorical_crossentropy\",\n              metrics=[\"accuracy\"])\nmodel.summary()","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.119696,"end_time":"2021-03-15T05:44:41.861327","exception":false,"start_time":"2021-03-15T05:44:41.741631","status":"completed"},"tags":[]},"cell_type":"markdown","source":"# Early stopping"},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:42.106123Z","iopub.status.busy":"2021-03-15T05:44:42.105397Z","iopub.status.idle":"2021-03-15T05:44:42.109252Z","shell.execute_reply":"2021-03-15T05:44:42.108824Z"},"papermill":{"duration":0.128412,"end_time":"2021-03-15T05:44:42.109363","exception":false,"start_time":"2021-03-15T05:44:41.980951","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"#reduce = tf.keras.callbacks.ReduceLROnPlateau( monitor='val_loss',factor=0.2,patience=5, min_lr=0.001 )\n\nearly = tf.keras.callbacks.EarlyStopping( patience=2,\n                                          min_delta=0.001,\n                                          restore_best_weights=True)","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":0.117889,"end_time":"2021-03-15T05:44:42.345298","exception":false,"start_time":"2021-03-15T05:44:42.227409","status":"completed"},"tags":[]},"cell_type":"markdown","source":"# Fitting the Model:"},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T05:44:42.59305Z","iopub.status.busy":"2021-03-15T05:44:42.592382Z","iopub.status.idle":"2021-03-15T06:43:05.343128Z","shell.execute_reply":"2021-03-15T06:43:05.342651Z"},"papermill":{"duration":3502.878164,"end_time":"2021-03-15T06:43:05.34326","exception":false,"start_time":"2021-03-15T05:44:42.465096","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"STEP_SIZE_TRAIN = train_generator.n//train_generator.batch_size\nSTEP_SIZE_VALID = valid_generator.n//valid_generator.batch_size\nSTEP_SIZE_TEST = test_generator.n//test_generator.batch_size\nhistory = model.fit(train_generator,\n                    steps_per_epoch=STEP_SIZE_TRAIN,\n                    validation_data=valid_generator,\n                    validation_steps=STEP_SIZE_VALID,\n                    epochs=25,\n                    callbacks=[early],)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Loss and Accuracy Curves"},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T06:43:09.8203Z","iopub.status.busy":"2021-03-15T06:43:09.819382Z","iopub.status.idle":"2021-03-15T06:43:09.822219Z","shell.execute_reply":"2021-03-15T06:43:09.821793Z"},"papermill":{"duration":2.145823,"end_time":"2021-03-15T06:43:09.822359","exception":false,"start_time":"2021-03-15T06:43:07.676536","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"def display_training_curves(training, validation, title, subplot):\n    if subplot%10==1: # set up the subplots on the first call\n        plt.subplots(figsize=(10,10), facecolor='#F0F0F0')\n        plt.tight_layout()\n    ax = plt.subplot(subplot)\n    ax.set_facecolor('#F8F8F8')\n    ax.plot(training)\n    ax.plot(validation)\n    ax.set_title('MODEL '+ title)\n    ax.set_ylabel(title)\n    #ax.set_ylim(0.28,1.05)\n    ax.set_xlabel('epoch')\n    ax.legend(['train', 'valid.'])","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T06:43:14.033708Z","iopub.status.busy":"2021-03-15T06:43:14.032867Z","iopub.status.idle":"2021-03-15T06:43:14.229313Z","shell.execute_reply":"2021-03-15T06:43:14.22975Z"},"papermill":{"duration":2.34054,"end_time":"2021-03-15T06:43:14.229903","exception":false,"start_time":"2021-03-15T06:43:11.889363","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"display_training_curves(\n    history.history['loss'],\n    history.history['val_loss'],\n    'LOSS',\n    211,\n)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"display_training_curves(\n    history.history['accuracy'],\n    history.history['val_accuracy'],\n    'ACCURACY',\n    211,\n)\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Accuracy"},{"metadata":{"trusted":true},"cell_type":"code","source":"score = model.evaluate(valid_generator,batch_size=32)\nprint(\"Accuracy: {:.2f}%\".format(score[1] * 100)) \nprint(\"Loss: \",score[0])\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from sklearn.metrics import f1_score","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Y_pred = model.predict(valid_generator)\ny_pred = np.argmax(Y_pred, axis=1)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# F1 Score"},{"metadata":{"trusted":true},"cell_type":"code","source":"f_score = f1_score(valid_generator.classes,y_pred,average='macro')\nprint('F1 score:',f_score)\n","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":2.139463,"end_time":"2021-03-15T06:44:05.6017","exception":false,"start_time":"2021-03-15T06:44:03.462237","status":"completed"},"tags":[]},"cell_type":"markdown","source":"# Predicting Test Images"},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T06:44:14.544774Z","iopub.status.busy":"2021-03-15T06:44:14.543315Z","iopub.status.idle":"2021-03-15T06:45:54.588868Z","shell.execute_reply":"2021-03-15T06:45:54.587797Z"},"papermill":{"duration":102.163857,"end_time":"2021-03-15T06:45:54.589065","exception":false,"start_time":"2021-03-15T06:44:12.425208","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"pred=model.predict(test_generator)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T06:45:58.763275Z","iopub.status.busy":"2021-03-15T06:45:58.762511Z","iopub.status.idle":"2021-03-15T06:45:59.042552Z","shell.execute_reply":"2021-03-15T06:45:59.042971Z"},"papermill":{"duration":2.38094,"end_time":"2021-03-15T06:45:59.043117","exception":false,"start_time":"2021-03-15T06:45:56.662177","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"df_submission = pd.read_csv('/kaggle/input/dog-breed-identification/sample_submission.csv')\ndf_submission.head()","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T06:46:03.494276Z","iopub.status.busy":"2021-03-15T06:46:03.473969Z","iopub.status.idle":"2021-03-15T06:46:03.504116Z","shell.execute_reply":"2021-03-15T06:46:03.503699Z"},"papermill":{"duration":2.341721,"end_time":"2021-03-15T06:46:03.50423","exception":false,"start_time":"2021-03-15T06:46:01.162509","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"file_list = test_generator.filenames\nid_list = []\nfor name in file_list:\n    m = re.sub('test/', '', name)\n    m = re.sub('.jpg', '', m)\n    id_list.append(m)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T06:46:07.627442Z","iopub.status.busy":"2021-03-15T06:46:07.62657Z","iopub.status.idle":"2021-03-15T06:46:08.05433Z","shell.execute_reply":"2021-03-15T06:46:08.054813Z"},"papermill":{"duration":2.517407,"end_time":"2021-03-15T06:46:08.054978","exception":false,"start_time":"2021-03-15T06:46:05.537571","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"df_submission['id'] = id_list\ndf_submission.iloc[:,1:] = pred\ndf_submission.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Prediction Score for selected breeds"},{"metadata":{"trusted":true},"cell_type":"code","source":"breeds=['id','beagle','chihuahua','doberman','french_bulldog', 'golden_retriever', 'malamute','pug','saint_bernard','scottish_deerhound','tibetan_mastiff']","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2021-03-15T06:46:12.184853Z","iopub.status.busy":"2021-03-15T06:46:12.184006Z","iopub.status.idle":"2021-03-15T06:46:15.734134Z","shell.execute_reply":"2021-03-15T06:46:15.733107Z"},"papermill":{"duration":5.621176,"end_time":"2021-03-15T06:46:15.734314","exception":false,"start_time":"2021-03-15T06:46:10.113138","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"selected_breeds = df_submission.loc[:,breeds]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Breeds and prediction score')\nselected_breeds.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Final Submission to Competition"},{"metadata":{"trusted":true},"cell_type":"code","source":"final_sub = df_submission.set_index('id')\nfinal_sub.to_csv('Submission.csv')","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}