Minimal PyTorch implementation of I-JEPA (ICLR 2023, Y. LeCun et al.). Self-supervised visual representation learning via multi-block masking + representation prediction.
pip install torch torchvision pillow numpyNo timm, no Hydra, no Lightning, no YAML.
Place images anywhere under data/train/:
data/train/
any_folder/
img001.jpg
img002.jpg
...
python train.pyCheckpoints saved to checkpoints/model.pt.
python inference.py --checkpoint checkpoints/model.pt --image dog.jpgPrints CLS shape: (192,) and Patch shape: (196, 192). Optional --save_npy to dump patch embeddings.
| Component | Encoder | Predictor |
|---|---|---|
| Depth | 12 | 6 |
| Dim | 192 | 192 |
| Heads | 3 | 3 |
| Params | ~5.7M | ~2.9M |
- Masking — Sample 1 large context block (85–100%) + 4 small target blocks (15–20%) per image. Overlapping patches removed from context.
- Context encoder — ViT on visible context patches only.
- Predictor — Narrow ViT, called once per target block. Receives context embeddings + mask tokens (shared learnable vector + positional embedding). Predicts target block representations.
- Loss —
1/M Σᵢ MSE(pred_blockᵢ, target_blockᵢ) - Target encoder — EMA copy of context encoder (momentum 0.996).
Edit config.py:
EMBED_DIM = 192 # 192 / 384 / 768
DEPTH = 12 # ViT depth
BATCH_SIZE = 64
EPOCHS = 100- Original paper: I-JEPA by Assran et al.