Skip to main content
LION

LION

Fully automated tumor segmentation for FDG and PSMA PET scans

PyPI DOI Python License Downloads Monthly

Quick Start

python -m venv lion-env
source lion-env/bin/activate        # macOS / Linux
lion-env\Scripts\activate           # Windows

pip install lionz
lionz -d /path/to/data -m fdg

That's it. Models download automatically on first run.

Requirements

  • Python 3.11+
  • 32GB RAM recommended
  • GPU optional (NVIDIA CUDA or Apple Silicon MPS) - CPU works but slower

Installation

We recommend installing LION in a virtual environment to avoid dependency conflicts.

uv is a fast Python package manager that handles virtual environments automatically.

# Install uv if you don't have it
curl -LsSf https://astral.sh/uv/install.sh | sh   # macOS/Linux
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"  # Windows

Install from PyPI:

uv venv lion-env
# Activate the environment
source lion-env/bin/activate        # macOS / Linux
lion-env\Scripts\activate           # Windows
uv pip install lionz

Install from source:

git clone https://github.com/ENHANCE-PET/LION.git
cd LION
uv sync

Using pip + venv

python -m venv lion-env
# Activate the environment
source lion-env/bin/activate        # macOS / Linux
lion-env\Scripts\activate           # Windows
python -m pip install lionz

Docker with NVIDIA GPUs

The LION Docker image targets CUDA 12.6. Use NVIDIA driver 560.28.03 or newer on Linux as the full CUDA 12.6 baseline. The host supplies the NVIDIA driver; it is not installed inside the container. Locked uv installations on Linux and Windows use the official PyTorch CUDA 12.6 index. Plain pip install lionz uses PyPI's Torch build, which currently targets CUDA 13.0 on Linux and needs a compatible 580-series driver. To select CUDA 12.6 with pip, install the matching runtime first:

python -m pip install "torch==2.13.0" "torchvision==0.28.0" --index-url https://download.pytorch.org/whl/cu126
python -m pip install "lionz==1.1.0"

CUDA 12.6's driver guidance is in the NVIDIA release notes. The official PyTorch installation matrix lists this patched CUDA 12.6 runtime. GPU inference must be validated on the target hardware before promoting a Docker candidate. NVIDIA also documents limited CUDA 12.x minor-version compatibility on older drivers; this is not the validated LION deployment baseline.

When upgrading an existing model cache, run once with a writable model volume so LION can fetch and verify the pinned archive. The updated cache can then be mounted read-only. Failed verification or installation preserves the previous cache and raises an error.

docker run --rm --gpus all --shm-size=2g \
  -v /path/to/data:/shared \
  -v lionz-models:/usr/local/models \
  lalithshiyam/lionz:1.1.0 \
  -d /shared -m psma

LION stores downloaded models under /usr/local/models/nnunet_trained_models, so the model volume persists across container runs.

On a Slurm cluster with Singularity:

singularity exec --nv \
  --bind /path/to/data:/shared \
  --bind /path/to/models:/usr/local/models \
  docker://lalithshiyam/lionz:1.1.0 \
  lionz -d /shared -m psma

Input Data Structure

LION runs on PET input only. CT is not required for the current FDG and PSMA models.

data/
├── patient_001/
│   └── PT_scan.nii.gz      # PET file with PT_ or PT- prefix
├── patient_002/
│   └── PT_scan.nii.gz
└── patient_003/
    └── PT_scan.nii.gz

Rules:

  • One folder per subject
  • PET files must start with PT_ or PT-
  • CT files are not needed and are ignored by the current segmentation models
  • Supports .nii and .nii.gz
  • PET DICOM folders are also supported; modality is auto-detected from tags

Messy Data?

Use the lion-mcp server with Claude Code or Codex to organize chaotic DICOM/NIfTI dumps. See lion-mcp/README.md.

CLI Usage

# Basic
lionz -d /path/to/data -m fdg

# With SUV threshold
lionz -d /path/to/data -m fdg -t 2.5

# Generate MIP preview
lionz -d /path/to/data -m fdg -g

# Parallel processing (multiple subjects)
lionz -d /path/to/data -m fdg -p 4

# All options
lionz -d /path/to/data -m fdg -t 2.5 -g -p 4

Options:

Flag Description
-d Input directory containing subject folders
-m Model name: fdg or psma
-t SUV threshold (requires SUV-calibrated input)
-g Generate rotational MIP GIF
-p Number of parallel jobs
-h Show help

Library Usage

import lionz

# From file path
result = lionz.lion('/path/to/PT_scan.nii.gz', 'fdg')

# From SimpleITK image
import SimpleITK as sitk
img = sitk.ReadImage('/path/to/PT_scan.nii.gz')
seg = lionz.lion(img, 'fdg')  # Returns SimpleITK.Image

# From numpy array
import numpy as np
array = np.load('pet_data.npy')
spacing = (2.0, 2.0, 2.0)
seg = lionz.lion((array, spacing), 'fdg')  # Returns np.ndarray

# With options
result = lionz.lion(
    '/path/to/PT_scan.nii.gz',
    'fdg',
    output_dir='/path/to/output',
    accelerator='mps',  # 'cpu', 'cuda', or 'mps'
    threshold=2.5
)

Important: Wrap in if __name__ == '__main__': to avoid multiprocessing issues:

import lionz

if __name__ == '__main__':
    lionz.lion('/path/to/PT_scan.nii.gz', 'fdg')

Models

Tracer Model Training Data Status
FDG fdg 5,235 patients Stable
PSMA psma 2,046 patients Stable

Output Structure

patient_001/
├── PT_scan.nii.gz                    # Original PET input
└── lionz-2024-01-15-10-30-00/
    ├── segmentations/
    │   ├── PT_scan_tumor_seg.nii.gz  # Tumor mask
    │   └── patient_001_rotational_mip.gif  # If -g flag used
    └── stats/
        └── patient_001_metrics.csv   # Volume, SUV metrics

Platform Support

Platform Accelerator Status
Linux CUDA Fully supported
Linux CPU Supported (slower)
macOS (Apple Silicon) MPS Fully supported
macOS (Intel) CPU Supported (slower)
Windows CUDA Fully supported
Windows CPU Supported (slower)

For AI Agents

LION provides an MCP server for organizing messy medical imaging data. Install and configure:

cd lion-mcp && pip install -e .

Add to .mcp.json:

{
  "lion-mcp": {
    "type": "stdio",
    "command": ".venv/bin/lion-mcp"
  }
}

Available MCP tools:

  • scan_directory - Scan for DICOM/NIfTI files, extract metadata
  • read_dicom_header - Read full DICOM tags
  • organize_for_lion - Reorganize files into LION structure
  • validate_structure - Check if directory is LION-ready
  • get_lion_requirements - Get structure documentation

Telemetry

LION collects anonymous usage statistics to help us understand how the tool is used and prioritize development. This is completely optional.

What we collect: version, model used, platform, accelerator type, number of subjects, success/failure

What we DON'T collect: file paths, patient data, IP addresses, any identifiable information

Opt-out:

export LIONZ_TELEMETRY=0

Citation

DOI: 10.5281/zenodo.12626789

License

Apache 2.0.

Contributors

Part of the ENHANCE.PET initiative.

Metadata

Release files for lionz 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lionz 1.1.0
File Size Uploaded Provenance Actions
lionz-1.1.0.tar.gz 65.1 kB Without provenance Details for lionz-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lionz 1.1.0
File Interpreter ABI Platform Actions
lionz-1.1.0-py3-none-any.whl Python 3 none any Details for lionz-1.1.0-py3-none-any.whl

Total release size: 118.7 kB

Release files / lionz-1.1.0.tar.gz

Download URL lionz-1.1.0.tar.gz
Size 65.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c2f46d5087fce17b8061068ae81b80f15ddce004d5ba17ddfc6491cc8c63532c
BLAKE2b-256 checksum
How to use checksums
88b6bb45ea0ac4e7eecca9346f37106a6067add9151a533e0e59a61b500f7b71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / lionz-1.1.0-py3-none-any.whl

Download URL lionz-1.1.0-py3-none-any.whl
Size 53.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bc2cd235acdf2abdb67c1b5c43ca30621969162af9e834cc6ffa80cfc65f3c1
BLAKE2b-256 checksum
How to use checksums
ca016f2643944d49c26a624c04c5f21009c6d8f8d0cf1a3b3905f92f9ca41ebc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for lionz 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page