Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback fixes #58

Merged
merged 27 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7007cb9
Update plugin_convert.py
C-Achard Nov 15, 2023
d73ed02
Update plugin_convert.py
C-Achard Nov 16, 2023
fe28b45
Update plugin_convert.py
C-Achard Nov 16, 2023
7a4646a
Update napari_cellseg3d_m1.yml
C-Achard Nov 16, 2023
0569a64
Fix memory allocation issue
C-Achard Nov 16, 2023
463c569
Add debug info to stats
C-Achard Nov 16, 2023
e001acb
Add mini-stats test
C-Achard Nov 16, 2023
fc73e5b
TEMP Comment out image stats
C-Achard Nov 16, 2023
4edc20d
Revert "TEMP Comment out image stats"
C-Achard Nov 16, 2023
7264abd
Disable image deletion
C-Achard Nov 16, 2023
22dbf56
Disable sphericity
C-Achard Nov 16, 2023
e567b22
Add sphericity
C-Achard Nov 16, 2023
e478bee
Add *.tiff as valid path everywhere
C-Achard Nov 21, 2023
62b76c8
Fix tests and tif+tiff loading
C-Achard Nov 21, 2023
7a24794
Fix several test issues and inconsistencies
C-Achard Nov 21, 2023
9d896b8
Update .gitignore
C-Achard Nov 21, 2023
3b1cd8d
Move pydensecrf back to main repo
C-Achard Nov 21, 2023
7adc683
Update worker_inference.py
C-Achard Nov 22, 2023
5d5b0a3
Update worker_inference.py
C-Achard Nov 22, 2023
0b03fe7
Update worker_inference.py
C-Achard Nov 22, 2023
b824bfb
Reduce warning spam in stats
C-Achard Nov 22, 2023
c6f6d6a
Update instance_segmentation.py
C-Achard Nov 22, 2023
f2f4b52
Update utils.py
C-Achard Nov 22, 2023
29894c5
Update instance_segmentation.py
C-Achard Nov 22, 2023
7064d95
Fix attr error in inference
C-Achard Nov 25, 2023
9e7d1ab
Add artifact removal (#60)
C-Achard Dec 5, 2023
254d7fd
macOS Silicon install (#59)
C-Achard Dec 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install setuptools tox tox-gh-actions
# pip install git+https://github.com/kodalli/pydensecrf.git@master#egg=pydensecrf
# pip install git+https://github.com/lucasb-eyer/pydensecrf.git@master#egg=pydensecrf

# this runs the platform-specific tests declared in tox.ini
- name: Test with tox
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ notebooks/instance_test.ipynb
*.prof
/docs/_build/
/docs/source/code/_autosummary/*.rst
cov.syspath.txt
napari_cellseg3d/dev_scripts/wandb

#include test data
!napari_cellseg3d/_tests/res/test.tif
Expand All @@ -123,9 +125,7 @@ notebooks/instance_test.ipynb
!napari_cellseg3d/_tests/res/wnet_test/*.tif
!napari_cellseg3d/_tests/res/wnet_test/lab/*.tif
!napari_cellseg3d/_tests/res/wnet_test/vol/*.tif
cov.syspath.txt

#include docs images
!docs/source/logo/*
!docs/source/images/*
napari_cellseg3d/dev_scripts/wandb
61 changes: 30 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# napari-cellseg3D: a napari plug-in for direct 3D cell segmentation with deep learning


<img src="https://images.squarespace-cdn.com/content/v1/57f6d51c9f74566f55ecf271/838605d0-9723-4e43-83cd-6dbfe4adf36b/cellseg-logo.png?format=1500w" title="cellseg3d" alt="cellseg3d logo" width="350" align="right" vspace = "80"/>

<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
Expand All @@ -10,23 +9,34 @@
[![codecov](https://codecov.io/gh/AdaptiveMotorControlLab/CellSeg3d/branch/main/graph/badge.svg?token=hzUcn3XN8F)](https://codecov.io/gh/AdaptiveMotorControlLab/CellSeg3d)
[![napari hub](https://img.shields.io/endpoint?url=https://api.napari-hub.org/shields/napari-cellseg3d)](https://www.napari-hub.org/plugins/napari-cellseg3d)


A napari plugin for 3D cell segmentation: training, inference, and data review. In particular, this project was developed for analysis of mesoSPIM-acquired (cleared tissue + lightsheet) datasets.

**Help us make the code better by reporting issues and adding your feature requests!**

----------------------------------

## News

*April 2023: New version with interface overhaul published ! New model and utilities coming soon*
**New version : v1.0**

Added :

**This is an alpha version, please expect bugs and issues, and help us make the code better by reporting them as an issue!**
- Improved training interface
- Unsupervised model : WNet
- Generate labels directly from raw data !
- Can be trained in napari directly or in Colab
- Pretrained weights for mesoSPIM whole-brain cell segmentation
- WandB support (install wandb and login to use automatically when training)
- Remade and improved documentation
- Moved to Jupyter Book
- Dedicated installation page, and working ARM64 install for macOS Silicon users
- New utilities
- Many small improvements and many bug fixes

## Demo

![demo](https://images.squarespace-cdn.com/content/v1/57f6d51c9f74566f55ecf271/0d16a71b-3ff2-477a-9d83-18d96cb1ce28/full_demo.gif?format=500w)


## Installation

**Note** : we recommend using conda to create a new environment for the plugin.
Expand Down Expand Up @@ -58,14 +68,15 @@ To avoid issues when installing on the ARM64 architecture, please follow these s
conda env create -f conda/napari_cellseg3d_m1.yml
conda activate napari_cellseg3d_m1

2) Then install PyQt5 from conda separately :
2) Install the plugin.
From repository root folder, run :

conda install -c anaconda pyqt

3) And install the plugin :
pip install -e .
OR directly via PyPi :

pip install napari-cellseg3d

OR directly via [napari-hub] (see Installation section above)

## Documentation

Expand All @@ -86,21 +97,21 @@ Then go into Plugins > napari-cellseg3d, and choose which tool to use.
- **Train**: This module allows you to train segmentation algorithms from labeled volumes.
- **Utilities**: This module allows you to perform several actions like cropping your volumes and labels dynamically, by selecting a fixed size volume and moving it around the image; computing prediction scores from ground truth and predicition labels; or converting labels from instance to segmentation and the opposite.


## Requirements
**Python >= 3.8 required**

Requires **pytorch** and **MONAI**.
For PyTorch, please see [PyTorch's website for installation instructions].
**Python 3.8 or 3.9 required.**
Requires **[napari]**, **[PyTorch]** and **[MONAI]**.

For PyTorch, please see [the PyTorch website for installation instructions].

A CUDA-capable GPU is not needed but very strongly recommended, especially for training.
If you get errors from MONAI regarding missing readers, please see [MONAI's optional dependencies] page for instructions on getting the readers required by your images.

If you get errors from MONAI regarding missing readers, please see [MONAI's optional dependencies] page for instructions on getting the readers required by your images.

## Issues

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


## Testing

To run tests locally:
Expand Down Expand Up @@ -134,20 +145,15 @@ Distributed under the terms of the [MIT] license.
[Cookiecutter]: https://github.com/audreyr/cookiecutter
[@napari]: https://github.com/napari
[MIT]: http://opensource.org/licenses/MIT
[BSD-3]: http://opensource.org/licenses/BSD-3-Clause
[GNU GPL v3.0]: http://www.gnu.org/licenses/gpl-3.0.txt
[GNU LGPL v3.0]: http://www.gnu.org/licenses/lgpl-3.0.txt
[Apache Software License 2.0]: http://www.apache.org/licenses/LICENSE-2.0
[Mozilla Public License 2.0]: https://www.mozilla.org/media/MPL/2.0/index.txt
[cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin

[napari]: https://github.com/napari/napari
[tox]: https://tox.readthedocs.io/en/latest/
[pip]: https://pypi.org/project/pip/
[PyPI]: https://pypi.org/

[PyTorch's website for installation instructions]: https://pytorch.org/get-started/locally/
[the PyTorch website for installation instructions]: https://pytorch.org/get-started/locally/
[PyTorch]: https://pytorch.org/get-started/locally/
[MONAI's optional dependencies]: https://docs.monai.io/en/stable/installation.html#installing-the-recommended-dependencies
[MONAI]: https://docs.monai.io/en/stable/installation.html#installing-the-recommended-dependencies

## Acknowledgements

Expand All @@ -156,12 +162,5 @@ This work was funded, in part, from the Wyss Center to the [Mathis Laboratory of
Please refer to the documentation for full acknowledgements.

## Plugin base
This [napari] plugin was generated with [Cookiecutter] using [@napari]'s [cookiecutter-napari-plugin] template.

<!--
Don't miss the full getting started guide to set up your new package:
https://github.com/napari/cookiecutter-napari-plugin#getting-started

and review the napari docs for plugin developers:
https://napari.org/plugins/stable/index.html
-->
This [napari] plugin was generated with [Cookiecutter] using [@napari]'s [cookiecutter-napari-plugin] template.
8 changes: 5 additions & 3 deletions conda/napari_cellseg3d_m1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ channels:
- conda-forge
- defaults
dependencies:
- python=3.8
- python=3.9
- pip
- pyqt
- imagecodecs
- pip:
- numpy
- napari>=0.4.14
- QtPy
- opencv-python>=4.5.5
- scikit-image>=0.19.2
- matplotlib>=3.4.1
- tifffile>=2022.2.9
- imageio-ffmpeg>=0.4.5
- torch>=1.11
- monai>=0.9.0
- monai[nibabel, einops]>=0.9.0
- tqdm
- nibabel
- scikit-image
- pillow
- pyclesperanto-prototype
- tqdm
- matplotlib
- vispy>=0.9.6
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ logo: source/logo/logo_alpha.png
# Force re-execution of notebooks on each build.
# See https://jupyterbook.org/content/execute.html
execute:
execute_notebooks: force
execute_notebooks: 'off'

# Define the name of the latex output file for PDF builds
latex:
Expand Down
9 changes: 5 additions & 4 deletions docs/source/guides/installation_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ In the terminal, navigate to the CellSeg3D folder:

.. code-block::

cd CellSeg3D
conda env create -f conda/napari_cellseg3d_m1.yml

3. **Activate the environment** :
Expand All @@ -98,14 +99,14 @@ In the terminal, navigate to the CellSeg3D folder:

conda activate napari_cellseg3d_m1

4. **Install PyQt5 via conda** :
4. **Install the plugin** :

.. code-block::

conda install -c anaconda pyqt
pip install napari-cellseg3d

5. **Install the plugin** :
OR to install from source:

.. code-block::

pip install napari-cellseg3d
pip install -e .
10 changes: 5 additions & 5 deletions docs/welcome.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ Use CellSeg3D to:
* Review labeled cell volumes from whole-brain samples of mice imaged by mesoSPIM microscopy [1]_
* Train and use segmentation models from the MONAI project [2]_ or implement your own custom 3D segmentation models using PyTorch.

No labeled data? Try our unsupervised model to automate your data labelling.
No labeled data? Try our unsupervised model, based on the `WNet`_ model, to automate your data labelling.

The models provided should be adaptable to other tasks related to detection of 3D objects,
outside of whole-brain light-sheet microscopy.
This applies to the unsupervised model as well, feel free to try to generate labels for your own data!

.. figure:: https://images.squarespace-cdn.com/content/v1/57f6d51c9f74566f55ecf271/0d16a71b-3ff2-477a-9d83-18d96cb1ce28/full_demo.gif?format=500w
:alt: CellSeg3D demo
Expand Down Expand Up @@ -52,6 +53,7 @@ you need further assistance, please see below.
Installation
--------------------------------------------
CellSeg3D can be run on Windows, Linux, or MacOS.

For detailed installation instructions, including installing pre-requisites,
please see :ref:`source/guides/installation_guide:Installation guide ⚙`

Expand All @@ -72,8 +74,6 @@ For local installation after cloning from GitHub, please run the following in th

If the installation was successful, you will find the napari-cellseg3D plugin in the Plugins section of napari.



Usage
--------------------------------------------

Expand Down Expand Up @@ -160,7 +160,7 @@ This plugin mainly uses the following libraries and software:

* `pyclEsperanto`_ (for the Voronoi Otsu labeling) by Robert Haase

* A custom re-implementation of the `WNet model`_ by Xia and Kulis [3]_
* A custom re-implementation of the `WNet`_ by Xia and Kulis [3]_

.. _Mathis Laboratory of Adaptive Motor Control: http://www.mackenziemathislab.org/
.. _Wyss Center: https://wysscenter.ch/
Expand All @@ -170,7 +170,7 @@ This plugin mainly uses the following libraries and software:
.. _MONAI project: https://monai.io/
.. _on their website: https://docs.monai.io/en/stable/networks.html#nets
.. _pyclEsperanto: https://github.com/clEsperanto/pyclesperanto_prototype
.. _WNet model: https://arxiv.org/abs/1711.08506
.. _WNet: https://arxiv.org/abs/1711.08506

.. rubric:: References

Expand Down
Binary file modified napari_cellseg3d/_tests/res/test.tif
Binary file not shown.
Binary file modified napari_cellseg3d/_tests/res/wnet_test/lab/test.tif
Binary file not shown.
Binary file modified napari_cellseg3d/_tests/res/wnet_test/test.tif
Binary file not shown.
Binary file modified napari_cellseg3d/_tests/res/wnet_test/vol/test.tif
Binary file not shown.
11 changes: 7 additions & 4 deletions napari_cellseg3d/_tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,18 @@ def __call__(self, x):
post_process_transforms=mock_work(),
)
assert isinstance(res, InferenceResult)
assert res.result is not None
assert res.semantic_segmentation is not None


def test_post_processing():
config = InferenceWorkerConfig()
worker = InferenceWorker(worker_config=config)

image = rand_gen.random((1, 1, 64, 64, 64))
labels = rand_gen.random((1, 2, 64, 64, 64))
mock_layer = napari.layers.Image(data=image)
mock_layer.name = "test"

config = InferenceWorkerConfig()
config.layer = mock_layer
worker = InferenceWorker(worker_config=config)

results = worker.run_crf(image, labels, lambda x: x)
assert results.shape == (2, 64, 64, 64)
Expand Down
12 changes: 6 additions & 6 deletions napari_cellseg3d/_tests/test_plugin_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ def test_inference(make_napari_viewer_proxy, qtbot):

assert len(viewer.layers) == 1

widget.window_infer_box.setChecked(True)
widget.use_window_choice.setChecked(True)
widget.window_overlap_slider.setValue(0)
widget.keep_data_on_cpu_box.setChecked(True)

assert widget.check_ready()

widget.model_choice.setCurrentText("WNet")
widget._restrict_window_size_for_model()
assert widget.window_infer_box.isChecked()
assert widget.use_window_choice.isChecked()
assert widget.window_size_choice.currentText() == "64"

test_model_name = "test"
MODEL_LIST[test_model_name] = TestModel
widget.model_choice.addItem(test_model_name)
widget.model_choice.setCurrentText(test_model_name)

widget.window_infer_box.setChecked(False)
widget.use_window_choice.setChecked(False)
widget.worker_config = widget._set_worker_config()
assert widget.worker_config is not None
assert widget.model_info is not None
Expand All @@ -50,7 +50,7 @@ def test_inference(make_napari_viewer_proxy, qtbot):
assert worker.config is not None
assert worker.config.model_info is not None
assert worker.config.sliding_window_config.is_enabled() is False
worker.config.layer = viewer.layers[0].data
worker.config.layer = viewer.layers[0]
worker.config.post_process_config.instance.enabled = True
worker.config.post_process_config.instance.method = (
INSTANCE_SEGMENTATION_METHOD_LIST["Watershed"]()
Expand All @@ -61,7 +61,7 @@ def test_inference(make_napari_viewer_proxy, qtbot):

res = next(worker.inference())
assert isinstance(res, InferenceResult)
assert res.result.shape == (8, 8, 8)
assert res.semantic_segmentation.shape == (8, 8, 8)
assert res.instance_labels.shape == (8, 8, 8)
widget.on_yield(res)

Expand All @@ -73,7 +73,7 @@ def test_inference(make_napari_viewer_proxy, qtbot):
instance_labels=mock_labels,
crf_results=mock_image,
stats=[volume_stats(mock_labels)],
result=mock_image,
semantic_segmentation=mock_image,
model_name="test",
)
num_layers = len(viewer.layers)
Expand Down
2 changes: 1 addition & 1 deletion napari_cellseg3d/_tests/test_plugin_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_worker_configs(make_napari_viewer_proxy):
worker.config, attr
)
widget.unsupervised_images_filewidget.text_field.setText(
str(im_path.parent)
str((im_path.parent / "wnet_test").resolve())
)
widget.data = widget.create_dataset_dict_no_labs()
worker = widget._create_worker(additional_results_description="TEST_2")
Expand Down
13 changes: 13 additions & 0 deletions napari_cellseg3d/_tests/test_plugin_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np

from napari_cellseg3d.code_plugins.plugin_convert import StatsUtils
from napari_cellseg3d.code_plugins.plugin_crop import Cropping
from napari_cellseg3d.code_plugins.plugin_utilities import (
UTILITIES_WIDGETS,
Expand Down Expand Up @@ -57,3 +58,15 @@ def test_crop_widget(make_napari_viewer_proxy):
widget.sliders[2].setValue(2)

widget._start()


def test_stats_plugin(make_napari_viewer_proxy):
view = make_napari_viewer_proxy()
widget = StatsUtils(view)

labels = rand_gen.random((10, 10, 10)).astype(np.uint8)
view.add_labels(labels, name="labels")

view.window.add_dock_widget(widget)
widget.csv_name.setText("test.csv")
widget._start()
3 changes: 2 additions & 1 deletion napari_cellseg3d/_tests/test_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ def test_launch_review(make_napari_viewer_proxy):
# widget.filetype_choice.setCurrentIndex(0)

im_path = str(Path(__file__).resolve().parent / "res/test.tif")
lab_path = str(Path(__file__).resolve().parent / "res/test_labels.tif")

widget.folder_choice.setChecked(True)
widget.image_filewidget.text_field = im_path
widget.labels_filewidget.text_field = im_path
widget.labels_filewidget.text_field = lab_path
widget.results_filewidget.text_field = str(
Path(__file__).resolve().parent / "res"
)
Expand Down
Loading