{"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\n# import numpy as np # linear algebra\n# import 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-05-07T21:23:36.305266Z","iopub.execute_input":"2023-05-07T21:23:36.306084Z","iopub.status.idle":"2023-05-07T21:23:36.311122Z","shell.execute_reply.started":"2023-05-07T21:23:36.306051Z","shell.execute_reply":"2023-05-07T21:23:36.310098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -q efficientnet","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:36.315994Z","iopub.execute_input":"2023-05-07T21:23:36.316748Z","iopub.status.idle":"2023-05-07T21:23:47.091735Z","shell.execute_reply.started":"2023-05-07T21:23:36.316714Z","shell.execute_reply":"2023-05-07T21:23:47.090576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd \nimport os\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport plotly.express as px\nimport plotly.figure_factory as ff\nimport plotly.graph_objects as go\nfrom scipy import stats\nimport cv2\nimport glob\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.applications import MobileNetV2\nfrom keras.utils import to_categorical\nfrom keras.layers import Dense\nfrom keras import Model\nfrom keras.callbacks import ModelCheckpoint\nfrom keras.models import load_model\nfrom tensorflow.keras.applications.xception import Xception\nimport tensorflow as tf\nimport tensorflow.keras.layers as L\n\nimport tensorflow.keras.layers as L\nimport efficientnet.tfkeras as efn","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:47.094444Z","iopub.execute_input":"2023-05-07T21:23:47.094811Z","iopub.status.idle":"2023-05-07T21:23:55.294029Z","shell.execute_reply.started":"2023-05-07T21:23:47.094766Z","shell.execute_reply":"2023-05-07T21:23:55.292983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(os.listdir('../input/landmark-recognition-2020/'))","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:55.295444Z","iopub.execute_input":"2023-05-07T21:23:55.296284Z","iopub.status.idle":"2023-05-07T21:23:55.303325Z","shell.execute_reply.started":"2023-05-07T21:23:55.296248Z","shell.execute_reply":"2023-05-07T21:23:55.302352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('../input/landmark-recognition-2020/train.csv')\nsample_df = pd.read_csv('../input/landmark-recognition-2020/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:55.305818Z","iopub.execute_input":"2023-05-07T21:23:55.306756Z","iopub.status.idle":"2023-05-07T21:23:56.617083Z","shell.execute_reply.started":"2023-05-07T21:23:55.306658Z","shell.execute_reply":"2023-05-07T21:23:56.616132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"landmark_count=pd.value_counts(train_df[\"landmark_id\"])\nlandmark_count=landmark_count.reset_index()\nlandmark_count.rename(columns={\"index\":'landmark_id','landmark_id':'count'},inplace=True)\nlandmark_count","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:56.618622Z","iopub.execute_input":"2023-05-07T21:23:56.618996Z","iopub.status.idle":"2023-05-07T21:23:56.681391Z","shell.execute_reply.started":"2023-05-07T21:23:56.618964Z","shell.execute_reply":"2023-05-07T21:23:56.680539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:56.682891Z","iopub.execute_input":"2023-05-07T21:23:56.683216Z","iopub.status.idle":"2023-05-07T21:23:56.690894Z","shell.execute_reply.started":"2023-05-07T21:23:56.683185Z","shell.execute_reply":"2023-05-07T21:23:56.688974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:56.694865Z","iopub.execute_input":"2023-05-07T21:23:56.695480Z","iopub.status.idle":"2023-05-07T21:23:56.704901Z","shell.execute_reply.started":"2023-05-07T21:23:56.695454Z","shell.execute_reply":"2023-05-07T21:23:56.703735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.info()","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:56.706377Z","iopub.execute_input":"2023-05-07T21:23:56.706705Z","iopub.status.idle":"2023-05-07T21:23:56.919375Z","shell.execute_reply.started":"2023-05-07T21:23:56.706675Z","shell.execute_reply":"2023-05-07T21:23:56.918430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"landmarks = len(train_df['landmark_id'].unique())\nlandmarks","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:56.920542Z","iopub.execute_input":"2023-05-07T21:23:56.920867Z","iopub.status.idle":"2023-05-07T21:23:56.945985Z","shell.execute_reply.started":"2023-05-07T21:23:56.920826Z","shell.execute_reply":"2023-05-07T21:23:56.945040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"landmark_count = train_df.landmark_id.value_counts().head(10).to_frame() # to_frame converts data in to dataframe.\nlandmark_count = landmark_count.reset_index() \nlandmark_count.rename(columns={\"index\":'landmark_id','landmark_id':'count'},inplace=True)\nlandmark_count.style.background_gradient(cmap='Oranges')","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:56.950390Z","iopub.execute_input":"2023-05-07T21:23:56.952127Z","iopub.status.idle":"2023-05-07T21:23:57.057976Z","shell.execute_reply.started":"2023-05-07T21:23:56.952101Z","shell.execute_reply":"2023-05-07T21:23:57.057060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,8))\nsns.relplot(data=landmark_count, x='landmark_id', y='count',kind='line')\nplt.xticks(rotation=45)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:57.059580Z","iopub.execute_input":"2023-05-07T21:23:57.059959Z","iopub.status.idle":"2023-05-07T21:23:57.394217Z","shell.execute_reply.started":"2023-05-07T21:23:57.059928Z","shell.execute_reply":"2023-05-07T21:23:57.393223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,8))\nsns.barplot(data=landmark_count, y='landmark_id', x='count',orient='h')\nsns.set_color_codes(\"pastel\")\nplt.xticks(rotation=45)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:57.396229Z","iopub.execute_input":"2023-05-07T21:23:57.396884Z","iopub.status.idle":"2023-05-07T21:23:57.677532Z","shell.execute_reply.started":"2023-05-07T21:23:57.396849Z","shell.execute_reply":"2023-05-07T21:23:57.676661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Landmark Id Density Plot\nplt.figure(figsize = (15, 5))\nplt.title('Landmark id density plot')\nsns.kdeplot(train_df['landmark_id'], color=\"tomato\", shade=True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:23:57.679023Z","iopub.execute_input":"2023-05-07T21:23:57.679382Z","iopub.status.idle":"2023-05-07T21:24:03.758199Z","shell.execute_reply.started":"2023-05-07T21:23:57.679340Z","shell.execute_reply":"2023-05-07T21:24:03.757226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Landmark id distribuition and density plot\nplt.figure(figsize = (15, 5))\nplt.title('Landmark id distribuition and density plot')\nsns.distplot(train_df['landmark_id'],color='green', kde=True,bins=200)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:24:03.759775Z","iopub.execute_input":"2023-05-07T21:24:03.760139Z","iopub.status.idle":"2023-05-07T21:24:09.571182Z","shell.execute_reply.started":"2023-05-07T21:24:03.760106Z","shell.execute_reply":"2023-05-07T21:24:09.570221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#scatter plot\ntemp = train_df.landmark_id.value_counts().to_frame()\ntemp.reset_index(inplace=True)\ntemp.columns=['landmark_id','count']\n\nplt.figure(figsize=(15,5))\nsns.scatterplot(x='landmark_id', y='count', data=temp)\nplt.ylabel('# of images')\nplt.xlabel('landmark id')\nplt.title('Number of images for each landmark category')","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:24:09.572538Z","iopub.execute_input":"2023-05-07T21:24:09.572958Z","iopub.status.idle":"2023-05-07T21:24:10.169872Z","shell.execute_reply.started":"2023-05-07T21:24:09.572927Z","shell.execute_reply":"2023-05-07T21:24:10.168967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize = (15,5))\ncount = train_df.landmark_id.value_counts().sort_values(ascending=False)[:50]\nsns.countplot(x=train_df.landmark_id,order = train_df.landmark_id.value_counts().sort_values(ascending=False).iloc[:50].index)\nplt.xticks(rotation = 90)\nplt.xlabel(\"LandMark Id\")\nplt.ylabel(\"Frequency\")\nplt.title(\"Top 50 Classes in the Dataset\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:24:10.170853Z","iopub.execute_input":"2023-05-07T21:24:10.171181Z","iopub.status.idle":"2023-05-07T21:24:10.872087Z","shell.execute_reply.started":"2023-05-07T21:24:10.171152Z","shell.execute_reply":"2023-05-07T21:24:10.871229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_list = glob.glob('../input/landmark-recognition-2020/train/*/*/*/*')","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:24:10.873472Z","iopub.execute_input":"2023-05-07T21:24:10.874446Z","iopub.status.idle":"2023-05-07T21:32:09.660538Z","shell.execute_reply.started":"2023-05-07T21:24:10.874413Z","shell.execute_reply":"2023-05-07T21:32:09.656931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_list[:5]","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:32:09.667944Z","iopub.execute_input":"2023-05-07T21:32:09.668738Z","iopub.status.idle":"2023-05-07T21:32:09.676348Z","shell.execute_reply.started":"2023-05-07T21:32:09.668662Z","shell.execute_reply":"2023-05-07T21:32:09.675347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.rcParams[\"axes.grid\"] = False\nf, axarr = plt.subplots(4, 3, figsize=(15, 10))\ncurr_row = 0\nfor i in range(12):\n    example = cv2.imread(train_list[i])\n    example = example[:,:,::-1]\n    col = i%4\n    axarr[col, curr_row].imshow(example)\n    if col == 3:\n        curr_row += 1","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:32:09.677856Z","iopub.execute_input":"2023-05-07T21:32:09.678491Z","iopub.status.idle":"2023-05-07T21:32:12.081821Z","shell.execute_reply.started":"2023-05-07T21:32:09.678454Z","shell.execute_reply":"2023-05-07T21:32:12.079370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example = cv2.imread(train_list[112])\nplt.imshow(example)","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:32:12.083136Z","iopub.execute_input":"2023-05-07T21:32:12.084116Z","iopub.status.idle":"2023-05-07T21:32:12.415946Z","shell.execute_reply.started":"2023-05-07T21:32:12.084067Z","shell.execute_reply":"2023-05-07T21:32:12.415195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[\"filename\"] = train_df.id.str[0]+\"/\"+train_df.id.str[1]+\"/\"+train_df.id.str[2]+\"/\"+train_df.id+\".jpg\"\ntrain_df[\"label\"] = train_df.landmark_id.astype(str)","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:32:12.417121Z","iopub.execute_input":"2023-05-07T21:32:12.418035Z","iopub.status.idle":"2023-05-07T21:32:15.813024Z","shell.execute_reply.started":"2023-05-07T21:32:12.418006Z","shell.execute_reply":"2023-05-07T21:32:15.812112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-07T21:32:15.814493Z","iopub.execute_input":"2023-05-07T21:32:15.814845Z","iopub.status.idle":"2023-05-07T21:32:15.827939Z","shell.execute_reply.started":"2023-05-07T21:32:15.814813Z","shell.execute_reply":"2023-05-07T21:32:15.826924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from collections import Counter\ncount_val = train_df.landmark_id.values\nprint(count_val)\nprint(len(count_val))\ncount = Counter(count_val).most_common(1000)\nprint(len(count),count[-1])","metadata":{"execution":{"iopub.status.busy":"2023-05-07T22:02:37.810129Z","iopub.execute_input":"2023-05-07T22:02:37.810826Z","iopub.status.idle":"2023-05-07T22:02:38.048648Z","shell.execute_reply.started":"2023-05-07T22:02:37.810795Z","shell.execute_reply":"2023-05-07T22:02:38.047655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# only keep 1000 classes\nkeep_labels = [i[0] for i in count]\ntrain_keep = train_df[train_df.landmark_id.isin(keep_labels)]","metadata":{"execution":{"iopub.status.busy":"2023-05-07T22:03:32.872074Z","iopub.execute_input":"2023-05-07T22:03:32.872536Z","iopub.status.idle":"2023-05-07T22:03:32.907220Z","shell.execute_reply.started":"2023-05-07T22:03:32.872506Z","shell.execute_reply":"2023-05-07T22:03:32.906340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_rate = 0.2\nbatch_size = 32","metadata":{"execution":{"iopub.status.busy":"2023-05-07T22:03:39.141875Z","iopub.execute_input":"2023-05-07T22:03:39.142552Z","iopub.status.idle":"2023-05-07T22:03:39.146227Z","shell.execute_reply.started":"2023-05-07T22:03:39.142517Z","shell.execute_reply":"2023-05-07T22:03:39.145367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gen = ImageDataGenerator(validation_split=val_rate)\n\ntrain_gen = gen.flow_from_dataframe(\n    train_keep,\n    directory=\"/kaggle/input/landmark-recognition-2020/train/\",\n    x_col=\"filename\",\n    y_col=\"label\",\n    weight_col=None,\n    target_size=(256, 256),\n    color_mode=\"rgb\",\n    classes=None,\n    class_mode=\"categorical\",\n    batch_size=batch_size,\n    shuffle=True,\n    subset=\"training\",\n    interpolation=\"nearest\",\n    validate_filenames=False)\n    \nval_gen = gen.flow_from_dataframe(\n    train_keep,\n    directory=\"/kaggle/input/landmark-recognition-2020/train/\",\n    x_col=\"filename\",\n    y_col=\"label\",\n    weight_col=None,\n    target_size=(256, 256),\n    color_mode=\"rgb\",\n    classes=None,\n    class_mode=\"categorical\",\n    batch_size=batch_size,\n    shuffle=True,\n    subset=\"validation\",\n    interpolation=\"nearest\",\n    validate_filenames=False)","metadata":{"execution":{"iopub.status.busy":"2023-05-07T22:04:21.549774Z","iopub.execute_input":"2023-05-07T22:04:21.550112Z","iopub.status.idle":"2023-05-07T22:04:22.595433Z","shell.execute_reply.started":"2023-05-07T22:04:21.550084Z","shell.execute_reply":"2023-05-07T22:04:22.594472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#model\nmodel = tf.keras.Sequential([\n    efn.EfficientNetB2(\n        input_shape=(256, 256, 3),\n        weights='imagenet',\n        include_top=False\n    ),\n    L.GlobalAveragePooling2D(),\n    L.Dense(1000, activation='softmax')\n])\n\nmodel.compile(\n    optimizer='adam',\n    loss = 'categorical_crossentropy',\n    metrics=['categorical_accuracy']\n)","metadata":{"execution":{"iopub.status.busy":"2023-05-07T22:05:06.216748Z","iopub.execute_input":"2023-05-07T22:05:06.217088Z","iopub.status.idle":"2023-05-07T22:05:09.879358Z","shell.execute_reply.started":"2023-05-07T22:05:06.217062Z","shell.execute_reply":"2023-05-07T22:05:09.878444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# training parameters\nepochs = 5 # maximum number of epochs\ntrain_steps = int(len(train_keep)*(1-val_rate))//batch_size\nval_steps = int(len(train_keep)*val_rate)//batch_size\n\n# model_checkpoint = ModelCheckpoint(\"model_efnB3.h5\", save_best_only=True, verbose=1)","metadata":{"execution":{"iopub.status.busy":"2023-05-07T22:05:40.276651Z","iopub.execute_input":"2023-05-07T22:05:40.276996Z","iopub.status.idle":"2023-05-07T22:05:40.284256Z","shell.execute_reply.started":"2023-05-07T22:05:40.276970Z","shell.execute_reply":"2023-05-07T22:05:40.283352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(train_gen, steps_per_epoch=train_steps, epochs=epochs,validation_data=val_gen, validation_steps=val_steps)\n# history = model.fit_generator(train_gen, steps_per_epoch=train_steps, epochs=epochs,validation_data=val_gen, validation_steps=val_steps, callbacks=[model_checkpoint])\n\n# model.save(\"model.h5\")","metadata":{"execution":{"iopub.status.busy":"2023-05-07T22:05:50.764649Z","iopub.execute_input":"2023-05-07T22:05:50.764990Z","iopub.status.idle":"2023-05-08T02:03:36.855653Z","shell.execute_reply.started":"2023-05-07T22:05:50.764965Z","shell.execute_reply":"2023-05-08T02:03:36.852775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#accuracy\nplt.figure(0)\nplt.plot(history.history['categorical_accuracy'],label='tranning accuracy')\nplt.plot(history.history['val_categorical_accuracy'],label='validation accuracy')\nplt.title('Accuracy')\nplt.xlabel('epochs')\nplt.ylabel('accuracy')\nplt.legend()\nplt.show","metadata":{"execution":{"iopub.status.busy":"2023-05-08T02:04:27.832109Z","iopub.execute_input":"2023-05-08T02:04:27.832479Z","iopub.status.idle":"2023-05-08T02:04:28.170236Z","shell.execute_reply.started":"2023-05-08T02:04:27.832448Z","shell.execute_reply":"2023-05-08T02:04:28.169222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Loss\n\nplt.plot(history.history['loss'],label='tranning loss')\nplt.plot(history.history['val_loss'],label='validation loss')\nplt.title('Loss')\nplt.xlabel('epochs')\nplt.ylabel('loss')\nplt.legend()\nplt.show","metadata":{"execution":{"iopub.status.busy":"2023-05-08T02:04:34.576848Z","iopub.execute_input":"2023-05-08T02:04:34.577196Z","iopub.status.idle":"2023-05-08T02:04:34.859279Z","shell.execute_reply.started":"2023-05-08T02:04:34.577167Z","shell.execute_reply":"2023-05-08T02:04:34.858332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.read_csv(\"/kaggle/input/landmark-recognition-2020/sample_submission.csv\")\nsub[\"filename\"] = sub.id.str[0]+\"/\"+sub.id.str[1]+\"/\"+sub.id.str[2]+\"/\"+sub.id+\".jpg\"\nsub","metadata":{"execution":{"iopub.status.busy":"2023-05-08T02:04:41.429785Z","iopub.execute_input":"2023-05-08T02:04:41.430133Z","iopub.status.idle":"2023-05-08T02:04:41.502020Z","shell.execute_reply.started":"2023-05-08T02:04:41.430104Z","shell.execute_reply":"2023-05-08T02:04:41.501067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_gen = ImageDataGenerator().flow_from_dataframe(\n    sub,\n    directory=\"/kaggle/input/landmark-recognition-2020/test/\",\n    x_col=\"filename\",\n    y_col=None,\n    weight_col=None,\n    target_size=(256, 256),\n    color_mode=\"rgb\",\n    classes=None,\n    class_mode=None,\n    batch_size=1,\n    shuffle=True,\n    subset=None,\n    interpolation=\"nearest\",\n    validate_filenames=False)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-08T02:08:52.673122Z","iopub.execute_input":"2023-05-08T02:08:52.673492Z","iopub.status.idle":"2023-05-08T02:08:52.700973Z","shell.execute_reply.started":"2023-05-08T02:08:52.673464Z","shell.execute_reply":"2023-05-08T02:08:52.700078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_one_hot = model.predict_generator(test_gen, verbose=1, steps=len(sub))","metadata":{"execution":{"iopub.status.busy":"2023-05-08T02:09:35.244835Z","iopub.execute_input":"2023-05-08T02:09:35.245190Z","iopub.status.idle":"2023-05-08T02:13:03.341909Z","shell.execute_reply.started":"2023-05-08T02:09:35.245163Z","shell.execute_reply":"2023-05-08T02:13:03.337718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_one_hot2 = model.predict(test_gen, verbose=1, steps=len(sub))","metadata":{"execution":{"iopub.status.busy":"2023-05-08T02:13:32.739208Z","iopub.execute_input":"2023-05-08T02:13:32.740246Z","iopub.status.idle":"2023-05-08T02:16:30.712316Z","shell.execute_reply.started":"2023-05-08T02:13:32.740187Z","shell.execute_reply":"2023-05-08T02:16:30.710010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = np.argmax(y_pred_one_hot2, axis=-1)\ny_prob = np.max(y_pred_one_hot2, axis=-1)\nprint(y_pred.shape, y_prob.shape)","metadata":{"execution":{"iopub.status.busy":"2023-05-08T02:16:44.953040Z","iopub.execute_input":"2023-05-08T02:16:44.953430Z","iopub.status.idle":"2023-05-08T02:16:44.968994Z","shell.execute_reply.started":"2023-05-08T02:16:44.953401Z","shell.execute_reply":"2023-05-08T02:16:44.967982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_uniq = np.unique(train_keep.landmark_id.values)\n\ny_pred = [y_uniq[Y] for Y in y_pred]","metadata":{"execution":{"iopub.status.busy":"2023-05-08T02:16:50.307669Z","iopub.execute_input":"2023-05-08T02:16:50.308015Z","iopub.status.idle":"2023-05-08T02:16:50.323349Z","shell.execute_reply.started":"2023-05-08T02:16:50.307988Z","shell.execute_reply":"2023-05-08T02:16:50.322242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(len(sub)):\n    sub.loc[i, \"landmarks\"] = str(y_pred[i])+\" \"+str(y_prob[i])\nsub = sub.drop(columns=\"filename\")\nsub.to_csv(\"submission.csv\", index=False)\nsub","metadata":{"execution":{"iopub.status.busy":"2023-05-08T02:16:56.637522Z","iopub.execute_input":"2023-05-08T02:16:56.638074Z","iopub.status.idle":"2023-05-08T02:16:58.026309Z","shell.execute_reply.started":"2023-05-08T02:16:56.638044Z","shell.execute_reply":"2023-05-08T02:16:58.025244Z"},"trusted":true},"execution_count":null,"outputs":[]}]}