Skip to main content

gfap-segmenter

License BSD-3 PyPI Python Version tests codecov napari hub npe2 Copier

A Bachelor Thesis project to allow segmentation of astrocytes on GFAP staining using machine learning in napari.


Features

  • Load .tif/.tiff/.czi microscopy data via bioio and display them in napari.
  • Run tiled U-Net inference that produces probability maps and binary masks.
  • Curate training patches with ≥300×300 validation and immediate colour feedback.
  • Synthesize 1000 augmented patches per curated region and train in the background with progress updates.
  • Import/export checkpoints (including ONNX) and optionally bundle curated training data.

Installation

Install gfap-segmenter via pip:

pip install gfap-segmenter

If napari (Qt backend included) is not yet installed, use:

pip install "gfap-segmenter[all]"

GPU support

The plugin automatically uses GPU acceleration when available. GPU support significantly speeds up both model training and inference (typically 10-50x faster than CPU).

Installation

The plugin relies on PyTorch. By default, pip install gfap-segmenter installs the CPU-only version of PyTorch. To enable GPU acceleration, you need a CUDA-enabled PyTorch build.

Important: PyTorch bundles its own CUDA runtime, so you don't need to install the full CUDA toolkit separately. You only need NVIDIA GPU drivers (usually pre-installed on systems with NVIDIA GPUs).

For NVIDIA GPUs (CUDA):

Option 1: Fresh installation (recommended)

  1. Install PyTorch with CUDA support from PyTorch's official installation guide:

    CUDA 11.8:

    pip install torch --index-url https://download.pytorch.org/whl/cu118
    

    CUDA 12.4:

    pip install torch --index-url https://download.pytorch.org/whl/cu124
    

    CUDA 12.8:

    pip install torch --index-url https://download.pytorch.org/whl/cu128
    

    CUDA 13.0:

    pip install torch --index-url https://download.pytorch.org/whl/cu130
    
  2. Then install gfap-segmenter:

    pip install gfap-segmenter
    

Option 2: Upgrade existing CPU-only PyTorch installation

If you already have gfap-segmenter installed with CPU-only PyTorch, you can upgrade to CUDA-enabled PyTorch:

  1. Uninstall the CPU-only PyTorch:

    pip uninstall torch
    
  2. Install CUDA-enabled PyTorch (choose the version matching your driver):

    pip install torch --index-url https://download.pytorch.org/whl/cu121
    
  3. The plugin will automatically use the CUDA-enabled PyTorch - no need to reinstall gfap-segmenter.

Note: You don't need to match the exact CUDA version. PyTorch includes its own CUDA runtime. As long as your NVIDIA driver is compatible (typically driver 11.0+ for CUDA 11.x, or 12.0+ for CUDA 12.x), you can use any recent PyTorch CUDA build. If unsure, use CUDA 12.1.

For Apple Silicon (macOS):

MPS (Metal Performance Shaders) support is automatically available if you have PyTorch 1.12+ installed. No additional steps required - the plugin will automatically use your Apple Silicon GPU.

Verification

To verify that GPU support is enabled:

  1. Check in the plugin UI: The status bar at the bottom of the plugin widget shows the current device (e.g., "Device: CUDA (NVIDIA GeForce RTX 3090)" or "Device: CPU").

  2. Check via Python:

    import torch
    print(f"CUDA available: {torch.cuda.is_available()}")
    if torch.cuda.is_available():
        print(f"CUDA device: {torch.cuda.get_device_name(0)}")
        print(f"CUDA version: {torch.version.cuda}")
    
  3. Check PyTorch CUDA support (command line):

    python -c "import torch; print('CUDA available:', torch.cuda.is_available()); print('CUDA version:', torch.version.cuda if torch.cuda.is_available() else 'N/A')"
    

Checking your NVIDIA driver version (optional, for reference):

  • Using nvidia-smi (if NVIDIA drivers are installed):

    nvidia-smi
    

    Look for the "CUDA Version" line (shows the maximum CUDA version your driver supports).

  • Using nvcc (if CUDA toolkit is installed):

    nvcc --version
    
  • Using PyTorch (after PyTorch is installed):

    python -c "import torch; print(torch.version.cuda)"
    

Troubleshooting

Problem: Plugin shows "Device: CPU" even though you have a GPU

  • PyTorch CPU-only build: You may have installed the CPU-only version of PyTorch. Uninstall and reinstall with CUDA support:

    pip uninstall torch
    pip install torch --index-url https://download.pytorch.org/whl/cu121  # Adjust CUDA version
    
  • CUDA driver mismatch: Your CUDA driver version may not match the PyTorch CUDA version. Check compatibility:

    nvidia-smi  # Shows driver version
    python -c "import torch; print(torch.version.cuda)"  # Shows PyTorch CUDA version
    

    The driver version should be >= the PyTorch CUDA version.

  • CUDA not detected: Ensure your NVIDIA drivers are up to date and CUDA is properly installed.

Problem: "CUDA out of memory" errors

  • Reduce batch size in training or prediction settings
  • Use a smaller patch size
  • Close other GPU-intensive applications

Problem: Training/inference is still slow

  • Verify GPU is actually being used (check status bar or console output)
  • Ensure you installed the correct CUDA version for your GPU
  • Check GPU utilization: nvidia-smi should show high GPU usage during training

Performance Notes

  • The plugin automatically uses GPU for both training and inference when available - no configuration needed. The current device is displayed at the bottom of the plugin.
  • If no GPU is detected, the plugin automatically falls back to CPU execution (slower but functional).

Development version

pip install git+https://github.com/MMV-Lab/gfap-segmenter.git

Usage overview

  1. Prediction tab – load the default checkpoint or import a custom one, choose an image layer, and run inference to create probability and mask layers.
  2. Curate Patches tab – draw rectangles in the dedicated shapes layer. Patches ≥300×300 are tinted blue; smaller ones are red. Add valid regions to the training set.
  3. Train tab – launch background training; progress and logs stream into the widget. Trained models are stored under ~/.gfap_segmenter/models.
  4. Model IO tab – export/import checkpoint bundles. Bundles can optionally include the curated training data for reproducibility.

Contributing

Contributions are very welcome. Tests can be run with tox; please ensure coverage at least stays the same before submitting a pull request.

License

Distributed under the terms of the BSD-3 license, "gfap-segmenter" is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Metadata

Release files for gfap-segmenter 1.0.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 gfap-segmenter 1.0.0
File Size Uploaded
gfap_segmenter-1.0.0.tar.gz 56.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for gfap-segmenter 1.0.0
File Interpreter ABI Platform
gfap_segmenter-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 56.3 MB

Release files / gfap_segmenter-1.0.0.tar.gz

Download URL gfap_segmenter-1.0.0.tar.gz
Size 56.2 MB
Tags Source
SHA-256 checksum
How to use checksums
03e1cb9db91abd07a4be3d30722129320ed32b1490248e2508ee5716c94ef496
BLAKE2b-256 checksum
How to use checksums
9040927c42941b9301356562e721103e8e0038754d27e345711642e6cee783b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 8, 2026.

Transparency log

Release files / gfap_segmenter-1.0.0-py3-none-any.whl

Download URL gfap_segmenter-1.0.0-py3-none-any.whl
Size 35.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb3d66aa65f0be609f9c0e433d26973c1d69fae46cb8256f8cf39cbacfd486fd
BLAKE2b-256 checksum
How to use checksums
c9940133c1df2decdccdb318f4c2f379e9227b71165b8c812f25922a6c4ba467
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

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