Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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 ≥256×256 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 ≥256×256 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.1rc2

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.1rc2
File Size Uploaded Provenance Actions
gfap_segmenter-1.0.1rc2.tar.gz 56.3 MB With provenance Details for gfap_segmenter-1.0.1rc2.tar.gz

Built distribution (wheel)

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

Total release size: 56.3 MB

Release files / gfap_segmenter-1.0.1rc2.tar.gz

Download URL gfap_segmenter-1.0.1rc2.tar.gz
Size 56.3 MB
Tags Source
SHA-256 checksum
How to use checksums
bff494d32b4d19c822be34aab87e46acef1665b3d7af14e8f1a9169a72f17730
BLAKE2b-256 checksum
How to use checksums
6df89a8373055c3e89885795b28abbb883fe021b879e3d60a5cfcee9c4d48632
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 9, 2026.

Transparency log

Release files / gfap_segmenter-1.0.1rc2-py3-none-any.whl

Download URL gfap_segmenter-1.0.1rc2-py3-none-any.whl
Size 40.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
880c5083dace456b23cc73c2e7bbaaff9d6dec204a42ac5a529f5f49cd278e54
BLAKE2b-256 checksum
How to use checksums
a58303b33ea0d98ff0ecd2652d20848b0b392692b330826a275741d12fef89ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 9, 2026.

Transparency log

Security for gfap-segmenter 1.0.1rc2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gfap_segmenter-1.0.1rc2.tar.gz

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 Nov 9, 2026.

Transparency log

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.

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