LION
Fully automated tumor segmentation for FDG and PSMA PET scans
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.10+
- 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.
Using uv (recommended)
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.4 and requires NVIDIA driver 550.54.14 or newer on Linux. The host supplies the NVIDIA driver; it is not installed inside the container.
docker run --rm --gpus all --shm-size=2g \
-v /path/to/data:/shared \
-v lionz-models:/usr/local/models \
lalithshiyam/lionz:1.0.6 \
-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.0.6 \
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_orPT- - CT files are not needed and are ignored by the current segmentation models
- Supports
.niiand.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
Standards-compliant DICOM SEG export
scripts/export_idc_dicom_seg.py converts an existing LION FDG NIfTI mask
back onto its original PET DICOM grid and encodes it as a source-referenced
binary DICOM SEG. This dataset workflow is separate from the normal lionz
inference command because it requires the original PET instances plus pinned
dcmqi and dicom3tools containers.
The LMU Slurm workflow is:
sbatch --wait scripts/lmu/prepare_dicom_seg_tools.sbatch
sbatch --wait --export=ALL,MODE=smoke scripts/lmu/export_idc_dicom_seg.sbatch
sbatch --wait --export=ALL,MODE=full,WORKERS=8 scripts/lmu/export_idc_dicom_seg.sbatch
Every produced object must pass source-UID and coded-metadata checks, zero
dciodvfy/dcentvfy errors, and an exact dcmqi SEG-to-mask round trip. Empty
masks are recorded explicitly and do not produce meaningless empty SEG
objects. The LUNG-PET-CT-Dx export also checks that every SUV>=4 mask is a
subset of its corresponding native mask.
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 metadataread_dicom_header- Read full DICOM tagsorganize_for_lion- Reorganize files into LION structurevalidate_structure- Check if directory is LION-readyget_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.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lionz-1.0.6.tar.gz | 60.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lionz-1.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 112.6 kB
Release files / lionz-1.0.6.tar.gz
| Download URL | lionz-1.0.6.tar.gz |
|---|---|
| Size | 60.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
437655651bc527df0c1dfbc513602726fcc3774739f0ff5c95006070e7b7e95a
|
|
BLAKE2b-256 checksum How to use checksums |
624196d049500879907958c128a1d77f8cfb1c384aa047006cfaf94d58ec3736
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / lionz-1.0.6-py3-none-any.whl
| Download URL | lionz-1.0.6-py3-none-any.whl |
|---|---|
| Size | 52.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
030fcb62478cee7731d1272fb5c522e0a20a256745d8d0fd8edf9299a92b1fcb
|
|
BLAKE2b-256 checksum How to use checksums |
498fc27f605fac65b370a69b99ad51bce362029c1fe003623fde8ce97014480f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|