<jupyter_start><jupyter_text>Importing libraries and data<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import cv2
import os
import tensorflow as tf
#List of images
images_list = os.listdir('dataset/flickr30k_images/flickr30k_images/')
print(len(images_list))
image_size = (299, 299)
num_channels = 3<jupyter_output><empty_output><jupyter_text>Visualizing sample<jupyter_code>sample_size = 5000
sample_images_list = images_list[:sample_size]
images = []
for img_name in sample_images_list:
    images.append(plt.imread('dataset/flickr30k_images/flickr30k_images/' + img_name))
images = np.array(images)
for i in range(images.shape[0]):
    images[i] = cv2.resize(images[i], image_size)
    images[i] = images[i].reshape(1, image_size[0], image_size[1], num_channels)
images = np.vstack(images[:])
print(images.shape) #shape is now (30, 256, 256, 3)
plt.imshow(images[12])
plt.show()
images_caption = pd.read_csv('dataset/flickr30k_images/results.csv', delimiter='|')
images_caption.columns = ['image_name', 'comment_number', 'comment']
images_caption.head()
def get_captions(images_list, images_caption):
    """
    images_list: list of image names
    images_captions: dataframe extracted from results.csv
    
    Returns: List of captions corresponding to images_list
    """
    captions_list = []
    
    for img_name in images_list:
        captions_list.append(images_caption[images_caption['image_name'] == img_name]['comment'].iat[0])
    
    return captions_list
captions = np.array(get_captions(sample_images_list, images_caption))
print("Total Captions :", len(captions))
image_model = tf.keras.applications.InceptionV3(include_top=False, weights='imagenet')
new_input = image_model.input
hidden_layer = image_model.layers[-1].output

image_features_extract_model = tf.keras.Model(new_input, hidden_layer)
image_features_extract_model.summary()<jupyter_output>Model: "model"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            [(None, None, None,  0                                            
__________________________________________________________________________________________________
conv2d (Conv2D)                 (None, None, None, 3 864         input_1[0][0]                    
__________________________________________________________________________________________________
batch_normalization (BatchNorma (None, None, None, 3 96          conv2d[0][0]                     
__________________________________________________________________________________________________
activation (Activation)         (None, None, None, 3 0           batch_normalization[0][0]    [...]
{'fraction_non_alphanumeric': 0.12611377655928718, 'fraction_numerical': 0.021247429746401644, 'mean_word_length': 4.757396449704142, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '174950', 'license': 'MIT', 'n_tokens_mistral': 843, 'n_tokens_neox': 785, 'n_words': 163, 'path': 'image_captioning.ipynb', 'repo_name': 'manaskhatri/video-captioning', 'size': '2918'}