This document contains code to generate image captions using a neural network model, collect actual and predicted captions, tokenize and pad the captions, convert them to sequences of numerical labels, and generate a confusion matrix to evaluate the model's performance at predicting captions. It loads an image, displays the real captions, generates a predicted caption, collects the actual and predicted captions, tokenizes the captions, pads them to a maximum length, converts them to labels, generates a confusion matrix, and visualizes the matrix to evaluate predictions against actual captions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
29 views2 pages
Matrix
This document contains code to generate image captions using a neural network model, collect actual and predicted captions, tokenize and pad the captions, convert them to sequences of numerical labels, and generate a confusion matrix to evaluate the model's performance at predicting captions. It loads an image, displays the real captions, generates a predicted caption, collects the actual and predicted captions, tokenizes the captions, pads them to a maximum length, converts them to labels, generates a confusion matrix, and visualizes the matrix to evaluate predictions against actual captions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2
from PIL import Image
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix import numpy as np from tensorflow.keras.preprocessing.text import Tokenizer from tensorflow.keras.preprocessing.sequence import pad_sequences
def generate_caption(image_name): # Get the image id from the image name image_id = image_name.split('.')[0]