How ivanpanshin/supcon-framework works
Main Components
• Config Manager:
• The “configs” directory holds all the YAML configuration files that dictate hyperparameters, training stages, and other experimental setups.
• Data Pipeline:
• Look into “tools/datasets.py” which defines dataset classes and augmentation logic (using albumentations).
• This module is responsible for loading, augmenting, and preprocessing the image data.
• Model & Loss Modules:
• The “tools” directory contains submodules such as “backbones.py”, “models.py”, and “losses.py” which define the neural network architectures (like ResNet18), projection heads, and various losses (including LabelSmoothing and contrastive losses).
• As a “Model Construction” block and “Loss Functions” block.
• Training Engines:
• The primary training scripts are “train.py” and “swa.py” (Stochastic Weight Averaging) with “learning_rate_finder.py” serving for hyperparameter optimization.
• Optimization & Utilities:
• Tools for optimizers, schedulers, and additional helper functions are available under “tools/optimizers.py”, “tools/schedulers.py”, and “tools/utils.py”.
• This forms the “Optimization & Utility” layer that configures backpropagation, learning rate scheduling, EMA, and mixed precision (AMP) handling.
• Logging & Visualization:
• The README and included notebook “t-SNE.ipynb” indicate that tensorboard logging and t-SNE visualizations are key parts of tracking training progress and evaluating the model’s embeddings.
Relationships and Interactions
• Data Flow:
• The “Training Controller” orchestrates data loading (via the “Data Pipeline”), builds the neural network (invoking “Model & Loss Modules”), and applies optimization steps (using “Optimization & Utility”).
• Once training is underway, the process includes periodic validations and logging through “Logging & Visualization”.
• Dependencies:
• The configuration files drive different training modes (first stage, second stage, LR finder, or SWA training).
• The “Training Controller” calls upon different components based on the configuration, such as using EMA or Automatic Mixed Precision (AMP).
Architectural Patterns & Technologies
• Modular Design:
• The code is separated into well-defined modules (configs, tools, training scripts) to follow modular programming principles.
• Two-Stage Training:
• External Libraries and Frameworks:
• Key libraries include PyTorch for deep learning, albumentations for augmentations, timm for model architectures, pytorch-metric-learning for evaluation metrics, and tensorboard for logging.
• As external dependencies interacting with the core modules.