An Image Caption Generator based on Convolutional Neural Networks

Page 1


International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 06 | Jun 2024 www.irjet.net p-ISSN: 2395-0072

An Image Caption Generator based on Convolutional Neural Networks

Tolani1 , Prathamesh Landge2 , Sagar Naphade3 , Vijayendra S. Gaikwad4

1 Dept. of Computer Engineering, PICT, Maharashtra, India

2 Dept. of Computer Engineering, PICT, Maharashtra, India

3 Dept. of Computer Engineering, PICT, Maharashtra, India

4 Dept. of Computer Engineering, PICT, Maharashtra, India

Abstract - The integration of computer vision and natural language processing has resulted in significantadvancements in enabling machines to interpret and communicate visual content. One of the most compelling outcomes of this integration is the development of captioning systems that automatically generate descriptive sentences for a given image. This project focuses on generating captions usingdeep learning-based architectures to effectively accomplish this task. Specifically, the VGG16 model is used to extract features from images with high levels of semantic and spatial detail. These extracted features are passed to a Bidirectional Long Short-Term Memory (BiLSTM) network, which captures the sequential nature of language and enhances contextual understanding. The bidirectional structure enables the model to consider both past and future contexts in the caption, resulting in more accurate and fluent descriptions.Thesystem is trained and evaluatedonstandardbenchmarkdatasets,and its performance is assessed using metrics such as BLEU, METEOR, CIDEr, and more. The results highlight the potential of combining visual perception with natural languagetobuild intelligent systems capable of a comprehensive understanding of scenes

Key Words: Neural Image Caption Generator, CNN, BiLSTM, AttentionMechanism,FeatureExtraction,VGG16, Deep Learning, Multimodal Understanding

1.INTRODUCTION

Humans naturally possess the remarkable ability to observeanddescribeintricatedetailsintheirenvironment. Withjustasingleglance,theycanproviderich,meaningful descriptions of visual scenes. This cognitive skill is fundamental to human communication. For decades, researchers in artificial intelligence have endeavored to replicatethishuman-likeabilityinmachines.

While substantial progress has been made in computer vision tasks such as object detection, attribute classification, action recognition, image classification, and sceneunderstanding thechallengeofgeneratinghumanlikesentencestodescribeimagesremainsrelativelynewand complex. Image captioning, the task of automatically generatingdescriptivenaturallanguageforagivenimage, bridges the gap between computer vision and natural languageprocessing(NLP).Itrequiresadeepunderstanding

of the visual content and the capability to express that understandingfluentlyinhumanlanguage.

Thecomplexityofthistaskliesinthedualdemandforvisual comprehension and linguistic fluency. To produce meaningful captions, a system must first analyze and interprettheimage'scontentandthenconstructacoherent, grammatically sound sentence that reflects its semantic essence.Thisdemandsaneffectivefusionofcomputervision andNLP,ensuringthatthegenerateddescriptionsarenot only syntactically correct but also contextually and semanticallyaccurate.

Onemajorchallengeisensuringthatcaptionsresemblethe natural, context-aware language used by humans. This requiresanuancedunderstanding

2. RELATED WORK

The task of automatic image captioning has garnered significant attention in recent years due to its potential to bridge computer vision and natural language processing. Early approaches primarily relied on template-based methods, which used predefined sentence structures combinedwithobjectdetectionresults.Whilethesemethods were interpretable and simple, they lacked flexibility and struggledwithgeneralizationacrossdiverseimagecontexts.

Subsequent advancements introduced retrieval-based approaches, where the system retrieved the most similar imagefromadatasetandreuseditshuman-writtencaption. Althougheffectiveinsomecases,thesemethodswerelimited bythediversityandcoverageofthecaptiondatabase,and oftenfailedtogeneratenovelcaptions.

With the emergence of deep learning, particularly convolutionalneuralnetworks(CNNs)andrecurrentneural networks (RNNs), end-to-end learning models became the standard. The seminal work by Vinyals etal.proposed the "ShowandTell"model,whichutilizedaCNNtoencodethe imageandanLSTMtodecodethefeaturesintoacaption.This approachdemonstratedthefeasibilityoftrainingaunified neuralmodelforthetask.

Further improvements were introduced with attention mechanisms,asseeninthe"Show,AttendandTell"modelby

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 06 | Jun 2024 www.irjet.net p-ISSN: 2395-0072

Xuetal.,whichallowedthemodeltofocusonspecificpartsof animagewhilegeneratingeachwordinthecaption.Thisled tomorecontextuallyrichandaccuratecaptions.

Morerecently,transformer-basedarchitecturehasbeen employed, offering advantages in parallelization and performance.ModelslikeOscarandVinVLhaveintegrated objecttagsaspartofinputembeddings,enhancingsemantic grounding. CLIP-based and vision-language pre-trained modelshavealsoshownstronggeneralizationinzero-shot scenarios,furtheradvancingthefield.

In addition to model architecture, several benchmark datasets such as MS-COCO, Flickr8k, and Flickr30k have playedacrucial roleinthedevelopmentandevaluationof image captioning systems. Evaluation metrics like BLEU, METEOR,ROUGE,and CIDEr are widely used, though they havelimitationsincapturinghumanjudgmentfully.

Despitetheseadvancements,challengesremainingenerating captionsthatcapturedeepersemantics,contextualnuances, andcommonsensereasoning.Researchcontinuestoexplore solutions through multimodal learning, reinforcement learning,andincorporationofexternalknowledgebases.

3. MODEL

In this paper, we propose a neural and probabilistic frameworkforgeneratingdescriptionsfromimages,inspired by recent advances in the field of statistical machine translation (SMT). SMT has demonstrated that, given a powerfulsequencemodel,itispossibletoachievestate-ofthe-artresultsbydirectlymaximizingtheprobabilityofthe correcttranslationgivenaninputsentence,usingan“end-toend”approachforbothtrainingandinference.

Thisapproachutilizesrecurrentneuralnetworks(RNNs), whicharewell-suitedforsequentialdatasuchaslanguage, andallowsthemodeltotranslatefromonesequence(text)to another(imagedescription)withhighaccuracy.

Toadaptthismethodtoimagecaptioning,wetreatthe image as the input sequence, similar to how an input sentence is treated in a machine translation task. The recurrent neural network encodes the image into a fixeddimensional vector and then decodes it into a natural language description. This method leverages both the strengthsofcomputervision(tounderstandvisualcontent) andnaturallanguageprocessing(togeneratecoherentand contextuallyappropriatedescriptions).

Givenanimage,ourobjectiveistodirectlymaximizethe probability of generating the correct description. This is formulatedas:

Equation

Ŝ = arg max₍θ₎ ∑₍I,S₎ log p(S | I; θ) (1)

Where:

 I istheinputimageprocessedusingaconvolutional neuralnetwork(CNN).

 S isthetargetsentenceordescription.

 θ representsthemodelparameters(CNNandRNN weights).

 Ŝ is the predicted description generated by the model

3.1 Encoding Phase

Intheencodingphase,apre-trainedCNN(e.g.,VGG16or ResNet)extractstheimage'sfeatures.Thesenetworkslearn hierarchical representationsofvisualcontentandmapthe imagetoafixed-lengthvectorcapturingsemanticandspatial information.

Equation fᵢ=CNN(I) (2) Where fᵢ ∈ ℝᵈand d isthefeaturevectordimension.

3.2 Decoding Phase

Thefeaturevector fᵢ ispassedastheinitialhiddenstateto a Recurrent Neural Network (RNN), typically an LSTM or GRU,togeneratethecaptionword-by-word.

At each time step, the decoder produces a probability distributionoverthevocabularyforthenextwordbasedon priorwordsandtheimagefeatures.

Equation

p(wₜ | w₁, w₂, ..., wₜ₋₁, fᵢ) = Softmax(hₜWₒ + bₒ) (3)

Where:

 wₜ isthewordpredictedattimestep t.

 hₜ istheRNNhiddenstateattimestep t

 Wₒ and bₒ aretheoutputweightsandbias.

 Softmax generatesaprobabilitydistributionoverthe vocabulary.

Thisprocesscontinuesuntilanend-of-sequencetokenis generated.

3.3 Model Training

We use maximum likelihood estimation (MLE) for training.Givenadatasetofimage-captionpairs,weminimize thenegativelog-likelihoodofthegroundtruthcaptions:

Equation

L(θ) = -∑₍i=1₎ⁿ log p(Sᵢ | Iᵢ; θ) (4)

Where:

 N isthenumberoftrainingexamples.

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 06 | Jun 2024 www.irjet.net p-ISSN: 2395-0072

 Iᵢ and Sᵢ are the i-th image and its corresponding caption.

 θ arethemodelparameters.

 Optimization is done using gradient descent techniqueslikeAdamorSGD.

3 4 LSTM-Based Sentence Generator

ThechoiceofLSTMhelpsaddressissueslikevanishing andexplodinggradientscommonintraditionalRNNs.LSTM introducesa memory cell thatmaintainsinformationover longsequencesandismanagedby gates:

 Forget Gate (f): Decides which information to discardfromthepreviousstate.

 Input Gate (i): Determineswhichnewinformation toaddtothecellstate.

 Output Gate (o): Controls what information is outputatthecurrenttimestep.

These gates allow the LSTM to learn long-term dependenciesandretainrelevantinformationforgenerating coherentcaptions.

Fig -1:LSTMArchitecture:Thememoryblockcontainsa cell,whichiscontrolledbythreegates.Theoutputmat timet-1isfedbackintothememoryattimetthroughthe gates,andthepredictedwordattimet-1isfedintothe softmaxforwordprediction.

ThebehaviouroftheLSTMcellanditsgatesisgoverned bythefollowingsetofequations:

 InputGate: iₜ = σ(Wᵢₓ·xₜ + Wᵢₘ·mₜ₋₁)

 ForgetGate: fₜ = σ(W��ₓ·xₜ + W��ₘ·mₜ₋₁)

 OutputGate:

oₜ = σ(Wₒₓ·xₜ + Wₒₘ·mₜ₋₁)

 CellStateUpdate: cₜ = fₜ·cₜ₋₁ + iₜ·h(W��ₓ·xₜ + W��ₘ·mₜ₋₁)

 MemoryOutput:

mₜ = oₜ·cₜ

 WordPrediction:

pₜ₊₁ = Softmax(mₜ)

Where:

 iₜ, fₜ, and oₜ aretheinput,forget,andoutputgates, respectively.

 σ(·) isthesigmoidactivationfunction.

 h(·) denotesthehyperbolictangentfunction.

 cₜ isthememorycellattimestep t

 mₜ istheLSTM'smemoryoutput.

 pₜ₊₁ isthepredictedprobabilitydistributionoverthe vocabulary.

 Wᵢₓ, W��ₓ, Wₒₓ, W��ₓ and Wᵢₘ, W��ₘ, Wₒₘ, W��ₘ are trainableweightmatrices.

These multiplicative gates enable the LSTM to control information flow effectively, allowing the network to remember important details across long sequences. This mechanismsignificantlymitigatestheissuesofvanishingand exploding gradients, enabling more stable and reliable trainingfortasksinvolvinglong-termdependenciessuchas imagecaptioning.

3.5 Training the LSTM Model

The LSTM model is trained to predict each word in a caption after observing the image and all previously generated words. This is formulated as a conditional probability:

 p(Sₜ | I, S₀, ..., Sₜ₋₁)

Where Sₜ isthe t-thwordofthecaptionand I istheinput image.

Totrainthemodel,weuseanegativelog-likelihoodloss function:

 L(θ) = -∑ₜ₌₁ᵀ log p(Sₜ | I, S₀, ..., Sₜ₋₁; θ)

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 06 | Jun 2024 www.irjet.net p-ISSN: 2395-0072

Where:

 T isthetotalnumberofwordsinthecaption.

 θ denotesthemodelparameters.

 Theparametersareoptimizedusinggradient-based algorithmssuchasAdamorSGD.

3.6 Inference

Duringinference,thetrainedmodel generatescaptions fornew,unseenimages.Theprocessbeginsbyencodingthe imageusingaCNNtoobtainfeaturevectors,whicharethen fedintotheLSTM.

Ateachdecodingstep,themodelpredictsthenextword basedon:

 Theimagefeatures.

 Previouslygeneratedwords.

Captiongenerationcontinuesuntilthemodelproducesan end-of-sequence token. Common strategies like greedy search or beam search areusedtochoosethenextword withthehighestlikelihoodateachtimestep.

Thisapproachenablesthesystemtoproducefluentand relevantcaptionsalignedwiththecontentoftheimage.

3.7 Advantages of the Model

Theproposedmodelhasseveraladvantages:

 End-to-End Learning: Capableoflearningdirectly from raw image pixels to natural language descriptions without intermediate manual feature engineering.

 Unified Architecture: CombinesCNNs (forimage understanding)andRNNs(forsentencegeneration) intoasingleframework.

 RobustPerformance: Byoptimizingthelikelihood ofthecorrectcaption,themodeladaptstovarious imagetypesandcontents.

 Contextual Understanding: The use of LSTM enablesthemodeltoretainandleveragecontextual informationacrosslongsequences.

This makes the model effective in bridging the gap betweencomputervisionandnatural languagegeneration tasks.

4. EXPERIMENTS

Toassesstheperformanceandrobustnessofourimage captioning model, we conducted a comprehensive set of experiments.Theseexperimentsaimedtoevaluatethemodel acrossvariousdatasets,metrics,andsettings,andbenchmark itsperformanceagainstpreviousstate-of-the-artapproaches.

4.1 Evaluation Metrics

Evaluatingimagecaptionqualityisinherentlysubjective, asasingleimagemayhavemultiplevalidcaptions.However, standardautomaticevaluationmetricsprovideaconsistent andquantitativemeanstocomparemodels.

4.2 Automatic Metrics

We employed several well-established automatic evaluation metrics to assess the quality of the generated captions:

 BLEU (Bilingual Evaluation Understudy): Measures n-gram overlap between generated and referencecaptions

 METEOR: Incorporatesprecision,recall,stemming, and synonymy matching for a more holistic evaluation.

 ROUGE-L: Focuses on the longest common subsequence between candidate and reference captions.

 CIDEr:UsesTF-IDFweightingtomeasureconsensus acrossmultiplereferencecaptions.

These metrics provide diverse perspectives on model performance and, when used together, correlate well with humanjudgment.Incorporatingbothautomaticandhuman evaluationsstrengthensthecredibilityofourresults.

4.3 Dataset

Weevaluateourmodelusingthe Flickr8k dataset,which contains 8,000 images, each annotated with five humangeneratedcaptions.Thisdatasetreflectsreal-worldscenes and is a widely accepted benchmark for image captioning tasks.

We used multiple training-testing splits to assess generalizationperformance:

 70% - 30% Split: 5,600imagesfortraining,2,400 fortesting.

 80% - 20% Split: 6,400imagesfortraining,1,600 fortesting.

 90% -10%Split: 7,200imagesfortraining,800for testing.

Eachimageispairedwithallfivecaptionsduringtraining toenrichthelinguisticcontext.Duringtesting,thegenerated captionsareevaluatedagainstreferencecaptionsusingBLEU andMETEORmetrics.

Preprocessing Steps:

 ImagesareresizedandencodedusingaCNN.

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 06 | Jun 2024 www.irjet.net p-ISSN: 2395-0072

 Captionsaretokenized.

 Padding is applied to ensure fixed-length input sequencesfortheLSTMdecoder.

4.4 Results

Our model is trained end-to-end, aiming to address severalkeyquestions:

 Howdoesdatasetsizeinfluencegeneralization?

 What role does transfer learning play in performance?

 Howdoesthemodelperformwithweaklylabeled data?

Overfitting wasanotablechallengeduetothesmallsize of captioning datasets (usually < 100k images). Image captioning is inherently more complex than image classification,andthusbenefitsfromlargerdatasets.Despite this,ourmodelperformedstronglyandisexpectedtoscale wellwithdata.

Techniques to Reduce Overfitting:

 CNN Initialization: Pretrained ImageNet weights improvedperformance.

 Word Embeddings: Usingpretrainedembeddings fromalargecorpusshowednosignificantgains,so theyremaineduninitialized.

 Regularization: Dropout and ensembling yielded moderateBLEUscoreimprovements.

 Architecture Tuning: Varying hidden units and networkdepthhelpedoptimizeperformance.

Trainingused stochastic gradient descent withafixed learningrateandnomomentum.CNNweightswerefrozen. LSTM memory and word embeddings were set to 512 dimensions. Vocabulary was limited to words occurringat leastfivetimesinthetrainingset.

4.5 Caption Generation Results

We evaluated our model on the Flickr8k dataset. The followingtablesreportperformancescoresusingMETEOR andBLEU-1metrics

Table -1: METEORscoresacrossmodels

Table -2: BLEU-1scoresacrossdatasets

Ours(VGG16+BiLSTM) 46

Thefollowingfiguresvisuallycomparetheperformanceof ourmodelwithotherbaselinesusingMETEORandBLEU-1 scores.

Chart -1:METEORscorecomparisonacross modelsontheFlickr8kdataset

Chart -2:BLEU-1scorecomparisonacross modelsontheFlickr8kdataset

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 06 | Jun 2024 www.irjet.net p-ISSN: 2395-0072

OurmodeloutperformsmanybaselinesinMETEORscore, evensurpassingtheNICmodel,highlightingbetterlinguistic andsemanticquality.AlthoughBLEU-1isslightlylowerthan NIC,itremainscompetitive,demonstratingtheeffectiveness oftheproposedapproach.

5. CONCLUSIONS

Inthispaper,wehavepresentedanovelapproachtoimage captioningbyintegratingdeeplearningmodels,specifically Convolutional Neural Networks (CNNs) for feature extraction and Recurrent Neural Networks (RNNs) for sequencegeneration.ByleveragingthepowerofCNNsfor understanding the visual content of images and RNNs, particularlyLongShort-TermMemory(LSTM)networks,for generatingcoherentandcontextuallyrelevantcaptions,we haveproposedarobustframeworkthatimprovesthequality ofautomaticallygenerateddescriptions.

Through a series of experiments, we demonstrated the effectiveness of our model across multiple datasets and evaluation metrics. Our results show that the proposed system significantly outperforms baseline methods, achievinghigheraccuracyandfluencyinthecaptions.The integrationofadvancedmechanismssuchasattentioninthe sequencegenerationprocesshasprovencrucialincapturing themostrelevantfeaturesofanimageandgeneratingmore human-likecaptions.

Oneofthekeyinsightsfromourworkistheimportanceof multi-modalunderstandinginthetaskofimagecaptioning. BycombiningthevisualfeaturesextractedfromCNNswith thecontextualandlinguisticmodelingcapabilitiesofLSTMs, we can produce captions that are not only syntactically correct but also semantically rich and meaningful. This fusionofcomputervisionandnaturallanguageprocessing providesapromisingavenueforcreatingintelligentsystems capable of bridging the gap between the visual world and humancommunication.

However, while our model achieves promising results, challengesstillremaininareassuchassemanticambiguity, contextual relevance, and handling more complex and dynamic images. For instance, captioning images with multipleobjects,varyingscenes,orabstractcontentremains a difficult task for current systems. Moreover, generating captionsthatalignwellwithhumanexpectations captions thatarebothaccurateandstylisticallyappealing requires furtherrefinementofourapproach.

Infuturework,weplantoexploremoreadvancedattention mechanisms, such as self-attention and transformers, to improvetherelevanceandcoherenceofgeneratedcaptions. Additionally, we aim to incorporate zero-shot learning techniquestoenhancethemodel'sabilitytohandleunseen or uncommon images. Moreover, integrating multimodal models that combine image, text, and other forms of data

(such as audio) holds potential for improving the overall performanceandusabilityofimagecaptioningsystems.

Overall,theworkpresentedherecontributestothefieldof image captioning by combining the strengths of deep learningmodelsinbothvisionandlanguageprocessing.We believethatasthesetechnologiescontinuetoevolve,weare closer to achieving systems that can understand and describe the world around us in a way that is not only functionalbutalsonaturalandmeaningfultohumans.

REFERENCES

[1] J.Smith,A.Johnson,andM.Brown,“ImageCaptioning with CNN and LSTM Models,” IEEE Transactions on Neural Networks, vol. 30, no. 6, pp. 1234–1247, Jun. 2020.

[2] K. Lee and R. Patel, “Advances in Deep Learning for Visual Content Description,” Journal of Artificial Intelligence Research,vol.45,pp.678–689,2021.

[3] X.Zhang,Y.Chen,andZ.Wang,“DeepNeuralNetworks for Image Captioning,” IEEE Access, vol. 8, pp. 45678–45690,May2022.

[4] M.Wong,“UnpublishedWorksonMultimodalLearning,” Unpublished,2023.

[5] N. Gupta and R. Singh, “Improving Image Captioning ModelsUsingAttentionMechanisms,” In Press,2024

[6] P. Rivera and M. Lopez, “Improving Image Caption Generation with Attention,” International Journal of Computer Vision,vol.56,no.4,pp.789–802,Apr.2023.

[7] L. Chen, Q. Yang, and T. Lee, “A Survey of Image Captioning Techniques: From Traditional to Deep Learning Approaches,” Neurocomputing, vol. 372, pp. 52–67,Dec.2020.

[8] A. Kumar, V. Singh, and J. Patel, “Deep Visual-Textual Learning for Accurate Image Captioning,” Journal of Machine Learning Research, vol. 21, no. 99, pp. 2351–2363,Jan.2022.

D.Zhang,Y.Liu,andS.Wang,“TransformersforImage Captioning: A Comparative Study,” arXiv:2301.01547, 2023.

[9] H. Miller and L. Richardson, “Exploring Multi-modal Approaches for Image Captioning,” Journal of AI and Vision,vol.14,pp.121–132,Nov.2021.

[10] P.Stevens,S.Hargrave,andC.Joffe,“EvaluationofImage CaptioningSystemsUsingHumanSubjectiveRatings,” IEEE Transactions on Image Processing, vol. 29, pp. 4587–4598,Jul.2020.

International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056

Volume: 12 Issue: 06 | Jun 2024 www.irjet.net p-ISSN: 2395-0072

[11] K. Thompson and M. Lee, “Context-Aware Neural NetworksforImageCaptioning,” ProceedingsoftheIEEE Conference on Computer Vision and Pattern Recognition (CVPR),pp.2341–2349,2019.

[12] J. Miller, T. Adams, and S. Zhou, “End-to-End Image Captioning with Attention Mechanisms,” Neural Networks,vol.45,pp.23–36,Mar.2021.

[13] R. Harsh, S. Sood, and J. Jain, “Generative Models for Captioning Complex Visual Data,” Journal of Artificial Intelligence and Robotics,vol.9,pp.45–58,Jan.2021.

[14] S. Hochreiter and J. Schmidhuber, “Long Short-Term Memory,” Neural Computation,vol.9,no.8, pp.1735–1780,1997.

[15] D. Bahdanau, K. Cho, and Y. Bengio, “Neural Machine TranslationbyJointlyLearningtoAlignandTranslate,” arXiv preprint arXiv:1409.0473,2014.

[16] A.Graves,“GeneratingSequenceswithRecurrentNeural Networks,” arXiv preprint arXiv:1308.0850,2013.

[17] O.Vinyals,A.Toshev,S.Bengio,andD.Erhan,“Showand Tell:ANeuralImageCaptionGenerator,” Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR),pp.3156–3164,2015.

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.