Skip to main content

Semantic Segmention using Deep Learning ONNX models packaged as *.czann files

Project description

napari-czann-segment

License PyPI Python Version napari hub

Semantic Segmentation of multi-dimensional images using Deep Learning ONNX models packaged as *.czann files.


This napari plugin was generated with Cookiecutter using @napari's cookiecutter-napari-plugin template.

Train on APEER and use model in Napari

Installation

Before installing, please setup a conda environment. If you have never worked with conda environments, go through this tutorial first.

You can then install napari-czann-segment via pip:

pip install napari-czann-segment

What does the plugin do

The plugin allows you to:

  • Use a *.czann file containing the Deep Neural Network (ONNX) for semantic segmentation and metadata
  • Segmentation will be applied per 2D plane for all dimensions
  • Processing larger multi-dimensional images it uses the cztile package to chunk the individual 2d arrays using a specific overlap.
  • multi-dimensional images will be processed plane-by-plane

What does the plugin NOT do

Before one can actually use a model it needs to be trained, which is NOT done by this plugin.

Therer two main ways hwo such a model can be created:

  • Train the segmentation model fully automated on APEER and download the *.czann file
  • Train your model in a Jupyter notebook etc. and package it using the czmodel python package as an *.czann

Using this plugin

Sample Data

A test image and a *.czann model file can be downloaded here.

  • PGC_20X.ome.tiff --> use PGC_20X_nucleus_detector.czann to segment

In order to use this plugin the user has to do the following things:

  • Open the image using "File - Open Files(s)" (requires napari-aicsimageio plugin).
  • Click napari-czann-segment: Segment with CZANN model in the "Plugins" menu.
  • *Select a .czann file to use the model for segmentation.
  • metadata of the model will be shown (see example below)
Parameter Value Explanation
model_type ModelType.SINGLE_CLASS_SEMANTIC_SEGMENTATION see: czmodel for details
input_shape [1024, 1024, 1] tile dimensions of model input
output_shape [1024, 1024, 3] tile dimensions of model output
model_id ba32bc6d-6bc9-4774-8b47-20646c7cb838 unique GUID for that model
min_overlap [128, 128] tile overlap used during training (for this model)
classes ['background', 'grains', 'inclusions'] availbale classes
model_name APEER-trained model name of the model

Napari - Image loaded and czann selected

  • Adjust the minimum overlap for the tiling (optional, see cztile for details).
  • Select the layer to be segmented.
  • Press Segment Selected Image Layer to run the segmentation.

Napari - Image successfully segmented

A successful is obviously only the starting point for further image analysis steps to extract the desired numbers from the segmented image. Another example is shown below demonstrating a simple "Grain Size Analysis" using a deep-learning model trained on APEER used in napari

Napari - Simple Grain Size Analysis

Remarks

IMPORTANT: Currently the plugin only supports using models trained on a single channel image. Therefore make sure that during the training on APEER or somewhere else the correct inputs images are used. It is quite simple to train an single RGB image, which actually has three channels, load this image in napari and notice only then that the model will not work, because the image will 3 channels inside napari.

  • Only the CPU will be used for the inference using the ONNX runtime for the ONNX-CPU runtime
  • GPUs are not supported yet and will require ONNX-GPU runtime

For developers

  • Please clone this repository first using your favorite tool.

  • Ideally one creates a new conda environment or use an existing environment that already contains Napari.

Feel free to create a new environment using the YAML file at your own risk:

cd the-github-repo-with-YAML-file
conda env create --file conda_env_napari_czann_segment.yml
conda activate napari_czmodel
  • Install the plugin locally

Please run the the following command:

pip install -e .

To install latest development version:

pip install git+https://github.com/sebi06/napari_czann_segment.git

Contributing

Contributions and Feedback are very welcome.

License

Distributed under the terms of the BSD-3 license, "napari-czann-segment" is free and open source software

Issues

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

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

napari-czann-segment-0.0.15.tar.gz (10.3 MB view details)

Uploaded Source

Built Distribution

napari_czann_segment-0.0.15-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file napari-czann-segment-0.0.15.tar.gz.

File metadata

  • Download URL: napari-czann-segment-0.0.15.tar.gz
  • Upload date:
  • Size: 10.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for napari-czann-segment-0.0.15.tar.gz
Algorithm Hash digest
SHA256 5f3df6a3376ae9e085fad19e707a8c1fe6eccbce6273f3845ff6f9dc6971d457
MD5 addf6997eaf1fca4634c1152df56ede2
BLAKE2b-256 c860464a68081434b3cd3c4903985d8e4f3baf04ad002041c76cf018dae4f837

See more details on using hashes here.

File details

Details for the file napari_czann_segment-0.0.15-py3-none-any.whl.

File metadata

File hashes

Hashes for napari_czann_segment-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 c71207e925141c3eecaee7f3d4e88b493f8c38e133be70ebdcce67b14db9d3d4
MD5 b7afc8803f9eb8b143564f8044fc89ee
BLAKE2b-256 e89f667e3ee32f6dc13547addad67cf29ae3dc2c5cd9855996cd77f36cf1f713

See more details on using hashes here.

Supported by

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