{"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_minor":4,"nbformat":4,"cells":[{"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\n# for 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","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":16.191827,"end_time":"2021-03-16T10:35:53.590772","exception":false,"start_time":"2021-03-16T10:35:37.398945","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:02.777325Z","iopub.execute_input":"2021-09-29T08:03:02.777661Z","iopub.status.idle":"2021-09-29T08:03:02.782757Z","shell.execute_reply.started":"2021-09-29T08:03:02.777584Z","shell.execute_reply":"2021-09-29T08:03:02.781788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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 matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"papermill":{"duration":5.207411,"end_time":"2021-03-16T10:35:58.886428","exception":false,"start_time":"2021-03-16T10:35:53.679017","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:02.784892Z","iopub.execute_input":"2021-09-29T08:03:02.785243Z","iopub.status.idle":"2021-09-29T08:03:07.138326Z","shell.execute_reply.started":"2021-09-29T08:03:02.785207Z","shell.execute_reply":"2021-09-29T08:03:07.137382Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntrain_dir = '../input/dog-breed-identification/train'\ntest_dir ='../input/dog-breed-identification/test'","metadata":{"papermill":{"duration":0.084354,"end_time":"2021-03-16T10:35:59.040784","exception":false,"start_time":"2021-03-16T10:35:58.95643","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:07.140263Z","iopub.execute_input":"2021-09-29T08:03:07.140811Z","iopub.status.idle":"2021-09-29T08:03:07.146447Z","shell.execute_reply.started":"2021-09-29T08:03:07.140767Z","shell.execute_reply":"2021-09-29T08:03:07.145553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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","metadata":{"papermill":{"duration":0.726751,"end_time":"2021-03-16T10:35:59.838551","exception":false,"start_time":"2021-03-16T10:35:59.1118","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:07.148704Z","iopub.execute_input":"2021-09-29T08:03:07.149406Z","iopub.status.idle":"2021-09-29T08:03:07.665254Z","shell.execute_reply.started":"2021-09-29T08:03:07.149368Z","shell.execute_reply":"2021-09-29T08:03:07.664313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dogs= traindf['breed'].unique()\nsDogs=sorted(dogs)\nsDogs","metadata":{"execution":{"iopub.status.busy":"2021-09-29T08:03:07.667208Z","iopub.execute_input":"2021-09-29T08:03:07.671904Z","iopub.status.idle":"2021-09-29T08:03:07.68703Z","shell.execute_reply.started":"2021-09-29T08:03:07.671857Z","shell.execute_reply":"2021-09-29T08:03:07.68615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Training Labels","metadata":{"papermill":{"duration":0.068505,"end_time":"2021-03-16T10:35:59.976152","exception":false,"start_time":"2021-03-16T10:35:59.907647","status":"completed"},"tags":[]}},{"cell_type":"code","source":"traindf.head()","metadata":{"papermill":{"duration":0.091166,"end_time":"2021-03-16T10:36:00.136753","exception":false,"start_time":"2021-03-16T10:36:00.045587","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:07.688332Z","iopub.execute_input":"2021-09-29T08:03:07.688688Z","iopub.status.idle":"2021-09-29T08:03:07.703476Z","shell.execute_reply.started":"2021-09-29T08:03:07.688651Z","shell.execute_reply":"2021-09-29T08:03:07.702181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test id or Sample Submission","metadata":{"papermill":{"duration":0.06905,"end_time":"2021-03-16T10:36:00.274221","exception":false,"start_time":"2021-03-16T10:36:00.205171","status":"completed"},"tags":[]}},{"cell_type":"code","source":"testdf.head()","metadata":{"papermill":{"duration":0.100591,"end_time":"2021-03-16T10:36:00.441971","exception":false,"start_time":"2021-03-16T10:36:00.34138","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:07.704729Z","iopub.execute_input":"2021-09-29T08:03:07.705198Z","iopub.status.idle":"2021-09-29T08:03:07.732418Z","shell.execute_reply.started":"2021-09-29T08:03:07.705165Z","shell.execute_reply":"2021-09-29T08:03:07.731356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Training Images","metadata":{"papermill":{"duration":0.127859,"end_time":"2021-03-16T10:36:00.685749","exception":false,"start_time":"2021-03-16T10:36:00.55789","status":"completed"},"tags":[]}},{"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'))\n    plt.axis('off')","metadata":{"papermill":{"duration":1.188808,"end_time":"2021-03-16T10:36:01.996333","exception":false,"start_time":"2021-03-16T10:36:00.807525","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:07.734037Z","iopub.execute_input":"2021-09-29T08:03:07.734678Z","iopub.status.idle":"2021-09-29T08:03:08.556399Z","shell.execute_reply.started":"2021-09-29T08:03:07.734642Z","shell.execute_reply":"2021-09-29T08:03:08.555508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data preprocessing","metadata":{"_kg_hide-output":true,"papermill":{"duration":0.075855,"end_time":"2021-03-16T10:36:02.14835","exception":false,"start_time":"2021-03-16T10:36:02.072495","status":"completed"},"tags":[]}},{"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                                  )","metadata":{"papermill":{"duration":0.085989,"end_time":"2021-03-16T10:36:02.309474","exception":false,"start_time":"2021-03-16T10:36:02.223485","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:08.557503Z","iopub.execute_input":"2021-09-29T08:03:08.557818Z","iopub.status.idle":"2021-09-29T08:03:08.564336Z","shell.execute_reply.started":"2021-09-29T08:03:08.557787Z","shell.execute_reply":"2021-09-29T08:03:08.56341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BATCH_SIZE = 32","metadata":{"papermill":{"duration":0.083649,"end_time":"2021-03-16T10:36:02.467716","exception":false,"start_time":"2021-03-16T10:36:02.384067","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:08.565871Z","iopub.execute_input":"2021-09-29T08:03:08.56648Z","iopub.status.idle":"2021-09-29T08:03:08.572814Z","shell.execute_reply.started":"2021-09-29T08:03:08.566442Z","shell.execute_reply":"2021-09-29T08:03:08.571906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_size=(331,331)","metadata":{"papermill":{"duration":0.081857,"end_time":"2021-03-16T10:36:02.624017","exception":false,"start_time":"2021-03-16T10:36:02.54216","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:08.5742Z","iopub.execute_input":"2021-09-29T08:03:08.574771Z","iopub.status.idle":"2021-09-29T08:03:08.581483Z","shell.execute_reply.started":"2021-09-29T08:03:08.574718Z","shell.execute_reply":"2021-09-29T08:03:08.580613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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)","metadata":{"papermill":{"duration":3.515719,"end_time":"2021-03-16T10:36:06.214598","exception":false,"start_time":"2021-03-16T10:36:02.698879","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:08.586364Z","iopub.execute_input":"2021-09-29T08:03:08.586865Z","iopub.status.idle":"2021-09-29T08:03:25.930107Z","shell.execute_reply.started":"2021-09-29T08:03:08.586826Z","shell.execute_reply":"2021-09-29T08:03:25.929214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plotting Augmented images","metadata":{"papermill":{"duration":0.074604,"end_time":"2021-03-16T10:36:06.365676","exception":false,"start_time":"2021-03-16T10:36:06.291072","status":"completed"},"tags":[]}},{"cell_type":"code","source":"x,y = next(train_generator)","metadata":{"papermill":{"duration":0.331865,"end_time":"2021-03-16T10:36:06.772658","exception":false,"start_time":"2021-03-16T10:36:06.440793","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:25.933263Z","iopub.execute_input":"2021-09-29T08:03:25.933546Z","iopub.status.idle":"2021-09-29T08:03:26.267311Z","shell.execute_reply.started":"2021-09-29T08:03:25.933517Z","shell.execute_reply":"2021-09-29T08:03:26.266336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(type(x))\nprint(x.shape)\nprint(y.shape)","metadata":{"papermill":{"duration":0.083869,"end_time":"2021-03-16T10:36:06.931543","exception":false,"start_time":"2021-03-16T10:36:06.847674","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:26.268556Z","iopub.execute_input":"2021-09-29T08:03:26.269042Z","iopub.status.idle":"2021-09-29T08:03:26.279087Z","shell.execute_reply.started":"2021-09-29T08:03:26.269006Z","shell.execute_reply":"2021-09-29T08:03:26.278275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_grid(image_list,nrows,ncols,figsize=(10,10),showaxis='off'):\n    \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        ","metadata":{"papermill":{"duration":0.090092,"end_time":"2021-03-16T10:36:07.096839","exception":false,"start_time":"2021-03-16T10:36:07.006747","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:26.280997Z","iopub.execute_input":"2021-09-29T08:03:26.28313Z","iopub.status.idle":"2021-09-29T08:03:26.29442Z","shell.execute_reply.started":"2021-09-29T08:03:26.283093Z","shell.execute_reply":"2021-09-29T08:03:26.293555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nshow_grid(x,8,3,figsize=(25,25))\n","metadata":{"papermill":{"duration":3.526836,"end_time":"2021-03-16T10:36:10.69815","exception":false,"start_time":"2021-03-16T10:36:07.171314","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:26.298241Z","iopub.execute_input":"2021-09-29T08:03:26.300731Z","iopub.status.idle":"2021-09-29T08:03:29.014401Z","shell.execute_reply.started":"2021-09-29T08:03:26.300694Z","shell.execute_reply":"2021-09-29T08:03:29.013545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Validation Data","metadata":{"papermill":{"duration":0.118688,"end_time":"2021-03-16T10:36:10.944053","exception":false,"start_time":"2021-03-16T10:36:10.825365","status":"completed"},"tags":[]}},{"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","metadata":{"papermill":{"duration":3.133173,"end_time":"2021-03-16T10:36:14.19651","exception":false,"start_time":"2021-03-16T10:36:11.063337","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:29.015464Z","iopub.execute_input":"2021-09-29T08:03:29.01578Z","iopub.status.idle":"2021-09-29T08:03:32.709015Z","shell.execute_reply.started":"2021-09-29T08:03:29.015734Z","shell.execute_reply":"2021-09-29T08:03:32.707994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Test Data","metadata":{"papermill":{"duration":0.118623,"end_time":"2021-03-16T10:36:14.436363","exception":false,"start_time":"2021-03-16T10:36:14.31774","status":"completed"},"tags":[]}},{"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\")","metadata":{"papermill":{"duration":3.898941,"end_time":"2021-03-16T10:36:18.453182","exception":false,"start_time":"2021-03-16T10:36:14.554241","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:32.710302Z","iopub.execute_input":"2021-09-29T08:03:32.710832Z","iopub.status.idle":"2021-09-29T08:03:59.497694Z","shell.execute_reply.started":"2021-09-29T08:03:32.710784Z","shell.execute_reply":"2021-09-29T08:03:59.496771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Pretrained model NASNetLarge","metadata":{"papermill":{"duration":0.120292,"end_time":"2021-03-16T10:36:18.693727","exception":false,"start_time":"2021-03-16T10:36:18.573435","status":"completed"},"tags":[]}},{"cell_type":"code","source":"shape=(331,331,3)","metadata":{"papermill":{"duration":0.128561,"end_time":"2021-03-16T10:36:18.942533","exception":false,"start_time":"2021-03-16T10:36:18.813972","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:59.499016Z","iopub.execute_input":"2021-09-29T08:03:59.499507Z","iopub.status.idle":"2021-09-29T08:03:59.503725Z","shell.execute_reply.started":"2021-09-29T08:03:59.499468Z","shell.execute_reply":"2021-09-29T08:03:59.502897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pretrained_model = tf.keras.applications.NASNetLarge(\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    ])","metadata":{"papermill":{"duration":6.127009,"end_time":"2021-03-16T10:36:25.188793","exception":false,"start_time":"2021-03-16T10:36:19.061784","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:03:59.504964Z","iopub.execute_input":"2021-09-29T08:03:59.505432Z","iopub.status.idle":"2021-09-29T08:04:12.397623Z","shell.execute_reply.started":"2021-09-29T08:03:59.505396Z","shell.execute_reply":"2021-09-29T08:04:12.396858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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()","metadata":{"papermill":{"duration":0.17769,"end_time":"2021-03-16T10:36:25.501594","exception":false,"start_time":"2021-03-16T10:36:25.323904","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:04:12.399587Z","iopub.execute_input":"2021-09-29T08:04:12.400098Z","iopub.status.idle":"2021-09-29T08:04:12.483829Z","shell.execute_reply.started":"2021-09-29T08:04:12.40006Z","shell.execute_reply":"2021-09-29T08:04:12.483043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Early stopping","metadata":{"papermill":{"duration":0.140371,"end_time":"2021-03-16T10:36:25.777072","exception":false,"start_time":"2021-03-16T10:36:25.636701","status":"completed"},"tags":[]}},{"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)","metadata":{"papermill":{"duration":0.149269,"end_time":"2021-03-16T10:36:26.063886","exception":false,"start_time":"2021-03-16T10:36:25.914617","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:04:12.487042Z","iopub.execute_input":"2021-09-29T08:04:12.487368Z","iopub.status.idle":"2021-09-29T08:04:12.502557Z","shell.execute_reply.started":"2021-09-29T08:04:12.48734Z","shell.execute_reply":"2021-09-29T08:04:12.5016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Fitting the Model:","metadata":{"papermill":{"duration":0.124982,"end_time":"2021-03-16T10:36:26.319586","exception":false,"start_time":"2021-03-16T10:36:26.194604","status":"completed"},"tags":[]}},{"cell_type":"code","source":"STEP_SIZE_TRAIN = train_generator.n//train_generator.batch_size\nSTEP_SIZE_VALID = valid_generator.n//valid_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=6,\n                    callbacks=[early],)","metadata":{"papermill":{"duration":1245.64345,"end_time":"2021-03-16T10:57:12.090137","exception":false,"start_time":"2021-03-16T10:36:26.446687","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-09-29T08:04:12.503935Z","iopub.execute_input":"2021-09-29T08:04:12.504301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loss and Accuracy Curves","metadata":{"papermill":{"duration":1.560335,"end_time":"2021-03-16T10:57:15.213278","exception":false,"start_time":"2021-03-16T10:57:13.652943","status":"completed"},"tags":[]}},{"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_xlabel('epoch')\n    ax.legend(['train', 'valid.'])","metadata":{"papermill":{"duration":1.574586,"end_time":"2021-03-16T10:57:18.372678","exception":false,"start_time":"2021-03-16T10:57:16.798092","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_training_curves(\n    history.history['loss'],\n    history.history['val_loss'],\n    'LOSS',\n    211,\n)\n\ndisplay_training_curves(\n    history.history['accuracy'],\n    history.history['val_accuracy'],\n    'ACCURACY',\n    212,\n)\n","metadata":{"papermill":{"duration":2.086662,"end_time":"2021-03-16T10:57:22.135604","exception":false,"start_time":"2021-03-16T10:57:20.048942","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Accuracy","metadata":{"papermill":{"duration":1.566686,"end_time":"2021-03-16T10:57:29.120074","exception":false,"start_time":"2021-03-16T10:57:27.553388","status":"completed"},"tags":[]}},{"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","metadata":{"papermill":{"duration":3.696096,"end_time":"2021-03-16T10:57:34.451049","exception":false,"start_time":"2021-03-16T10:57:30.754953","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Predicting Test Images","metadata":{"papermill":{"duration":1.62017,"end_time":"2021-03-16T10:57:53.608834","exception":false,"start_time":"2021-03-16T10:57:51.988664","status":"completed"},"tags":[]}},{"cell_type":"code","source":"%%time\npred=model.predict(test_generator)","metadata":{"papermill":{"duration":90.347441,"end_time":"2021-03-16T10:59:25.80864","exception":false,"start_time":"2021-03-16T10:57:55.461199","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import io\nimport numpy as np\nfrom PIL import Image\nimport tensorflow as tf\nfrom PIL import Image\nimport base64\nfrom io import BytesIO\nimport cv2\nfrom skimage import io","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndef urlHandPred(url, scale=1.05, minN=5):\n#     if \"https://images.unsplash.com/\" in url:\n#         url= url+ add \n    print(url)\n    img = io.imread(url)    \n    crop= img\n    crop = cv2.resize(crop,(331, 331))\n    crop = np.reshape(crop,[1,331, 331, 3])/255.0\n    pred = model.predict(crop)\n    print(np.argmax(pred[0]))\n    print('---------------------pred[0]',sDogs[np.argmax(pred[0])])\n    plt.figure(figsize=(10,10))\n    plt.imshow(img)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"urlHandPred('https://images.unsplash.com/photo-1617181668756-68f6613051d0?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwyMTYyOTB8MHwxfHNlYXJjaHwxN3x8Y2FuaW5lfGVufDB8fHx8MTYzMjgxNjE2Nw&ixlib=rb-1.2.1&q=80&w=400')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}