How nssharmaofficial/image-caption-generator works
Project Overview & Main Components
• Data & Preprocessing:
• Input image files from the Flickr30k dataset.
• Caption files and associated train/validation splits (train_list*.txt, val_list*.txt).
• A vocabulary creation module (vocab.py) that processes the raw captions (captions.txt) into word2index and index2word mappings, output to vocabulary.txt.
• Data Loader Component:
• The custom ImageCaptionDataset class in dataset.py that loads and preprocesses images and captions. This includes padding captions (using PADDING_INDEX) and preparing image tensors.
• Model Architecture:
• Encoder: Utilizes a pre-trained ResNet50 (with the final classification layer removed) plus a linear layer that transforms the extracted image features to a desired dimension (IMAGE_EMB_DIM).
• Embedding Layer: Transforms input word indices from captions into dense vector representations (WORD_EMB_DIM).
• Decoder: Comprises an LSTM for sequential processing and a fully connected (FC) layer followed by LogSoftmax to output probabilities for each word in the vocabulary.
• Training & Evaluation:
• Training script (train.py and train_whole_sequence.py) ties together data loading, model processing, and iteratively trains by generating captions word-by-word.
• Evaluation and visualization are handled by test_show.py, which also computes BLEU scores for quality assessment.
• Inference:
• A separate script (predict_sample.py) uses the trained model to generate captions for new sample images.
Important Architectural Patterns & Design Principles
• Separation of concerns: Distinguish modules for data handling (dataset, vocabulary), model computation (encoder, embedding, decoder), and separate scripts for training, evaluating, and inference.
• Modularity: Each script (e.g., vocab.py, train.py, test_show.py) performs a distinct role and can be individually maintained.