Common issues and solutions when using LayerD.
ERROR: Cannot install layerd because these package versions have conflicting dependencies.
Solutions:
# Use fresh virtual environment
python -m venv layerd-env
source layerd-env/bin/activate # Windows: layerd-env\Scripts\activate
pip install git+https://github.com/CyberAgentAILab/LayerD.git
# Or upgrade pip first
pip install --upgrade pip setuptools wheel
pip install git+https://github.com/CyberAgentAILab/LayerD.git
# With conda
conda create -n layerd python=3.12
conda activate layerd
pip install git+https://github.com/CyberAgentAILab/LayerD.gitbash: uv: command not foundSolution:
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh # macOS/Linux
# or
pip install uvSolution: LayerD requires numpy 2.0+
pip install --upgrade "numpy>=2.0"Solutions:
# Check internet connection, then try manual download
python -c "from huggingface_hub import snapshot_download; snapshot_download('cyberagent/layerd-birefnet')"
# If behind proxy
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
# Use HuggingFace CLI for better resume support
pip install huggingface_hub[cli]
huggingface-cli download cyberagent/layerd-birefnetSolution: Free up 2GB+ or change cache directory
export HF_HOME=/path/to/new/cache
export TORCH_HOME=/path/to/new/cacheSolutions:
# Reduce process size
layerd = LayerD(matting_process_size=(512, 512))
# Or use CPU
layerd = layerd.to("cpu")
# For training: reduce batch size or use mixed precisionuv run python ./tools/train.py ... batch_size=2 mixed_precision=bf16Solutions:
# Check PyTorch CUDA installation
python -c "import torch; print(torch.cuda.is_available(), torch.version.cuda)"
# Reinstall PyTorch with CUDA (see https://pytorch.org/get-started/locally/)
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
# Check NVIDIA driver
nvidia-smiSolutions:
- Update GPU drivers
- Reinstall PyTorch:
pip uninstall torch torchvision && pip install torch torchvision - Check hardware:
nvidia-smi - Try CPU mode to isolate issue:
layerd.to("cpu")
Solutions:
# Use PNG input (not JPEG) to avoid compression artifacts
image = Image.open("design.png")
# Increase kernel_scale for better edge handling
layerd = LayerD(kernel_scale=0.020) # Default: 0.015
# Increase matting process size
layerd = LayerD(matting_process_size=(1024, 1024))Solution: Adjust max_iterations
layers = layerd.decompose(image, max_iterations=5) # More layers
layers = layerd.decompose(image, max_iterations=2) # Fewer layersSolutions:
# Use GPU
layerd = layerd.to("cuda")
# Reduce process size
layerd = LayerD(matting_process_size=(512, 512))
# Reduce iterations
layers = layerd.decompose(image, max_iterations=2)Solutions:
# Verify file is valid
file your_image.png
# Try with OpenCV
python -c "import cv2; img = cv2.imread('image.png'); print(img.shape)"
# Check permissions and re-download if neededSolutions:
# Reduce learning rate
uv run python ./tools/train.py ... learning_rate=5e-5
# Use mixed precision with bf16
uv run python ./tools/train.py ... mixed_precision=bf16
# Check dataset for corrupted imagesSolutions:
# Use multiple GPUs
CUDA_VISIBLE_DEVICES=0,1 uv run torchrun --standalone --nproc_per_node 2 \
./tools/train.py ... dist=true
# Use mixed precision
uv run python ./tools/train.py ... mixed_precision=bf16
# Increase data loading workers
uv run python ./tools/train.py ... num_workers=8Solutions:
- Check internet connection (downloads ~20GB)
- Ensure sufficient disk space (~100GB)
- Verify HuggingFace access:
python -c "from datasets import load_dataset; load_dataset('cyberagent/crello')"
Solutions:
# Verify dist=true is set
uv run torchrun ... dist=true
# Check GPU visibility
echo $CUDA_VISIBLE_DEVICES
CUDA_VISIBLE_DEVICES=0,1,2,3 uv run torchrun --nproc_per_node 4 ...
# Verify nproc_per_node matches GPU countThis is expected. LayersEditDist handles different layer counts automatically.
Solutions:
# Evaluate subset first
samples = list(pred_dir.iterdir())[:100]
# Use multiprocessing (modify evaluation script)
# Use smaller images if pixel-perfect accuracy not neededSolutions:
- Check layer ordering (background should be first)
- Verify alpha quality:
compute_alpha_iou(layer_pred, layer_gt)should be > 0.8 - Check for extra/missing layers
Problem: Generated SVG files are very large (100MB+)
Solutions:
# Use external image mode instead of base64 embedding
from layerd import LayerDPipeline
pipeline = LayerDPipeline()
result = pipeline(image)
result.save("output.svg", image_mode="external", image_dir="./images")Additional tips:
- Reduce layer count with higher matting threshold
- Use fewer iterations:
pipeline(image, max_iterations=2) - Consider PSD format for large designs
Problem: Adobe Photoshop shows "Not a valid Photoshop document" error
Solutions:
# Try different compression method
result.save("output.psd", compression="rle") # Default
# or
result.save("output.psd", compression="zip")
# Verify color mode compatibility
result.save("output.psd", color_depth=8) # Try 8-bit instead of 16/32Common causes:
- Corrupted file during write (check disk space)
- Very large files (>2GB) may have compatibility issues
- Some Photoshop versions have stricter validation
Problem: PSD export raises import error
Solution: Install LayerD with PSD support:
pip install "git+https://github.com/CyberAgentAILab/LayerD.git#egg=layerd[psd]"Problem: SVG shows empty boxes or missing images
Solutions:
# For external mode, verify image directory exists
result.save("output.svg", image_mode="external", image_dir="./images")
# Check that images/ directory was created
# Images should be in: ./images/element_0.png, ./images/element_1.png, etc.
# Or use base64 mode for self-contained SVG
result.save("output.svg", image_mode="base64")Problem: Text detected as image, or vice versa
Solutions:
# Use custom labeler with adjusted threshold
from layerd import LayerDPipeline, EntropyLabeler
labeler = EntropyLabeler(entropy_threshold=4.0) # Default: 5.0
pipeline = LayerDPipeline(labeler=labeler)
result = pipeline(image)
# Or use gradient-aware labeler
from layerd import GradientAwareLabeler
pipeline = LayerDPipeline(labeler=GradientAwareLabeler())See Pipeline Guide - Element Classification for details.
ModuleNotFoundError: No module named 'layerd'Solutions:
# Verify installation
pip list | grep layerd
# Reinstall
pip uninstall layerd && pip install git+https://github.com/CyberAgentAILab/LayerD.git
# Check environment
which python
# For development
cd LayerD && uv sync --all-extrasLayerD requires strict type annotations:
# Bad
def process(image):
...
# Good
def process(image: Image.Image) -> list[Image.Image]:
...See development.md for details.
Solutions:
# Check permissions
ls -la /path/to/file
# Make writable
chmod +w /path/to/output
# Don't run as rootIf you can't resolve your issue:
- Check GitHub issues
- Create new issue with: LayerD version, Python version, OS, full traceback, minimal example
- Read the paper for methodology details
- Check related docs: Installation, Inference, Training, Development