{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":1111676,"sourceType":"datasetVersion","datasetId":623289},{"sourceId":47156,"sourceType":"modelInstanceVersion","isSourceIdPinned":true,"modelInstanceId":39484},{"sourceId":47281,"sourceType":"modelInstanceVersion","isSourceIdPinned":true,"modelInstanceId":39583}],"dockerImageVersionId":30698,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport os\nfrom tqdm.notebook import tqdm\nfrom PIL import Image\nimport pickle\nfrom nltk.translate.bleu_score import corpus_bleu\nfrom tensorflow.keras.models import load_model\nfrom tensorflow.keras.utils import plot_model\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array, array_to_img\nfrom tensorflow.keras.preprocessing.text import Tokenizer\nfrom tensorflow.keras.preprocessing.sequence import pad_sequences\nfrom tensorflow.keras.utils import Sequence\nfrom tensorflow.keras.utils import to_categorical\nfrom tensorflow.keras.models import Sequential, Model\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, GlobalAveragePooling2D, Activation, Dropout, Flatten, Dense, Input, Layer\nfrom tensorflow.keras.layers import Embedding, LSTM, add, Concatenate, Reshape, concatenate, Bidirectional, RepeatVector, Dot, Lambda\nfrom tensorflow.keras.applications import DenseNet201, InceptionV3\nfrom tensorflow.keras.optimizers import Adam\nfrom tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau\nimport warnings\nfrom textwrap import wrap\n\nplt.rcParams['font.size'] = 14\nsns.set_style('dark')\nwarnings.filterwarnings('ignore')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-28T05:12:41.397782Z","iopub.execute_input":"2024-05-28T05:12:41.398643Z","iopub.status.idle":"2024-05-28T05:12:54.996966Z","shell.execute_reply.started":"2024-05-28T05:12:41.398611Z","shell.execute_reply":"2024-05-28T05:12:54.996019Z"},"trusted":true},"execution_count":1,"outputs":[{"name":"stderr","text":"2024-05-28 05:12:45.668759: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n2024-05-28 05:12:45.668878: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n2024-05-28 05:12:45.779641: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n","output_type":"stream"}]},{"cell_type":"code","source":"image_path = \"/kaggle/input/flickr8k/Images\"","metadata":{"execution":{"iopub.status.busy":"2024-05-28T05:12:54.998922Z","iopub.execute_input":"2024-05-28T05:12:54.999458Z","iopub.status.idle":"2024-05-28T05:12:55.006815Z","shell.execute_reply.started":"2024-05-28T05:12:54.999433Z","shell.execute_reply":"2024-05-28T05:12:55.005772Z"},"trusted":true},"execution_count":2,"outputs":[]},{"cell_type":"code","source":"captionss = pd.read_csv(\"/kaggle/input/flickr8k/captions.txt\")\ncaptionss.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-28T05:12:55.008128Z","iopub.execute_input":"2024-05-28T05:12:55.009063Z","iopub.status.idle":"2024-05-28T05:12:55.148375Z","shell.execute_reply.started":"2024-05-28T05:12:55.009019Z","shell.execute_reply":"2024-05-28T05:12:55.147512Z"},"trusted":true},"execution_count":3,"outputs":[{"execution_count":3,"output_type":"execute_result","data":{"text/plain":" image \\\n0 1000268201_693b08cb0e.jpg \n1 1000268201_693b08cb0e.jpg \n2 1000268201_693b08cb0e.jpg \n3 1000268201_693b08cb0e.jpg \n4 1000268201_693b08cb0e.jpg \n\n caption \n0 A child in a pink dress is climbing up a set o... \n1 A girl going into a wooden building . \n2 A little girl climbing into a wooden playhouse . \n3 A little girl climbing the stairs to her playh... \n4 A little girl in a pink dress going into a woo... ","text/html":"
| \n | image | \ncaption | \n
|---|---|---|
| 0 | \n1000268201_693b08cb0e.jpg | \nA child in a pink dress is climbing up a set o... | \n
| 1 | \n1000268201_693b08cb0e.jpg | \nA girl going into a wooden building . | \n
| 2 | \n1000268201_693b08cb0e.jpg | \nA little girl climbing into a wooden playhouse . | \n
| 3 | \n1000268201_693b08cb0e.jpg | \nA little girl climbing the stairs to her playh... | \n
| 4 | \n1000268201_693b08cb0e.jpg | \nA little girl in a pink dress going into a woo... | \n
Model: \"functional_5\"\n\n"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓\n┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mConnected to \u001b[0m\u001b[1m \u001b[0m┃\n┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩\n│ input_layer_3 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1920\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n│ (\u001b[38;5;33mInputLayer\u001b[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_3 (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m491,776\u001b[0m │ input_layer_3[\u001b[38;5;34m0\u001b[0m]… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ input_layer_4 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m34\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ - │\n│ (\u001b[38;5;33mInputLayer\u001b[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ reshape_1 (\u001b[38;5;33mReshape\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ dense_3[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ embedding_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m34\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m2,172,160\u001b[0m │ input_layer_4[\u001b[38;5;34m0\u001b[0m]… │\n│ (\u001b[38;5;33mEmbedding\u001b[0m) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ concatenate_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m35\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ reshape_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n│ (\u001b[38;5;33mConcatenate\u001b[0m) │ │ │ embedding_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ lstm_1 (\u001b[38;5;33mLSTM\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m525,312\u001b[0m │ concatenate_1[\u001b[38;5;34m0\u001b[0m]… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dropout_2 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ lstm_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ add_1 (\u001b[38;5;33mAdd\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ dropout_2[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m], │\n│ │ │ │ dense_3[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_4 (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m32,896\u001b[0m │ add_1[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dropout_3 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │ dense_4[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_5 (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8485\u001b[0m) │ \u001b[38;5;34m1,094,565\u001b[0m │ dropout_3[\u001b[38;5;34m0\u001b[0m][\u001b[38;5;34m0\u001b[0m] │\n└─────────────────────┴───────────────────┴────────────┴───────────────────┘\n","text/html":"┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓\n┃ Layer (type) ┃ Output Shape ┃ Param # ┃ Connected to ┃\n┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩\n│ input_layer_3 │ (None, 1920) │ 0 │ - │\n│ (InputLayer) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_3 (Dense) │ (None, 256) │ 491,776 │ input_layer_3[0]… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ input_layer_4 │ (None, 34) │ 0 │ - │\n│ (InputLayer) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ reshape_1 (Reshape) │ (None, 1, 256) │ 0 │ dense_3[0][0] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ embedding_1 │ (None, 34, 256) │ 2,172,160 │ input_layer_4[0]… │\n│ (Embedding) │ │ │ │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ concatenate_1 │ (None, 35, 256) │ 0 │ reshape_1[0][0], │\n│ (Concatenate) │ │ │ embedding_1[0][0] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ lstm_1 (LSTM) │ (None, 256) │ 525,312 │ concatenate_1[0]… │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dropout_2 (Dropout) │ (None, 256) │ 0 │ lstm_1[0][0] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ add_1 (Add) │ (None, 256) │ 0 │ dropout_2[0][0], │\n│ │ │ │ dense_3[0][0] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_4 (Dense) │ (None, 128) │ 32,896 │ add_1[0][0] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dropout_3 (Dropout) │ (None, 128) │ 0 │ dense_4[0][0] │\n├─────────────────────┼───────────────────┼────────────┼───────────────────┤\n│ dense_5 (Dense) │ (None, 8485) │ 1,094,565 │ dropout_3[0][0] │\n└─────────────────────┴───────────────────┴────────────┴───────────────────┘\n\n"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"\u001b[1m Total params: \u001b[0m\u001b[38;5;34m4,316,709\u001b[0m (16.47 MB)\n","text/html":"
Total params: 4,316,709 (16.47 MB)\n\n"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m4,316,709\u001b[0m (16.47 MB)\n","text/html":"
Trainable params: 4,316,709 (16.47 MB)\n\n"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n","text/html":"
Non-trainable params: 0 (0.00 B)\n\n"},"metadata":{}}]},{"cell_type":"code","source":"train_generator = CustomDataGenerator(df=train, X_col='image', y_col='caption', batch_size=64, directory=image_path, tokenizer=tokenizer, vocab_size=vocab_size, max_length = max_length, features=features)\nvalidation_generator = CustomDataGenerator(df=test, X_col='image', y_col='caption', batch_size=64, directory=image_path, tokenizer=tokenizer, vocab_size=vocab_size, max_length = max_length, features=features)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T06:00:36.272244Z","iopub.execute_input":"2024-05-28T06:00:36.272910Z","iopub.status.idle":"2024-05-28T06:00:36.281783Z","shell.execute_reply.started":"2024-05-28T06:00:36.272883Z","shell.execute_reply":"2024-05-28T06:00:36.280886Z"},"trusted":true},"execution_count":35,"outputs":[]},{"cell_type":"code","source":"model_name = \"SuperAwesomeCaptioner.keras\"\ncheckpoint = ModelCheckpoint(model_name, monitor=\"val_loss\", mode=\"min\", save_best_only=True, verbose=1)\n\nearlystopping = EarlyStopping(monitor=\"val_loss\", min_delta=0, patience=5, verbose=1, restore_best_weights=True)\n\nlearning_rate_reduction = ReduceLROnPlateau(monitor=\"val_loss\", patience=3, verbose=1, factor=0.2, min_lr=0.00000001)","metadata":{"execution":{"iopub.status.busy":"2024-05-28T06:00:36.446804Z","iopub.execute_input":"2024-05-28T06:00:36.447603Z","iopub.status.idle":"2024-05-28T06:00:36.453104Z","shell.execute_reply.started":"2024-05-28T06:00:36.447570Z","shell.execute_reply":"2024-05-28T06:00:36.452020Z"},"trusted":true},"execution_count":36,"outputs":[]},{"cell_type":"markdown","source":"## Training the Model","metadata":{}},{"cell_type":"code","source":"history = caption_model.fit(train_generator, epochs=30, validation_data=validation_generator, callbacks=[checkpoint, earlystopping, learning_rate_reduction])","metadata":{"execution":{"iopub.status.busy":"2024-05-28T06:00:37.893718Z","iopub.execute_input":"2024-05-28T06:00:37.894382Z","iopub.status.idle":"2024-05-28T06:21:54.716076Z","shell.execute_reply.started":"2024-05-28T06:00:37.894352Z","shell.execute_reply":"2024-05-28T06:21:54.715254Z"},"trusted":true},"execution_count":37,"outputs":[{"name":"stdout","text":"Epoch 1/30\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 487ms/step - loss: 5.6573\nEpoch 1: val_loss improved from inf to 4.20357, saving model to SuperAwesomeCaptioner.keras\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m314s\u001b[0m 574ms/step - loss: 5.6562 - val_loss: 4.2036 - learning_rate: 0.0010\nEpoch 2/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 129ms/step - loss: 4.2100\nEpoch 2: val_loss improved from 4.20357 to 3.89559, saving model to SuperAwesomeCaptioner.keras\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m82s\u001b[0m 152ms/step - loss: 4.2098 - val_loss: 3.8956 - learning_rate: 0.0010\nEpoch 3/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 128ms/step - loss: 3.9355\nEpoch 3: val_loss improved from 3.89559 to 3.75911, saving model to SuperAwesomeCaptioner.keras\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m82s\u001b[0m 151ms/step - loss: 3.9354 - val_loss: 3.7591 - learning_rate: 0.0010\nEpoch 4/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 121ms/step - loss: 3.7643\nEpoch 4: val_loss improved from 3.75911 to 3.68269, saving model to SuperAwesomeCaptioner.keras\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m78s\u001b[0m 143ms/step - loss: 3.7643 - val_loss: 3.6827 - learning_rate: 0.0010\nEpoch 5/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 118ms/step - loss: 3.6425\nEpoch 5: val_loss improved from 3.68269 to 3.65118, saving model to SuperAwesomeCaptioner.keras\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m77s\u001b[0m 141ms/step - loss: 3.6425 - val_loss: 3.6512 - learning_rate: 0.0010\nEpoch 6/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 128ms/step - loss: 3.5448\nEpoch 6: val_loss improved from 3.65118 to 3.62224, saving model to SuperAwesomeCaptioner.keras\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m82s\u001b[0m 151ms/step - loss: 3.5448 - val_loss: 3.6222 - learning_rate: 0.0010\nEpoch 7/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 126ms/step - loss: 3.4597\nEpoch 7: val_loss improved from 3.62224 to 3.62041, saving model to SuperAwesomeCaptioner.keras\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m81s\u001b[0m 148ms/step - loss: 3.4598 - val_loss: 3.6204 - learning_rate: 0.0010\nEpoch 8/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 122ms/step - loss: 3.4002\nEpoch 8: val_loss improved from 3.62041 to 3.61204, saving model to SuperAwesomeCaptioner.keras\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m77s\u001b[0m 143ms/step - loss: 3.4002 - val_loss: 3.6120 - learning_rate: 0.0010\nEpoch 9/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 130ms/step - loss: 3.3384\nEpoch 9: val_loss did not improve from 3.61204\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m83s\u001b[0m 152ms/step - loss: 3.3385 - val_loss: 3.6220 - learning_rate: 0.0010\nEpoch 10/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 129ms/step - loss: 3.2996\nEpoch 10: val_loss did not improve from 3.61204\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m82s\u001b[0m 151ms/step - loss: 3.2997 - val_loss: 3.6329 - learning_rate: 0.0010\nEpoch 11/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 125ms/step - loss: 3.2514\nEpoch 11: val_loss did not improve from 3.61204\n\nEpoch 11: ReduceLROnPlateau reducing learning rate to 0.00020000000949949026.\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m79s\u001b[0m 146ms/step - loss: 3.2515 - val_loss: 3.6346 - learning_rate: 0.0010\nEpoch 12/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 121ms/step - loss: 3.1730\nEpoch 12: val_loss did not improve from 3.61204\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m78s\u001b[0m 144ms/step - loss: 3.1729 - val_loss: 3.6456 - learning_rate: 2.0000e-04\nEpoch 13/30\n\u001b[1m536/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m━\u001b[0m \u001b[1m0s\u001b[0m 129ms/step - loss: 3.1358\nEpoch 13: val_loss did not improve from 3.61204\n\u001b[1m537/537\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m82s\u001b[0m 151ms/step - loss: 3.1358 - val_loss: 3.6512 - learning_rate: 2.0000e-04\nEpoch 13: early stopping\nRestoring model weights from the end of the best epoch: 8.\n","output_type":"stream"}]},{"cell_type":"code","source":"caption_model = load_model('/kaggle/input/densenet201/tensorflow2/aa/1/SuperAwesomeCaptioner.keras')","metadata":{"execution":{"iopub.status.busy":"2024-05-28T06:38:15.115445Z","iopub.execute_input":"2024-05-28T06:38:15.115800Z","iopub.status.idle":"2024-05-28T06:38:16.429575Z","shell.execute_reply.started":"2024-05-28T06:38:15.115773Z","shell.execute_reply":"2024-05-28T06:38:16.428793Z"},"trusted":true},"execution_count":55,"outputs":[]},{"cell_type":"markdown","source":"## Inference\n- Learning Curve (Loss Curve)\n- Assessment of generated captions (by checking relevance of caption wrt image, should add BLEU too I guess!)","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(20, 8))\nplt.plot(history.history['loss'])\nplt.plot(history.history['val_loss'])\nplt.title('Model Loss')\nplt.ylabel('Loss')\nplt.xlabel('Epochs')\nplt.legend(['train', 'val'], loc='upper left')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-28T06:38:16.431199Z","iopub.execute_input":"2024-05-28T06:38:16.431497Z","iopub.status.idle":"2024-05-28T06:38:16.810468Z","shell.execute_reply.started":"2024-05-28T06:38:16.431473Z","shell.execute_reply":"2024-05-28T06:38:16.809541Z"},"trusted":true},"execution_count":56,"outputs":[{"output_type":"display_data","data":{"text/plain":"