Skip to main content

A modular library for training, benchmarking, and experimenting with deep vision models.

Project description

About

refrakt_core is a deep learning research framework that re-implements key computer vision papers with high modularity, extensibility, and reproducibility. Designed for education, experimentation, and benchmarking, Refrakt enables rapid iteration on architectures, loss functions, and training routines โ€” all driven via configuration.

This project is part of a broader initiative to understand, unify, and visualize foundational and modern architectures through clean code, clear abstractions, and rigorous logging.

๐Ÿ“Œ Goals

  • Faithfully reproduce influential CV papers
  • Modularize training/evaluation pipelines using YAML + registry patterns
  • Enable quick debugging and metric logging via TensorBoard and Weights & Biases (W&B)
  • Serve as a platform for personal research, fine-tuning, or new model design

๐Ÿ“š Implemented Papers

  • Vision Transformer (ViT) โ€“ An Image is Worth 16x16 Words
  • ResNet โ€“ Deep Residual Learning for Image Recognition
  • Autoencoders โ€“ Learning Representations via Reconstruction
  • Swin Transformer โ€“ Hierarchical Vision Transformer with Shifted Windows
  • Attention is All You Need
  • ConvNeXt โ€“ A ConvNet for the 2020s
  • SRGAN โ€“ Photo-Realistic Single Image Super-Resolution with GANs
  • SimCLR โ€“ A Simple Framework for Contrastive Learning
  • DINO โ€“ Self-Supervised Vision Transformers
  • MAE โ€“ Masked Autoencoders
  • MSN โ€“ Masked Siamese Networks
  • LNN โ€“ Lagrangian Neural Networks

โš™๏ธ Setup

git clone https://github.com/refrakt-hub/refrakt_core.git
cd refrakt_core

# Create and activate a virtual environment
conda create -n refrakt python=3.10 -y
conda activate refrakt

# Install dependencies
pip install -r requirements.txt

๐Ÿงช Running Experiments

# Calling __main__.py
python -m refrakt_core.api --config refrakt_core/config/vit.yaml

# Calling `refrakt` as a command. 
refrakt --config ./refrakt_core/config/resnet.yaml


# Override on-the-fly
python -m refrakt_core.api.train \
    config.model.name=ResNet \
    config.optimizer.lr=0.0005 \
    config.trainer.epochs=20

CLI Usage

usage: refrakt [-h] --config CONFIG --mode {train,test,inference,pipeline}
               [--log_dir LOG_DIR]
               [--log_type [{tensorboard,wandb} ...]]
               [--console]
               [--model_path MODEL_PATH]
               [--debug]
Flag Description
--config Path to YAML config file
--mode Execution mode: train, test, inference, or pipeline
--log_dir Path to log directory (e.g., ./runs)
--log_type Logging backend: tensorboard, wandb, or both
--console Print logs to console as well
--model_path Path to model weights/checkpoint for inference/test
--debug Enable debug mode with extra verbosity

๐Ÿ”ง Config Structure (YAML)

All components (model, trainer, loss, optimizer, scheduler) are defined in modular YAML files under refrakt_core/config/.

Example: vit.yaml

dataset:
  name: MNIST
  params:
    root: ./data
    train: true
    download: true
  transform:
    - name: Resize
      params: { size: [28, 28] }
    - name: ToTensor
    - name: Normalize
      params:
        mean: [0.1307]
        std: [0.3081]

dataloader:
  params:
    batch_size: 32
    shuffle: true
    num_workers: 4
    drop_last: false

model:
  name: vit
  params:
    in_channels: 1
    num_classes: 10
    image_size: 28 
    patch_size: 7

loss:
  name: cross_entropy
  params: {}

optimizer:
  name: adamw
  params:
    lr: 0.0003

scheduler: null

trainer:
  name: supervised
  params:
    save_dir: "./checkpoints"
    model_name: "vit"
    num_epochs: 1
    device: cuda

๐Ÿ“ˆ Logging & Monitoring

โœ… Supported

  • TensorBoard (logs saved in runs/)
  • Weights & Biases (auto-logged via config)

Setup

# TensorBoard
tensorboard --logdir=./logs/<model_name>/tensorboard/

# Weights & Biases
export WANDB_API_KEY=your_key_here

๐Ÿงฑ Project Structure

refrakt_core/
โ”œโ”€โ”€ api/                  # CLI: train.py, test.py, inference.py
โ”‚   โ””โ”€โ”€ builders/         # Builders for models, losses, optimizers, datasets
โ”‚
โ”œโ”€โ”€ config/               # YAML configurations for each experiment
โ”‚   โ””โ”€โ”€ schema.py         # Pydantic validation for configs
โ”‚
โ”œโ”€โ”€ losses/               # Contrastive, GAN, MAE, VAE, etc.
โ”‚
โ”œโ”€โ”€ models/               # Vision architectures (ViT, ResNet, MAE, etc.)
โ”‚   โ””โ”€โ”€ templates/        # Base model templates and abstractions
โ”‚
โ”œโ”€โ”€ trainer/              # Task-specific training logic (SimCLR, SRGAN, etc.)
โ”‚
โ”œโ”€โ”€ registry/             # Decorator-based plugin system
โ”‚
โ”œโ”€โ”€ utils/                # Helper modules (encoders, decoders, data classes)
โ”‚
โ”œโ”€โ”€ transforms.py         # Data augmentation logic
โ”œโ”€โ”€ datasets.py           # Dataset definitions and loader helpers
โ”œโ”€โ”€ logging.py            # Logger wrapper for stdout + W&B/TensorBoard

๐Ÿงฉ Extending Refrakt

Add a New Model

  1. Create the architecture in models/your_model.py
  2. Inherit from a base class in models/templates/models.py
  3. Register it using:
from refrakt_core.registry.model_registry import register_model

@register_model("your_model")
class YourModel(BaseClassifier):
    ...
  1. Add a YAML config: config/your_model.yaml
  2. Write a custom trainer if needed (trainer/your_model.py)s

๐Ÿ” Example Output

Once training begins, expect:

  • Printed progress bar (via tqdm)
  • Metrics like loss/accuracy printed and logged
  • ./logs/<model_name>/ with events.out.tfevents for TensorBoard
  • W&B dashboard with training curves, if enabled

๐Ÿ“ฌ Contributing

  1. Clone and install:

    git clone ...
    pip install -r requirements-dev.txt
    pre-commit install
    
  2. Follow formatting (black, isort, pylint)

  3. Write tests for any new feature

  4. Run:

    pytest tests/
    

PRs and creating issues are absolutely welcome.

๐Ÿ”ญ Future Scope

Milestone Description
โœ… Stage 1 Paper re-implementations in notebooks
โœ… Stage 2 Modular training + model pipelines
๐Ÿ”œ Stage 3 Convert to a Python library (refrakt train, etc.)
๐Ÿ”œ Stage 4 Web app: visual dashboards, interactive inference
๐Ÿ”œ Stage 5 No-code/low-code config engine for multimodal pipelines
๐Ÿ”œ Stage 6 Explainability: saliency maps, attention visualizations

Planned additions include:

  • Mixed-modality support (e.g., image + text)
  • More contrastive/self-supervised frameworks
  • System-level benchmarks across GPUs
  • Evaluation on downstream tasks (detection, segmentation)

๐Ÿ“„ License

This repository is licensed under the MIT License. See LICENSE for full details.

๐Ÿ‘ค Maintainer

Akshath Mangudi If you find issues, raise them. If you learn from this, share it. Built with love and curiosity :)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

refrakt_core-0.2.1.tar.gz (66.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

refrakt_core-0.2.1-py3-none-any.whl (98.1 kB view details)

Uploaded Python 3

File details

Details for the file refrakt_core-0.2.1.tar.gz.

File metadata

  • Download URL: refrakt_core-0.2.1.tar.gz
  • Upload date:
  • Size: 66.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for refrakt_core-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4649b7372d1a8b9eeb26b240a87e21ebbd002bb4fc8b7b2b506f1d6f6226eca2
MD5 d6873deafc5f2045b338a4146e00b3dc
BLAKE2b-256 70fb1d43b7ded8bb2063d24624dab096d98b92ce52da3773e64f5db5bdd66ed8

See more details on using hashes here.

Provenance

The following attestation bundles were made for refrakt_core-0.2.1.tar.gz:

Publisher: pypi-publish.yml on refrakt-hub/refrakt_core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file refrakt_core-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: refrakt_core-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 98.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for refrakt_core-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1408201cdbe5abc8fcf6d3b197882f68c1765525f7a6451913d108bc44a369c
MD5 124899aa544f8d14b64f7536a3aefb82
BLAKE2b-256 c120f1850d9f06c4d3c694033c2b38490956818386e9b14cd3ddb4485e6526b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for refrakt_core-0.2.1-py3-none-any.whl:

Publisher: pypi-publish.yml on refrakt-hub/refrakt_core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page