How jokieleung/cl-vqa works
Main components of the system
• Data Management & Preprocessing:
• Data download and preparation are handled by scripts in the tools/ directory (download.sh, process.sh, etc.).
• The project links to an external dataset (via bottom-up-attention-vqa) that provides visual features.
• Data Loading & Processing:
• The dataset.py script is responsible for loading and preprocessing the inputs (images and questions).
• Utilities (utils.py) assist with general operations.
• Model Components:
• base_model.py contains the basic model architecture.
• language_model.py implements text processing components.
• classifier.py and fc.py likely define the classifier and fully-connected layers needed for prediction.
• attention.py implements the attention mechanism which is a core part of VQA.
• vqa_debias_loss_functions.py houses the loss functions that handle debiasing during training.
• Training and Evaluation Pipeline:
• main.py is used for training, with presets for argument handling.
• train.py could be an alternate or legacy training script.
• eval.py is used to evaluate the trained model.
• Contrastive Learning Mechanism:
• Though not separated into its own module, the contrastive mechanism for handling counterfactual samples is likely integrated within the training and loss components, such as within vqa_debias_loss_functions.py and possibly the base_model or classifier.
Relationships and interactions between the components
• Data flows from the Data Management layer (tools/) into dataset.py where the visual and textual data are prepared.
• The loaded data is then passed into the Model Components (base_model, language_model, classifier, attention) during both training and inference.
• During training (main.py or train.py), the model uses specific loss functions (vqa_debias_loss_functions.py) that integrate contrastive learning and debiasing.
• Evaluation (eval.py) reuses parts of the model architecture to test performance, possibly integrating evaluation metrics defined elsewhere.
• Utilities in utils.py support various modules with common helper functions.
Important architectural patterns and design principles
• Modular Design: Each key functionality (preprocessing, model definition, and evaluation) is isolated in its own Python module, making the system easier to maintain and extend.
• Clear Separation of Concerns: The structure cleanly distinguishes between “data tools,” “model components,” and “training/evaluation scripts.”
• Integration of External Data: A dedicated data setup process is emphasized (via external scripts and links) ensuring the model leverages precomputed bottom-up visual attention features.
• Contrastive and Debiasing Approach: The architecture integrates contrastive learning elements (through specialized loss functions and potentially through a separation of counterfactual data pipelines).
Relevant technologies, frameworks, or libraries
• PyTorch (v1.1.0) is the deep learning framework underpinning model operations.
• Python 2.7 is used, so note any legacy compatibility aspects.
• h5py for handling data storage in HDF5 format.
• numpy for numerical computations.
• tqdm for progress tracking during training.
• Click for command-line interface operations.
• Shell scripts are used for data management and preprocessing.
• Data flows from the tools/download scripts to the dataset loader.
• Connections from the dataset loader to the various model components in the forward pass.
• A training loop that feeds back loss values from the debias loss function into model parameter updates.