How yueyang1996/labo works
• A “LaBo” training/testing procedure (based on concept bottlenecks and submodular optimization), and
• A standard “linear probe” approach for interpretable image classification.
Main Components of the System
a. Experiment Driver and Interface:
– main.py acts as the primary entry point that dispatches experiments.
– Shell scripts (labo_train.sh, labo_test.sh, linear_probe.sh) wrap around the training/test routines.
b. Configuration Management:
– The cfg/ directory holds configuration files for both LaBo (in cfg/asso_opt) and linear probe experiments (in cfg/linear_probe). These configurations set system arguments, hyperparameters, and experiment settings.
c. Data Module:
– Data loaders are implemented in data.py (for LaBo) and data_lp.py (for linear probe).
– The datasets/ directory contains dataset-specific information (splits, concepts, and instructions on image storage), meaning that the data ingestion and preparation pipelines are crucial.
d. Model Implementations:
– LaBo Model: In models/asso_opt/asso_opt.py, this module implements the concept bottleneck model that utilizes language models and submodular optimization.
– Linear Probe: In models/linear_probe/linear_probe.py, this module implements the linear classification layer over image features.
– Concept Selection: In models/select_concept/select_algo.py, the algorithm for concept selection is provided.
e. Experiment Management and Checkpointing:
– The exp/ directory is used as a workspace to store model checkpoints and configuration snapshots from the training experiments.
– The output/ directory captures performance logs and results.
f. Utility and External Services:
– utils.py encapsulates auxiliary functions (preprocessing, feature extraction).
– External experiment logging/tracking with wandb is indicated in the README.
Relationships and Data Flows
– The configuration files, once parsed, direct two parallel branches:
• Data Pipeline: Data loaders (data.py / data_lp.py) use dataset definitions from the datasets/ folder.
• Model Pipeline: Depending on the experiment type, the corresponding model file is invoked (either asso_opt.py for LaBo or linear_probe.py for linear probe). When using LaBo, the concept selection module (select_algo.py) also comes into play.
– These pipelines finally converge in training or testing workflows (with main.py orchestrating) and then produce outputs that are stored in the exp/ and output/ directories.
– External modules like wandb are integrated during training to log metrics—this can be shown as a side component connecting to the training process.
Architectural Patterns and Design Principles
– Modularity: The project clearly separates configuration, data loading, model implementation, and experiment management.
– Separation of Concerns: Different directories deal with different aspects (models vs. datasets vs. configs).
– Extendibility: By having dedicated config files per dataset and shot variations, and separating the concept selection logic, changes or additions in new datasets or methods can be easily encapsulated.
– Reusability: Shared utilities in utils.py and separate data loading for different experiments foster a reusable design.
Relevant Technologies and Frameworks
– Python 3.9.13 is specified; the project likely leverages common deep learning frameworks (e.g., PyTorch) though that isn’t explicit in the tree.
– Experiment tracking is done using wandb.
– The configuration structure hints at potential use of argument parsers or configuration tools to manage experiment settings.