This guide covers all installation options for LayerD, from basic inference to full development setup.
We have verified reproducibility under the following environment:
- OS: Ubuntu 22.04 (should work on other Linux distributions and macOS)
- Python: 3.12.3 or compatible
- CUDA: 12.8 (optional, for GPU acceleration)
- Package Manager: uv 0.8.17 (for development)
- Minimum: 8GB RAM, CPU-only inference is supported
- Recommended: 16GB+ RAM, NVIDIA GPU with 8GB+ VRAM for faster inference
- Training: NVIDIA GPU with 16GB+ VRAM (A100 40GB recommended for efficient training)
Install the core package with inference and evaluation capabilities:
pip install git+https://github.com/CyberAgentAILab/LayerD.gitThis is suitable if you only want to:
- Decompose images into layers
- Run evaluations on decomposed layers
- Use the CLI or Python API
If you want to generate training datasets from Crello:
pip install "git+https://github.com/CyberAgentAILab/LayerD.git#egg=layerd[dataset]"This includes:
- All inference capabilities
- Crello dataset utilities
- Dataset generation tools
If you want to train or fine-tune models:
pip install "git+https://github.com/CyberAgentAILab/LayerD.git#egg=layerd[train]"This includes:
- All inference capabilities
- Training framework and utilities
- PyTorch distributed training support
If you want to use OCR (Optical Character Recognition) for text detection:
pip install "git+https://github.com/CyberAgentAILab/LayerD.git#egg=layerd[ocr]"This includes:
- All inference capabilities
- OCR backends (EAST and GOT-OCR2)
- Text detection during layer organization
OCR Backend Requirements:
- EAST: CPU-compatible, ~97MB model, lightweight text detection
- GOT-OCR2: CUDA-only, ~1.4GB model, full OCR with text recognition
Install with all optional dependencies:
pip install "git+https://github.com/CyberAgentAILab/LayerD.git#egg=layerd[all]"This includes everything: inference, dataset generation, training, and OCR support.
LayerD uses uv to manage the development environment.
- Install uv (if not already installed):
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Or with pip
pip install uv- Clone and install:
git clone https://github.com/CyberAgentAILab/LayerD.git
cd LayerD
uv sync --all-extrasThis installs all dependencies including development tools (pytest, mypy, ruff). Dev tools are included by default with uv sync.
See development.md for more details on development workflows.
On first run, LayerD automatically downloads pre-trained models:
-
BiRefNet matting model (~1GB)
- Source: HuggingFace repository cyberagent/layerd-birefnet
- Cached in:
~/.cache/huggingface/hub/
-
LaMa inpainting model (~200MB)
- Source: GitHub repository enesmsahin/simple-lama-inpainting
- Cached in:
~/.cache/simple_lama_inpainting/
Please ensure you have:
- Stable internet connection during first run
- At least 2GB free disk space for models
- Access to HuggingFace and GitHub (some networks may block these)
To use LayerD offline after initial setup:
- Run LayerD once with internet to download models
- Models will be cached locally
- Subsequent runs work offline
To manually download models:
from layerd import LayerD
# This downloads and caches models
layerd = LayerD(matting_hf_card="cyberagent/layerd-birefnet").to("cpu")Verify your installation by running a simple test:
from PIL import Image
from layerd import LayerD
# Create a LayerD instance (downloads models if needed)
layerd = LayerD(matting_hf_card="cyberagent/layerd-birefnet").to("cpu")
print("LayerD installed successfully!")Or use the CLI:
layerd --helpYou should see the CLI help message without errors.
If you encounter issues during installation, see the Troubleshooting Guide for detailed solutions:
- Dependency conflicts: Use a fresh virtual environment
- uv not found: Install uv first
- Model download fails: Check internet connection, try manual download, or configure proxy
- No space left: Free up 2GB+ or change cache directory
- CUDA issues: Use CPU mode or reduce process size
For complete troubleshooting steps, see troubleshooting.md.
To upgrade to the latest version:
pip install --upgrade git+https://github.com/CyberAgentAILab/LayerD.gitFor development installations:
cd LayerD
git pull
uv sync --all-extras --all-groups