{"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\n# import 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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-29T15:54:06.580003Z","iopub.execute_input":"2023-01-29T15:54:06.580358Z","iopub.status.idle":"2023-01-29T15:54:06.585690Z","shell.execute_reply.started":"2023-01-29T15:54:06.580326Z","shell.execute_reply":"2023-01-29T15:54:06.584679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf,tensorflow.keras as keras,matplotlib.pyplot as plt\nimport seaborn as sns\nimg =331\nfrom tensorflow.keras.utils import image_dataset_from_directory","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:06.936137Z","iopub.execute_input":"2023-01-29T15:54:06.937260Z","iopub.status.idle":"2023-01-29T15:54:06.943321Z","shell.execute_reply.started":"2023-01-29T15:54:06.937220Z","shell.execute_reply":"2023-01-29T15:54:06.941779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model_1 =keras.applications.Xception(weights='imagenet',\n                                          include_top=False,\n                                          input_shape=(img,img,3))","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:07.657921Z","iopub.execute_input":"2023-01-29T15:54:07.658641Z","iopub.status.idle":"2023-01-29T15:54:08.823133Z","shell.execute_reply.started":"2023-01-29T15:54:07.658601Z","shell.execute_reply":"2023-01-29T15:54:08.822009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model_2 = keras.applications.inception_v3.InceptionV3(weights='imagenet', include_top=False, input_shape=(img, img,3))","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:09.426190Z","iopub.execute_input":"2023-01-29T15:54:09.426972Z","iopub.status.idle":"2023-01-29T15:54:11.326828Z","shell.execute_reply.started":"2023-01-29T15:54:09.426931Z","shell.execute_reply":"2023-01-29T15:54:11.325733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model_5 = keras.applications.nasnet.NASNetLarge(weights='imagenet', include_top=False, input_shape=(img,img,3))","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:11.328577Z","iopub.execute_input":"2023-01-29T15:54:11.329336Z","iopub.status.idle":"2023-01-29T15:54:19.195644Z","shell.execute_reply.started":"2023-01-29T15:54:11.329304Z","shell.execute_reply":"2023-01-29T15:54:19.194613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datgen=keras.preprocessing.image.ImageDataGenerator(rescale=1/255.0,validation_split=0.1)","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:19.197605Z","iopub.execute_input":"2023-01-29T15:54:19.198025Z","iopub.status.idle":"2023-01-29T15:54:19.203586Z","shell.execute_reply.started":"2023-01-29T15:54:19.197986Z","shell.execute_reply":"2023-01-29T15:54:19.202676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model_2.trainable = False\nbase_model_5.trainable = False","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:19.341484Z","iopub.execute_input":"2023-01-29T15:54:19.342168Z","iopub.status.idle":"2023-01-29T15:54:19.385344Z","shell.execute_reply.started":"2023-01-29T15:54:19.342122Z","shell.execute_reply":"2023-01-29T15:54:19.384400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv(\"/kaggle/input/dog-breed-identification/labels.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:19.660070Z","iopub.execute_input":"2023-01-29T15:54:19.660435Z","iopub.status.idle":"2023-01-29T15:54:19.676861Z","shell.execute_reply.started":"2023-01-29T15:54:19.660402Z","shell.execute_reply":"2023-01-29T15:54:19.675820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['id']+='.jpg'\ndf","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:20.052612Z","iopub.execute_input":"2023-01-29T15:54:20.053298Z","iopub.status.idle":"2023-01-29T15:54:20.066768Z","shell.execute_reply.started":"2023-01-29T15:54:20.053261Z","shell.execute_reply":"2023-01-29T15:54:20.065846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil \nfrom shutil import copy","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:21.643164Z","iopub.execute_input":"2023-01-29T15:54:21.643848Z","iopub.status.idle":"2023-01-29T15:54:21.648319Z","shell.execute_reply.started":"2023-01-29T15:54:21.643810Z","shell.execute_reply":"2023-01-29T15:54:21.647312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['id']=='000bec180eb18c7604dcecc8fe0dba07.jpg']['breed'][0]","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:22.089673Z","iopub.execute_input":"2023-01-29T15:54:22.090366Z","iopub.status.idle":"2023-01-29T15:54:22.099093Z","shell.execute_reply.started":"2023-01-29T15:54:22.090329Z","shell.execute_reply":"2023-01-29T15:54:22.097738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:22.472507Z","iopub.execute_input":"2023-01-29T15:54:22.472951Z","iopub.status.idle":"2023-01-29T15:54:22.477794Z","shell.execute_reply.started":"2023-01-29T15:54:22.472920Z","shell.execute_reply":"2023-01-29T15:54:22.476624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"df.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:24.221093Z","iopub.execute_input":"2023-01-29T15:54:24.221442Z","iopub.status.idle":"2023-01-29T15:54:24.231613Z","shell.execute_reply.started":"2023-01-29T15:54:24.221412Z","shell.execute_reply":"2023-01-29T15:54:24.230605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.mkdir('train')","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:24.462757Z","iopub.execute_input":"2023-01-29T15:54:24.463549Z","iopub.status.idle":"2023-01-29T15:54:24.740103Z","shell.execute_reply.started":"2023-01-29T15:54:24.463517Z","shell.execute_reply":"2023-01-29T15:54:24.738661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=df.breed.unique()\nfor i in x:\n    os.mkdir('train/'+i)","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:24.882087Z","iopub.execute_input":"2023-01-29T15:54:24.883123Z","iopub.status.idle":"2023-01-29T15:54:24.907463Z","shell.execute_reply.started":"2023-01-29T15:54:24.883082Z","shell.execute_reply":"2023-01-29T15:54:24.905934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df[df['id']=='000bec180eb18c7604dcecc8fe0dba07.jpg']['breed']","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:26.311729Z","iopub.execute_input":"2023-01-29T15:54:26.312999Z","iopub.status.idle":"2023-01-29T15:54:26.317733Z","shell.execute_reply.started":"2023-01-29T15:54:26.312956Z","shell.execute_reply":"2023-01-29T15:54:26.316568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# i='000bec180eb18c7604dcecc8fe0dba07.jpg'\n# copy('/kaggle/input/dog-breed-identification/train/'+i,'train/'+(df[df['id']==i]['breed'][0]))","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:26.698623Z","iopub.execute_input":"2023-01-29T15:54:26.699902Z","iopub.status.idle":"2023-01-29T15:54:27.464045Z","shell.execute_reply.started":"2023-01-29T15:54:26.699861Z","shell.execute_reply":"2023-01-29T15:54:27.462953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(os.listdir('/kaggle/working/train/boston_bull'))","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:27.466572Z","iopub.execute_input":"2023-01-29T15:54:27.466985Z","iopub.status.idle":"2023-01-29T15:54:27.477788Z","shell.execute_reply.started":"2023-01-29T15:54:27.466947Z","shell.execute_reply":"2023-01-29T15:54:27.476658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[df['breed']=='boston_bull'].count()","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:27.479421Z","iopub.execute_input":"2023-01-29T15:54:27.480477Z","iopub.status.idle":"2023-01-29T15:54:27.492436Z","shell.execute_reply.started":"2023-01-29T15:54:27.480441Z","shell.execute_reply":"2023-01-29T15:54:27.491332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# for i,j in enumerate(df['id']):\n#     print(df.iloc[i,1])\n# #     print(j)","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:28.408973Z","iopub.execute_input":"2023-01-29T15:54:28.409773Z","iopub.status.idle":"2023-01-29T15:54:28.414539Z","shell.execute_reply.started":"2023-01-29T15:54:28.409727Z","shell.execute_reply":"2023-01-29T15:54:28.413544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i,j in enumerate(df['id']):\n    copy('/kaggle/input/dog-breed-identification/train/'+j,'train/'+df.iloc[i,1])\n    ","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:54:29.758536Z","iopub.execute_input":"2023-01-29T15:54:29.759542Z","iopub.status.idle":"2023-01-29T15:55:38.359128Z","shell.execute_reply.started":"2023-01-29T15:54:29.759496Z","shell.execute_reply":"2023-01-29T15:55:38.358134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BATCH_SIZE=64\nIMG_HEIGHT,IMG_WIDTH=331,331","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:55:38.362964Z","iopub.execute_input":"2023-01-29T15:55:38.363283Z","iopub.status.idle":"2023-01-29T15:55:38.369659Z","shell.execute_reply.started":"2023-01-29T15:55:38.363255Z","shell.execute_reply":"2023-01-29T15:55:38.368740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_gen = image_dataset_from_directory(\n  directory = 'train/',\n  labels = 'inferred',\n  label_mode='int',\n  batch_size=BATCH_SIZE,\n  image_size=(IMG_HEIGHT, IMG_WIDTH),\n  shuffle = True,\n  seed=17,\n  validation_split=0.1,\n  subset=\"training\",\n)","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:55:38.371270Z","iopub.execute_input":"2023-01-29T15:55:38.371796Z","iopub.status.idle":"2023-01-29T15:55:39.093800Z","shell.execute_reply.started":"2023-01-29T15:55:38.371757Z","shell.execute_reply":"2023-01-29T15:55:39.091882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_gen=datgen.flow_from_dataframe(df,\n#                                    '/kaggle/input/dog-breed-identification/train/',\n#                                    x_col='id',\n#                                    y_col='breed',\n#                                    traget_size=(img,img),\n#                                    batch_size=32,\n#                                    subset='training')","metadata":{"execution":{"iopub.status.busy":"2023-01-28T05:57:31.383176Z","iopub.execute_input":"2023-01-28T05:57:31.384278Z","iopub.status.idle":"2023-01-28T05:57:35.882620Z","shell.execute_reply.started":"2023-01-28T05:57:31.384235Z","shell.execute_reply":"2023-01-28T05:57:35.881378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nval_gen = image_dataset_from_directory(\n  directory = 'train/',\n  labels = 'inferred',\n  label_mode='int',\n  batch_size=BATCH_SIZE,\n  image_size=(IMG_HEIGHT, IMG_WIDTH),\n  shuffle = True,\n  seed=17,\n  validation_split=0.1,\n  subset=\"validation\",\n)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:55:39.096489Z","iopub.execute_input":"2023-01-29T15:55:39.097966Z","iopub.status.idle":"2023-01-29T15:55:39.657302Z","shell.execute_reply.started":"2023-01-29T15:55:39.097926Z","shell.execute_reply":"2023-01-29T15:55:39.656367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# val_gen=datgen.flow_from_dataframe(df,\n#                                    '/kaggle/input/dog-breed-identification/train/',\n#                                    x_col='id',\n#                                    y_col='breed',\n#                                    traget_size=(img,img),\n#                                    batch_size=32,\n#                                    subset='validation')","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:55:39.661813Z","iopub.execute_input":"2023-01-29T15:55:39.664202Z","iopub.status.idle":"2023-01-29T15:55:39.670876Z","shell.execute_reply.started":"2023-01-29T15:55:39.664149Z","shell.execute_reply":"2023-01-29T15:55:39.669756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub=pd.read_csv('/kaggle/input/dog-breed-identification/sample_submission.csv')\nsub['id']+='.jpg'\nsub['id']\nsu=pd.DataFrame(sub['id'])\nsu","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:55:39.675511Z","iopub.execute_input":"2023-01-29T15:55:39.675947Z","iopub.status.idle":"2023-01-29T15:55:40.223682Z","shell.execute_reply.started":"2023-01-29T15:55:39.675912Z","shell.execute_reply":"2023-01-29T15:55:40.222625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datagen2=keras.preprocessing.image.ImageDataGenerator(rescale=1/255)","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:55:40.225220Z","iopub.execute_input":"2023-01-29T15:55:40.226073Z","iopub.status.idle":"2023-01-29T15:55:40.232027Z","shell.execute_reply.started":"2023-01-29T15:55:40.226035Z","shell.execute_reply":"2023-01-29T15:55:40.230308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"\n\ntest_gen = image_dataset_from_directory(\n  directory = '/kaggle/input/dog-breed-identification/test',\n  label_mode= None,\n  batch_size=BATCH_SIZE,\n  image_size=(IMG_HEIGHT, IMG_WIDTH),\n  shuffle = False,\n  seed=1234\n)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:55:40.233644Z","iopub.execute_input":"2023-01-29T15:55:40.234847Z","iopub.status.idle":"2023-01-29T15:55:49.047036Z","shell.execute_reply.started":"2023-01-29T15:55:40.234810Z","shell.execute_reply":"2023-01-29T15:55:49.045142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_gen=datagen2.flow_from_dataframe(su,\n#                                    '/kaggle/input/dog-breed-identification/test/',\n#                                     x_col='id',\n#                                     y_col=None,\n#                                       class_mode=None,\n#                                     traget_size=(img,img),\n#                                     batch_size=32,\n#                                     subset='training')","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:55:49.048638Z","iopub.execute_input":"2023-01-29T15:55:49.049015Z","iopub.status.idle":"2023-01-29T15:55:49.054154Z","shell.execute_reply.started":"2023-01-29T15:55:49.048978Z","shell.execute_reply":"2023-01-29T15:55:49.052954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AUTOTUNE = tf.data.AUTOTUNE\n\ntrain_gen = train_gen.prefetch(buffer_size=AUTOTUNE)\nval_gen = val_gen.prefetch(buffer_size=AUTOTUNE)\ntest_gen = test_gen.prefetch(buffer_size=AUTOTUNE)","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:55:49.058044Z","iopub.execute_input":"2023-01-29T15:55:49.058406Z","iopub.status.idle":"2023-01-29T15:55:49.066104Z","shell.execute_reply.started":"2023-01-29T15:55:49.058371Z","shell.execute_reply":"2023-01-29T15:55:49.065127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"base_model_1.trainable=False","metadata":{"execution":{"iopub.status.busy":"2023-01-29T15:55:49.067701Z","iopub.execute_input":"2023-01-29T15:55:49.068062Z","iopub.status.idle":"2023-01-29T15:55:49.078804Z","shell.execute_reply.started":"2023-01-29T15:55:49.068029Z","shell.execute_reply":"2023-01-29T15:55:49.077880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow.keras.layers as layers","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:24:07.571989Z","iopub.execute_input":"2023-01-29T14:24:07.572966Z","iopub.status.idle":"2023-01-29T14:24:07.578175Z","shell.execute_reply.started":"2023-01-29T14:24:07.572929Z","shell.execute_reply":"2023-01-29T14:24:07.577009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_augmentation = keras.Sequential(\n    [\n        layers.RandomFlip(\"horizontal\"),\n        layers.RandomRotation(0.2),\n        layers.RandomTranslation(0.14,0.14),\n        layers.RandomZoom(0.2),\n        layers.RandomContrast(0.2),\n    ]\n)","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:24:08.264810Z","iopub.execute_input":"2023-01-29T14:24:08.265176Z","iopub.status.idle":"2023-01-29T14:24:08.282981Z","shell.execute_reply.started":"2023-01-29T14:24:08.265145Z","shell.execute_reply":"2023-01-29T14:24:08.282143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inputs =keras.layers.Input(shape=(img,img,3))\ninput=data_augmentation(inputs)\nx1 = keras.applications.xception.preprocess_input(input)\nx1 = base_model_1(x1, training=False)\nx1 = keras.layers.GlobalAveragePooling2D()(x1)\nx2 = keras.applications.inception_v3.preprocess_input(input)\nx2 = base_model_2(x2, training=False)\nx2 = keras.layers.GlobalAveragePooling2D()(x2)\nx5 = keras.applications.nasnet.preprocess_input(input)\nx5 = base_model_5(x5, training=False)\nx5 = keras.layers.GlobalAveragePooling2D()(x5)\nx = keras.layers.Concatenate()([x1, x2,x5])\n# x=keras.layers.Flatten()(x1)\nx=keras.layers.Dropout(0.5)(x)\nx=keras.layers.Dense(1024,activation='relu')(x)\nx=keras.layers.BatchNormalization()(x)\nx=keras.layers.Dropout(0.5)(x)\n# x=keras.layers.Dense(512,activation='softplus')(x)\n# x=keras.layers.BatchNormalization()(x)\n# x=keras.layers.Dropout(0.5)(x)\nx=keras.layers.Dense(512,activation='relu')(x)\n# x=keras.layers.BatchNormalization()(x)\nx=keras.layers.Dropout(0.5)(x)\noutput=keras.layers.Dense(120,activation='softmax')(x)\nmodel=keras.Model(inputs,output)\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:24:10.748020Z","iopub.execute_input":"2023-01-29T14:24:10.748703Z","iopub.status.idle":"2023-01-29T14:24:14.150258Z","shell.execute_reply.started":"2023-01-29T14:24:10.748668Z","shell.execute_reply":"2023-01-29T14:24:14.149075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# del model","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:21:58.810929Z","iopub.execute_input":"2023-01-29T14:21:58.811413Z","iopub.status.idle":"2023-01-29T14:21:58.818506Z","shell.execute_reply.started":"2023-01-29T14:21:58.811373Z","shell.execute_reply":"2023-01-29T14:21:58.817168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model.compile(optimizer=keras.optimizers.Adam(learning_rate=0.001),\n#               loss=keras.metrics.SparseCategoricalCrossentropy,\n#               metrics=['acc'])","metadata":{"execution":{"iopub.status.busy":"2023-01-28T06:01:15.246023Z","iopub.execute_input":"2023-01-28T06:01:15.246445Z","iopub.status.idle":"2023-01-28T06:01:15.251193Z","shell.execute_reply.started":"2023-01-28T06:01:15.246408Z","shell.execute_reply":"2023-01-28T06:01:15.250007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"optimizer = keras.optimizers.Adam(learning_rate=0.001)\n# learning_rate = 0.1\n# decay_rate = learning_rate / 50\n# momentum = 0.5\n# sgd = keras.optimizers.SGD(lr=learning_rate, momentum=momentum, decay=decay_rate, nesterov=False)\nmodel.compile(loss=keras.metrics.sparse_categorical_crossentropy, metrics=['accuracy'], optimizer=optimizer)","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:24:55.648016Z","iopub.execute_input":"2023-01-29T14:24:55.648721Z","iopub.status.idle":"2023-01-29T14:24:55.677740Z","shell.execute_reply.started":"2023-01-29T14:24:55.648686Z","shell.execute_reply":"2023-01-29T14:24:55.676686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Earlystop=keras.callbacks.EarlyStopping(min_delta=0.001,patience=10,restore_best_weights=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:24:57.542819Z","iopub.execute_input":"2023-01-29T14:24:57.543200Z","iopub.status.idle":"2023-01-29T14:24:57.548320Z","shell.execute_reply.started":"2023-01-29T14:24:57.543169Z","shell.execute_reply":"2023-01-29T14:24:57.546968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history =model.fit(train_gen,\n                   validation_data = val_gen,\n                   epochs=10,\n                   batch_size=64,\n                  callbacks=[Earlystop]\n                  )","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:24:58.211455Z","iopub.execute_input":"2023-01-29T14:24:58.211770Z","iopub.status.idle":"2023-01-29T14:26:02.107461Z","shell.execute_reply.started":"2023-01-29T14:24:58.211741Z","shell.execute_reply":"2023-01-29T14:26:02.106080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# del model","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:26:02.108757Z","iopub.status.idle":"2023-01-29T14:26:02.109514Z","shell.execute_reply.started":"2023-01-29T14:26:02.109249Z","shell.execute_reply":"2023-01-29T14:26:02.109274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os \ndata=pd.DataFrame(columns=['id','labels'])\ndata['id']=os.listdir('/kaggle/input/dog-breed-identification/test')","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:26:06.046361Z","iopub.execute_input":"2023-01-29T14:26:06.046837Z","iopub.status.idle":"2023-01-29T14:26:06.071088Z","shell.execute_reply.started":"2023-01-29T14:26:06.046799Z","shell.execute_reply":"2023-01-29T14:26:06.070228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels = pd.read_csv('/kaggle/input/dog-breed-identification/labels.csv', index_col = 'id')\ntarget, dog_breeds = pd.factorize(train_labels['breed'], sort = True)\ntrain_labels['target'] = target","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:26:06.751506Z","iopub.execute_input":"2023-01-29T14:26:06.751850Z","iopub.status.idle":"2023-01-29T14:26:06.771840Z","shell.execute_reply.started":"2023-01-29T14:26:06.751818Z","shell.execute_reply":"2023-01-29T14:26:06.770941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(\n    test_gen,\n    batch_size = 64,\n    verbose=1         \n)","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:26:08.510561Z","iopub.execute_input":"2023-01-29T14:26:08.510914Z","iopub.status.idle":"2023-01-29T14:33:37.933471Z","shell.execute_reply.started":"2023-01-29T14:26:08.510884Z","shell.execute_reply":"2023-01-29T14:33:37.932443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions","metadata":{"execution":{"iopub.status.busy":"2023-01-29T14:33:37.935347Z","iopub.execute_input":"2023-01-29T14:33:37.935706Z","iopub.status.idle":"2023-01-29T14:33:37.947469Z","shell.execute_reply.started":"2023-01-29T14:33:37.935673Z","shell.execute_reply":"2023-01-29T14:33:37.946533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission=pd.read_csv('/kaggle/input/dog-breed-identification/sample_submission.csv')\nsubmission.loc[:, dog_breeds] = predictions\nsubmission.to_csv('submission.csv', index=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# name=submission['id'][0]\n# name='/kaggle/input/dog-breed-identification/test/'+ name\n# import cv2 \n# image =cv2.imread(name)\n# plt.imshow(image)","metadata":{"execution":{"iopub.status.busy":"2023-01-26T21:22:41.693620Z","iopub.execute_input":"2023-01-26T21:22:41.694419Z","iopub.status.idle":"2023-01-26T21:22:41.698538Z","shell.execute_reply.started":"2023-01-26T21:22:41.694383Z","shell.execute_reply":"2023-01-26T21:22:41.697717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# submission.dtypes","metadata":{"execution":{"iopub.status.busy":"2023-01-26T21:22:41.710150Z","iopub.execute_input":"2023-01-26T21:22:41.710762Z","iopub.status.idle":"2023-01-26T21:22:41.715004Z","shell.execute_reply.started":"2023-01-26T21:22:41.710728Z","shell.execute_reply":"2023-01-26T21:22:41.713606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# len(os.listdir('/kaggle/input/dog-breed-identification/test'))","metadata":{"execution":{"iopub.status.busy":"2023-01-26T21:22:41.729012Z","iopub.execute_input":"2023-01-26T21:22:41.730139Z","iopub.status.idle":"2023-01-26T21:22:41.735844Z","shell.execute_reply.started":"2023-01-26T21:22:41.730110Z","shell.execute_reply":"2023-01-26T21:22:41.734948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}