{"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\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        #print(os.path.join(dirname, filename))\n        pass\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":"2022-08-12T16:38:56.255836Z","iopub.execute_input":"2022-08-12T16:38:56.256265Z","iopub.status.idle":"2022-08-12T16:39:04.511927Z","shell.execute_reply.started":"2022-08-12T16:38:56.256181Z","shell.execute_reply":"2022-08-12T16:39:04.510628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pwd","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:04.514132Z","iopub.execute_input":"2022-08-12T16:39:04.514832Z","iopub.status.idle":"2022-08-12T16:39:04.524041Z","shell.execute_reply.started":"2022-08-12T16:39:04.514790Z","shell.execute_reply":"2022-08-12T16:39:04.522986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#cd /kaggle/input/dog-breed-identification","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:04.525963Z","iopub.execute_input":"2022-08-12T16:39:04.526672Z","iopub.status.idle":"2022-08-12T16:39:04.532888Z","shell.execute_reply.started":"2022-08-12T16:39:04.526636Z","shell.execute_reply":"2022-08-12T16:39:04.531986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:04.535919Z","iopub.execute_input":"2022-08-12T16:39:04.536774Z","iopub.status.idle":"2022-08-12T16:39:05.692917Z","shell.execute_reply.started":"2022-08-12T16:39:04.536676Z","shell.execute_reply":"2022-08-12T16:39:05.691864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport cv2\nfrom tqdm import tqdm","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:05.694485Z","iopub.execute_input":"2022-08-12T16:39:05.694806Z","iopub.status.idle":"2022-08-12T16:39:05.830219Z","shell.execute_reply.started":"2022-08-12T16:39:05.694770Z","shell.execute_reply":"2022-08-12T16:39:05.829337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\ndataset=pd.read_csv(\"/kaggle/input/dog-breed-identification/labels.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:05.831520Z","iopub.execute_input":"2022-08-12T16:39:05.831883Z","iopub.status.idle":"2022-08-12T16:39:05.859300Z","shell.execute_reply.started":"2022-08-12T16:39:05.831847Z","shell.execute_reply":"2022-08-12T16:39:05.858464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:05.860650Z","iopub.execute_input":"2022-08-12T16:39:05.861686Z","iopub.status.idle":"2022-08-12T16:39:05.876205Z","shell.execute_reply.started":"2022-08-12T16:39:05.861650Z","shell.execute_reply":"2022-08-12T16:39:05.875236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:05.877417Z","iopub.execute_input":"2022-08-12T16:39:05.878120Z","iopub.status.idle":"2022-08-12T16:39:05.884446Z","shell.execute_reply.started":"2022-08-12T16:39:05.878071Z","shell.execute_reply":"2022-08-12T16:39:05.883416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"im=plt.imread(\"/kaggle/input/dog-breed-identification/train/001513dfcb2ffafc82cccf4d8bbaba97.jpg\")","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:05.886013Z","iopub.execute_input":"2022-08-12T16:39:05.887357Z","iopub.status.idle":"2022-08-12T16:39:05.906217Z","shell.execute_reply.started":"2022-08-12T16:39:05.887323Z","shell.execute_reply":"2022-08-12T16:39:05.905392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(im)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:05.910236Z","iopub.execute_input":"2022-08-12T16:39:05.911047Z","iopub.status.idle":"2022-08-12T16:39:06.214746Z","shell.execute_reply.started":"2022-08-12T16:39:05.911014Z","shell.execute_reply":"2022-08-12T16:39:06.213756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del im","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.215862Z","iopub.execute_input":"2022-08-12T16:39:06.216228Z","iopub.status.idle":"2022-08-12T16:39:06.222122Z","shell.execute_reply.started":"2022-08-12T16:39:06.216194Z","shell.execute_reply":"2022-08-12T16:39:06.221139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset['path']=\"/kaggle/input/dog-breed-identification/train/\"+dataset[\"id\"]+'.jpg'","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.224046Z","iopub.execute_input":"2022-08-12T16:39:06.224785Z","iopub.status.idle":"2022-08-12T16:39:06.242148Z","shell.execute_reply.started":"2022-08-12T16:39:06.224728Z","shell.execute_reply":"2022-08-12T16:39:06.241266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.243613Z","iopub.execute_input":"2022-08-12T16:39:06.244276Z","iopub.status.idle":"2022-08-12T16:39:06.256745Z","shell.execute_reply.started":"2022-08-12T16:39:06.244239Z","shell.execute_reply":"2022-08-12T16:39:06.255881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#i=0\n#for batch in tqdm(generator):\n #   print(len(batch))\n  #  i+=1\n   # if i>=10222:\n    #    break","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.258229Z","iopub.execute_input":"2022-08-12T16:39:06.258944Z","iopub.status.idle":"2022-08-12T16:39:06.264206Z","shell.execute_reply.started":"2022-08-12T16:39:06.258902Z","shell.execute_reply":"2022-08-12T16:39:06.263054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''X_train= np.empty((10222, 331, 331, 3), dtype=np.uint8)\nj=0\nfor i in dataset['path']:\n    X_train[j] = cv2.resize(cv2.imread(i),(331,331))\n    j+=1\n    '''","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.265986Z","iopub.execute_input":"2022-08-12T16:39:06.266778Z","iopub.status.idle":"2022-08-12T16:39:06.274222Z","shell.execute_reply.started":"2022-08-12T16:39:06.266733Z","shell.execute_reply":"2022-08-12T16:39:06.273024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#X_train.dtype","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.276024Z","iopub.execute_input":"2022-08-12T16:39:06.276825Z","iopub.status.idle":"2022-08-12T16:39:06.281202Z","shell.execute_reply.started":"2022-08-12T16:39:06.276789Z","shell.execute_reply":"2022-08-12T16:39:06.280150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#len(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.283144Z","iopub.execute_input":"2022-08-12T16:39:06.283897Z","iopub.status.idle":"2022-08-12T16:39:06.288874Z","shell.execute_reply.started":"2022-08-12T16:39:06.283862Z","shell.execute_reply":"2022-08-12T16:39:06.287527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dog_breeds=sorted(list(set(dataset['breed'])))\nn_classes=len(dog_breeds)\nclasses_to_num=dict(zip(dog_breeds,range(n_classes)))","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.292071Z","iopub.execute_input":"2022-08-12T16:39:06.293078Z","iopub.status.idle":"2022-08-12T16:39:06.305196Z","shell.execute_reply.started":"2022-08-12T16:39:06.293042Z","shell.execute_reply":"2022-08-12T16:39:06.304137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes_to_num","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.307995Z","iopub.execute_input":"2022-08-12T16:39:06.309265Z","iopub.status.idle":"2022-08-12T16:39:06.327407Z","shell.execute_reply.started":"2022-08-12T16:39:06.309228Z","shell.execute_reply":"2022-08-12T16:39:06.326390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset[\"type\"]=dataset['breed'].map(classes_to_num)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.330389Z","iopub.execute_input":"2022-08-12T16:39:06.331892Z","iopub.status.idle":"2022-08-12T16:39:06.348817Z","shell.execute_reply.started":"2022-08-12T16:39:06.331856Z","shell.execute_reply":"2022-08-12T16:39:06.347929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.350253Z","iopub.execute_input":"2022-08-12T16:39:06.350876Z","iopub.status.idle":"2022-08-12T16:39:06.371353Z","shell.execute_reply.started":"2022-08-12T16:39:06.350840Z","shell.execute_reply":"2022-08-12T16:39:06.370486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset['path'][0]","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.372788Z","iopub.execute_input":"2022-08-12T16:39:06.373413Z","iopub.status.idle":"2022-08-12T16:39:06.382683Z","shell.execute_reply.started":"2022-08-12T16:39:06.373378Z","shell.execute_reply":"2022-08-12T16:39:06.381558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=np.array(dataset[\"type\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.385253Z","iopub.execute_input":"2022-08-12T16:39:06.392693Z","iopub.status.idle":"2022-08-12T16:39:06.397562Z","shell.execute_reply.started":"2022-08-12T16:39:06.392656Z","shell.execute_reply":"2022-08-12T16:39:06.396508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(y.shape)\n#print(X_train.shape)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.398805Z","iopub.execute_input":"2022-08-12T16:39:06.399935Z","iopub.status.idle":"2022-08-12T16:39:06.406632Z","shell.execute_reply.started":"2022-08-12T16:39:06.399898Z","shell.execute_reply":"2022-08-12T16:39:06.405472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Now I will use different models and also build my own CNN model to test and get the best","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense,Layer,Lambda, Flatten,Conv2D,GlobalAveragePooling2D\nfrom tensorflow.keras.layers import Input , Concatenate, Dropout, MaxPooling2D,BatchNormalization\nfrom tensorflow.keras.models import Model\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.applications.xception import Xception\nfrom tensorflow.keras.applications.xception import preprocess_input as xcep_preprocess\nfrom tensorflow.keras.applications.resnet50 import ResNet50\nfrom tensorflow.keras.applications.resnet50 import preprocess_input as resnet_preprocess\nfrom tensorflow.keras.applications.nasnet import NASNetLarge,preprocess_input as nasnet_preprocess\nfrom tensorflow.keras.applications.inception_v3  import InceptionV3\nfrom tensorflow.keras.applications.inception_v3  import preprocess_input as inception_preprocess\nfrom tensorflow.keras.applications.inception_resnet_v2 import InceptionResNetV2,preprocess_input as incep_res_preprocess","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:06.408443Z","iopub.execute_input":"2022-08-12T16:39:06.409374Z","iopub.status.idle":"2022-08-12T16:39:11.845321Z","shell.execute_reply.started":"2022-08-12T16:39:06.409336Z","shell.execute_reply":"2022-08-12T16:39:11.844165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.preprocessing.image import ImageDataGenerator\ndatagen = ImageDataGenerator()\ngenerator = datagen.flow_from_dataframe(dataset,x_col = 'path',class_mode = None, \n                                            shuffle = False,target_size = (331,331),color_mode = 'rgb')\n","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:11.850534Z","iopub.execute_input":"2022-08-12T16:39:11.853832Z","iopub.status.idle":"2022-08-12T16:39:14.994189Z","shell.execute_reply.started":"2022-08-12T16:39:11.853788Z","shell.execute_reply":"2022-08-12T16:39:14.993041Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_features(MODEL,generator,preprocess_input):\n\n    \n    model = MODEL(include_top=False, weights='imagenet',pooling='avg')\n    inputs = Input((331,331, 3))\n    x = Lambda(preprocess_input, name='preprocessing')(inputs)\n    x = (model)(x)\n    model = Model(inputs, x)\n    \n    features = model.predict(generator)\n    return features","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:14.998654Z","iopub.execute_input":"2022-08-12T16:39:14.998993Z","iopub.status.idle":"2022-08-12T16:39:15.008783Z","shell.execute_reply.started":"2022-08-12T16:39:14.998965Z","shell.execute_reply":"2022-08-12T16:39:15.007456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#resnet_features = get_features(ResNet50, X_train,resnet_preprocess)\nxception_features = get_features(Xception, generator,xcep_preprocess)\nnasnet_features = get_features(NASNetLarge, generator,nasnet_preprocess)\ninception_features = get_features(InceptionV3,generator ,inception_preprocess)\nincep_res_features = get_features(InceptionResNetV2,generator ,incep_res_preprocess)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:39:15.016908Z","iopub.execute_input":"2022-08-12T16:39:15.017696Z","iopub.status.idle":"2022-08-12T16:47:40.274569Z","shell.execute_reply.started":"2022-08-12T16:39:15.017660Z","shell.execute_reply":"2022-08-12T16:47:40.273512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features=np.concatenate([xception_features,nasnet_features,inception_features,incep_res_features],axis=-1)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:47:40.276126Z","iopub.execute_input":"2022-08-12T16:47:40.276478Z","iopub.status.idle":"2022-08-12T16:47:40.425258Z","shell.execute_reply.started":"2022-08-12T16:47:40.276442Z","shell.execute_reply":"2022-08-12T16:47:40.424260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features.shape[1]","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:47:40.426557Z","iopub.execute_input":"2022-08-12T16:47:40.426932Z","iopub.status.idle":"2022-08-12T16:47:40.434183Z","shell.execute_reply.started":"2022-08-12T16:47:40.426898Z","shell.execute_reply":"2022-08-12T16:47:40.432936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inputs = Input(features.shape[1:])\nx = inputs\nx = Dropout(0.7)(x)\nx = Dense(120, activation='softmax')(x)\nmodel = Model(inputs, x)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:47:40.435484Z","iopub.execute_input":"2022-08-12T16:47:40.436495Z","iopub.status.idle":"2022-08-12T16:47:40.459608Z","shell.execute_reply.started":"2022-08-12T16:47:40.436459Z","shell.execute_reply":"2022-08-12T16:47:40.458571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(\n    optimizer=tf.keras.optimizers.Adam(),\n    loss=tf.keras.losses.SparseCategoricalCrossentropy(),\n    metrics=[\"accuracy\"],\n)    \nhistory=model.fit(features,y,epochs=100,batch_size=1024,validation_split=0.3,verbose=2)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:47:40.460919Z","iopub.execute_input":"2022-08-12T16:47:40.461725Z","iopub.status.idle":"2022-08-12T16:48:22.255290Z","shell.execute_reply.started":"2022-08-12T16:47:40.461691Z","shell.execute_reply":"2022-08-12T16:48:22.254283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%matplotlib inline\n%config InlineBackend.figure_format = 'retina'\n\nplt.figure(figsize=(10, 4))\nplt.subplot(1, 2, 1)\nplt.plot(history.history['loss'])\nplt.plot(history.history['val_loss'])\nplt.legend(['loss', 'val_loss'])\nplt.ylabel('loss')\nplt.xlabel('epoch')\n\nplt.subplot(1, 2, 2)\nplt.plot(history.history['accuracy'])\nplt.plot(history.history['val_accuracy'])\nplt.legend(['accuracy', 'val_accuracy'])\nplt.ylabel('accuracy')\nplt.xlabel('epoch')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:48:22.257457Z","iopub.execute_input":"2022-08-12T16:48:22.257853Z","iopub.status.idle":"2022-08-12T16:48:23.040940Z","shell.execute_reply.started":"2022-08-12T16:48:22.257816Z","shell.execute_reply":"2022-08-12T16:48:23.040059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Testing Data","metadata":{}},{"cell_type":"code","source":"cd /kaggle/input/dog-breed-identification","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:48:23.042375Z","iopub.execute_input":"2022-08-12T16:48:23.043162Z","iopub.status.idle":"2022-08-12T16:48:23.052344Z","shell.execute_reply.started":"2022-08-12T16:48:23.043124Z","shell.execute_reply":"2022-08-12T16:48:23.051032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_csv('sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:48:23.054482Z","iopub.execute_input":"2022-08-12T16:48:23.054981Z","iopub.status.idle":"2022-08-12T16:48:23.458322Z","shell.execute_reply.started":"2022-08-12T16:48:23.054945Z","shell.execute_reply":"2022-08-12T16:48:23.457323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:48:23.459766Z","iopub.execute_input":"2022-08-12T16:48:23.460125Z","iopub.status.idle":"2022-08-12T16:48:23.466160Z","shell.execute_reply.started":"2022-08-12T16:48:23.460070Z","shell.execute_reply":"2022-08-12T16:48:23.465152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ans=pd.DataFrame()\ndf_ans['path']=\"/kaggle/input/dog-breed-identification/test/\"+df_test[\"id\"]+'.jpg'\ndf_ans['id']=df_test['id']","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:48:23.467656Z","iopub.execute_input":"2022-08-12T16:48:23.468397Z","iopub.status.idle":"2022-08-12T16:48:23.480929Z","shell.execute_reply.started":"2022-08-12T16:48:23.468362Z","shell.execute_reply":"2022-08-12T16:48:23.480145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datagen = ImageDataGenerator()\ngenerator = datagen.flow_from_dataframe(df_ans,x_col = 'path',class_mode = None, \n                                            shuffle = False,target_size = (331,331),color_mode = 'rgb')","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:48:23.483642Z","iopub.execute_input":"2022-08-12T16:48:23.484384Z","iopub.status.idle":"2022-08-12T16:48:26.694217Z","shell.execute_reply.started":"2022-08-12T16:48:23.484351Z","shell.execute_reply":"2022-08-12T16:48:26.693129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#resnet_features = get_features(ResNet50, X_test,resnet_preprocess)\nxception_features = get_features(Xception, generator,xcep_preprocess)\nnasnet_features = get_features(NASNetLarge, generator,nasnet_preprocess)\ninception_features = get_features(InceptionV3,generator ,inception_preprocess)\nincep_res_features = get_features(InceptionResNetV2,generator ,incep_res_preprocess)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:48:26.695945Z","iopub.execute_input":"2022-08-12T16:48:26.696891Z","iopub.status.idle":"2022-08-12T16:55:44.497606Z","shell.execute_reply.started":"2022-08-12T16:48:26.696848Z","shell.execute_reply":"2022-08-12T16:55:44.496576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features=np.concatenate([xception_features,nasnet_features,inception_features,incep_res_features],axis=-1)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:55:44.499335Z","iopub.execute_input":"2022-08-12T16:55:44.499683Z","iopub.status.idle":"2022-08-12T16:55:44.651141Z","shell.execute_reply.started":"2022-08-12T16:55:44.499648Z","shell.execute_reply":"2022-08-12T16:55:44.650153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"features.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:55:44.652551Z","iopub.execute_input":"2022-08-12T16:55:44.652916Z","iopub.status.idle":"2022-08-12T16:55:44.661029Z","shell.execute_reply.started":"2022-08-12T16:55:44.652881Z","shell.execute_reply":"2022-08-12T16:55:44.659850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predict=model.predict(features)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:16.958940Z","iopub.execute_input":"2022-08-12T16:56:16.960298Z","iopub.status.idle":"2022-08-12T16:56:18.394085Z","shell.execute_reply.started":"2022-08-12T16:56:16.960226Z","shell.execute_reply":"2022-08-12T16:56:18.393033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predict.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:18.921280Z","iopub.execute_input":"2022-08-12T16:56:18.922061Z","iopub.status.idle":"2022-08-12T16:56:18.936236Z","shell.execute_reply.started":"2022-08-12T16:56:18.922024Z","shell.execute_reply":"2022-08-12T16:56:18.935153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_ans=[]\nfor i in range (y_predict.shape[0]):\n    y_ans.append(np.argmax(y_predict[i]))","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:22.339784Z","iopub.execute_input":"2022-08-12T16:56:22.340166Z","iopub.status.idle":"2022-08-12T16:56:22.375293Z","shell.execute_reply.started":"2022-08-12T16:56:22.340130Z","shell.execute_reply":"2022-08-12T16:56:22.374422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_ans=np.array(y_ans)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:23.003416Z","iopub.execute_input":"2022-08-12T16:56:23.004084Z","iopub.status.idle":"2022-08-12T16:56:23.011680Z","shell.execute_reply.started":"2022-08-12T16:56:23.004045Z","shell.execute_reply":"2022-08-12T16:56:23.010176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_ans.shape","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:23.470345Z","iopub.execute_input":"2022-08-12T16:56:23.470676Z","iopub.status.idle":"2022-08-12T16:56:23.477662Z","shell.execute_reply.started":"2022-08-12T16:56:23.470648Z","shell.execute_reply":"2022-08-12T16:56:23.476457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_ans[:5]","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:24.105489Z","iopub.execute_input":"2022-08-12T16:56:24.106398Z","iopub.status.idle":"2022-08-12T16:56:24.113413Z","shell.execute_reply.started":"2022-08-12T16:56:24.106354Z","shell.execute_reply":"2022-08-12T16:56:24.112246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"values_list=list(classes_to_num.values())\nkeys_list = list(classes_to_num.keys())\ny_names=[]\nfor i in y_ans:\n    position = values_list.index(i)\n    y_names.append(keys_list[position])","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:24.833297Z","iopub.execute_input":"2022-08-12T16:56:24.833748Z","iopub.status.idle":"2022-08-12T16:56:25.006030Z","shell.execute_reply.started":"2022-08-12T16:56:24.833702Z","shell.execute_reply":"2022-08-12T16:56:25.005163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_names[:5]","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:25.565913Z","iopub.execute_input":"2022-08-12T16:56:25.566826Z","iopub.status.idle":"2022-08-12T16:56:25.574604Z","shell.execute_reply.started":"2022-08-12T16:56:25.566777Z","shell.execute_reply":"2022-08-12T16:56:25.573650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#df_ans[\"Dog_breed\"]=y_names","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:26.522692Z","iopub.execute_input":"2022-08-12T16:56:26.523612Z","iopub.status.idle":"2022-08-12T16:56:26.528569Z","shell.execute_reply.started":"2022-08-12T16:56:26.523566Z","shell.execute_reply":"2022-08-12T16:56:26.527402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ans['id']=df_test['id']","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:27.175954Z","iopub.execute_input":"2022-08-12T16:56:27.176601Z","iopub.status.idle":"2022-08-12T16:56:27.183854Z","shell.execute_reply.started":"2022-08-12T16:56:27.176564Z","shell.execute_reply":"2022-08-12T16:56:27.182755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ans.drop(['path'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:56:28.059714Z","iopub.execute_input":"2022-08-12T16:56:28.060067Z","iopub.status.idle":"2022-08-12T16:56:28.067181Z","shell.execute_reply.started":"2022-08-12T16:56:28.060037Z","shell.execute_reply":"2022-08-12T16:56:28.066050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predict=pd.DataFrame(y_predict,columns=classes_to_num.keys())\ny_predict","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:58:26.827701Z","iopub.execute_input":"2022-08-12T16:58:26.828073Z","iopub.status.idle":"2022-08-12T16:58:26.867213Z","shell.execute_reply.started":"2022-08-12T16:58:26.828043Z","shell.execute_reply":"2022-08-12T16:58:26.866179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ans=pd.merge(df_ans,y_predict,left_index=True,right_index=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:58:31.664568Z","iopub.execute_input":"2022-08-12T16:58:31.665184Z","iopub.status.idle":"2022-08-12T16:58:31.686224Z","shell.execute_reply.started":"2022-08-12T16:58:31.665140Z","shell.execute_reply":"2022-08-12T16:58:31.685210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ans.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:58:33.807717Z","iopub.execute_input":"2022-08-12T16:58:33.808524Z","iopub.status.idle":"2022-08-12T16:58:33.839278Z","shell.execute_reply.started":"2022-08-12T16:58:33.808477Z","shell.execute_reply":"2022-08-12T16:58:33.838324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cd /kaggle/working","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:58:38.968980Z","iopub.execute_input":"2022-08-12T16:58:38.969674Z","iopub.status.idle":"2022-08-12T16:58:38.976683Z","shell.execute_reply.started":"2022-08-12T16:58:38.969637Z","shell.execute_reply":"2022-08-12T16:58:38.975300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ans.to_csv('submission.csv',index=None)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T16:58:39.807861Z","iopub.execute_input":"2022-08-12T16:58:39.808992Z","iopub.status.idle":"2022-08-12T16:58:40.956525Z","shell.execute_reply.started":"2022-08-12T16:58:39.808952Z","shell.execute_reply":"2022-08-12T16:58:40.955511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}