Skip to main content

PyTorch-only StarDist 2D inference for Keras H5 StarDist weights.

Project description

cistardist_pytorch

PyTorch-only StarDist 2D inference for existing TensorFlow/Keras StarDist .h5 weights. The first target model is models/SD_Nuclei_Versatile.

This repo intentionally does not depend on TensorFlow, Keras, CSBDeep, or the upstream stardist Python package.

Install

The package is published on PyPI: https://pypi.org/project/cistardist-pytorch/

Install the library with:

pip install cistardist-pytorch

PyTorch is intentionally not pinned by the package, so you can choose the CPU or CUDA build that matches your environment. For this repo's CUDA 12.6 setup, use:

conda create -n cistardist_pytorch python=3.10
conda activate cistardist_pytorch
pip install -r requirements.txt
pip install -e . --no-deps

The package includes a compiled StarDist-style C++ NMS extension for fast polygon suppression. When building from source, a C++ compiler is needed to compile it; if the extension is not available, inference automatically falls back to the slower pure-Python NMS implementation. See COMPILE_NMS.md for detailed build instructions.

Convert and Predict

cistardist-convert models/SD_Nuclei_Versatile
cistardist-predict models/SD_Nuclei_Versatile data/nuclei.tif --out outputs/nuclei_labels.tif

The converter reads config.json, thresholds.json, and weights_best.h5. It writes a PyTorch checkpoint next to the source model as weights_best.pt.

Python API

import tifffile
from cistardist_pytorch import StarDist2D

model = StarDist2D.from_folder("models/SD_Nuclei_Versatile")
image = tifffile.imread("data/nuclei.tif")
labels, details = model.predict_instances(image)

Current Scope

  • 2D grayscale inference
  • Keras .h5 Conv2D weight conversion via h5py
  • StarDist-style polygon postprocessing with compiled C++ NMS and vendored BSD-compatible 2D geometry
  • No training, no TensorFlow reference tests, no 3D, no multiclass models

Attribution

The 2D geometry and NMS behavior follows the BSD-3-Clause upstream StarDist project: https://github.com/stardist/stardist

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cistardist_pytorch-0.3.0.tar.gz (68.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cistardist_pytorch-0.3.0-cp311-cp311-win_amd64.whl (112.6 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file cistardist_pytorch-0.3.0.tar.gz.

File metadata

  • Download URL: cistardist_pytorch-0.3.0.tar.gz
  • Upload date:
  • Size: 68.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for cistardist_pytorch-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f184823d4407adcbd3e2cf2671c6c18722bad1ed36178d41f1ac40835b959f97
MD5 c3d6391d42dbfb20bcce7c94d77ac9e7
BLAKE2b-256 fd1ab9060bea384a6fca79756ff00fc8b9a23ac50c1b9d513d76d057977cbebb

See more details on using hashes here.

File details

Details for the file cistardist_pytorch-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cistardist_pytorch-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4f651785c19b90b66ae62a8fe613500e48102dda85ae9a4ddb296a3d6a044e6b
MD5 2274057424eea9b405b868a0ceb3e3fb
BLAKE2b-256 3f71aadd5911b8bd0f7d614befff9dc626ed833c90c711b4a539b736c766519d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page