Skip to main content

Prerequisites

LAFT requires:
  • Python 3.11 or higher
  • CUDA-capable GPU (recommended for performance)
  • 8GB+ GPU memory for most experiments

Environment Setup

1

Create a Conda Environment

We recommend using conda to manage your Python environment:
conda create -n laft python=3.11
conda activate laft
While conda is recommended, you can also use virtualenv or other environment managers.
2

Install PyTorch

Install PyTorch from the official website first to ensure proper CUDA support:
# For CUDA 12.1 (adjust based on your CUDA version)
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
Make sure to select the correct PyTorch version for your CUDA installation.
3

Install Dependencies

Clone the repository and install required packages:
git clone https://github.com/yuneg11/laft.git
cd laft
pip install -r requirements.txt

Dependencies

The requirements.txt includes:
torch >= 2.3.0
torchvision >= 0.18.0
open_clip_torch >= 2.20.0
scikit-learn >= 1.5.0
tabulate >= 0.9.0
torcheval >= 0.0.6

Tested Versions

LAFT has been tested with:
  • torch==2.5.1
  • torchvision==0.20.1
  • torcheval==0.0.7
  • open_clip_torch==2.29.0

Dataset Setup

LAFT supports multiple datasets for semantic and industrial anomaly detection.

Directory Structure

Organize datasets in the data/ directory:
laft/
├── data/
│   ├── MNIST/              # ColorMNIST (auto-downloaded)
│   ├── waterbirds_v1.0/    # Waterbirds dataset
│   └── celeba/             # CelebA dataset

MNIST (ColorMNIST)

The MNIST dataset will be automatically downloaded when first used:
import laft

dataset = laft.build_semantic_dataset(
    name="color_mnist",
    split="train",
    root="./data",
    seed=42
)

Waterbirds

Download from the Waterbirds repository and extract to data/waterbirds_v1.0/.

CelebA

Download from the CelebA website and extract to data/celeba/.

Checkpoint Downloads

For baseline comparisons, download pre-trained checkpoints:
Download from the CLIPN repository:
mkdir -p checkpoints/clipn
Download each repeat checkpoint:
  • repeat1checkpoints/clipn/repeat1.pt
  • repeat2checkpoints/clipn/repeat2.pt
  • repeat3checkpoints/clipn/repeat3.pt
CLIPN checkpoints are only needed for running baseline comparisons, not for core LAFT functionality.
Download from the InCTRL repository:
mkdir -p checkpoints/inctrl
Download from Google Drive:MVTec AD:VisA:

Final Directory Structure

After completing installation, your directory should look like:
laft/
├── checkpoints/
│   ├── clipn/
│   │   ├── repeat1.pt
│   │   ├── repeat2.pt
│   │   └── repeat3.pt
│   └── inctrl/
│       ├── mvtec2.pt
│       ├── mvtec4.pt
│       ├── mvtec8.pt
│       ├── visa2.pt
│       ├── visa4.pt
│       └── visa8.pt
├── data/
│   ├── MNIST/
│   ├── waterbirds_v1.0/
│   ├── celeba/
│   ├── mvtec_anomaly_detection/
│   └── VisA_20220922/
├── laft/
├── scripts/
├── requirements.txt
└── README.md

Verification

Verify your installation:
import torch
import laft

print(f"PyTorch version: {torch.__version__}")
print(f"CUDA available: {torch.cuda.is_available()}")

# Test loading CLIP
model, transform = laft.load_clip("ViT-B-16-quickgelu:dfn2b")
print("LAFT installation successful!")
Expected output:
PyTorch version: 2.5.1
CUDA available: True
LAFT installation successful!
If CUDA is not available but you have a GPU, check your PyTorch installation and CUDA drivers.

Common Issues

If you encounter OOM errors:
import torch
torch.set_grad_enabled(False)  # Disable autograd to save memory
Or reduce batch size in your experiments.
If model downloads fail, manually specify the cache directory:
model, transform = laft.load_clip(
    "ViT-B-16-quickgelu:dfn2b",
    download_root="./checkpoints/open_clip"
)
Ensure datasets are in the correct directory structure and paths match the expected locations:
dataset = laft.build_semantic_dataset(
    name="color_mnist",
    split="train",
    root="./data",  # Adjust if your data directory is elsewhere
)

Next Steps

Quick Start Guide

Run your first LAFT example to verify everything works correctly

Build docs developers (and LLMs) love