From a8cc5d2377bdf66ae259fe1c0a6e0fa86c1cad6c Mon Sep 17 00:00:00 2001 From: Shalin Mehta Date: Thu, 10 Aug 2023 12:55:29 -0700 Subject: [PATCH 1/5] readme + dependencies tested with python 3.10 --- README.md | 41 +++++++++++++---------------------------- pyproject.toml | 1 + 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 6a301208..a039e119 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,25 @@ viscy is a deep learning pipeline for training and deploying computer vision models for image-based phenotyping at single cell resolution. -The current focus of the pipeline is on the image translation models for virtual staining of multiple cellular compartments from label-free images. We are building these models for simultaneous segmentation of nuclei and membrane, which are the first steps in a single-cell phenotyping pipeline. Our pipeline also provides utilities to export the models to onnx format for use at runtime. We will grow the collection of the models suitable for high-throughput imaging and phenotyping. +The current focus of the pipeline is on the image translation models for virtual staining of multiple cellular compartments from label-free images. We are building these models for simultaneous segmentation of nuclei and membrane, which are the first steps in a single-cell phenotyping pipeline. Our pipeline also provides utilities to export the models to onnx format for use at runtime. We will grow the collection of the models suitable for high-throughput imaging and phenotyping. Expect rough edges until we release a pypi package. ![virtual_staining](docs/figures/phase_to_nuclei_membrane.svg) This pipeline evolved from the [TensorFlow version of virtual staining pipeline](https://github.com/mehta-lab/microDL), which we reported in [this paper in 2020](https://elifesciences.org/articles/55502). The previous pipeline is now a public archive, and we will be focusing our efforts on viscy. -## Installation +## Installing viscy -(Optional) create a new virtual/Conda environment. +1. We highly encourage you to create a new Conda environment. We prefer using mamba, but conda will work just as well. -Clone this repository and install viscy: +```sh + mamba create -n viscy python=3.10 + + OR + + mamba create -p /viscy python=3.10 +``` + +2. Clone this repository and install viscy: ```sh git clone https://github.com/mehta-lab/viscy.git @@ -20,7 +28,7 @@ cd viscy pip install . ``` -Verify installation by accessing the CLI help message: +3. Verify installation by accessing the CLI help message: ```sh viscy --help @@ -34,29 +42,6 @@ The full functionality is tested only on Linux `x86_64` with NVIDIA Ampere GPUs Some features (e.g. mixed precision and distributed training) may not work with other setups, see [PyTorch documentation](https://pytorch.org) for details. -Following dependencies will allow use and development of the pipeline, while the pypi package is pending: - -``` -iohub==0.1.0.dev3 -torch>=2.0.0 -torchvision>=0.15.1 -tensorboard>=2.13.0 -lightning>=2.0.1 -monai>=1.2.0 -jsonargparse[signatures]>=4.20.1 -scikit-image>=0.19.2 -matplotlib -cellpose==2.1.0 -lapsolver==1.1.0 -scikit-learn>=1.1.3 -scipy>=1.8.0 -torchmetrics[detection]>=1.0.0 -pytest -pytest-cov -hypothesis -profilehooks -onnxruntime -``` ## Virtual staining of cellular compartments from label-free images diff --git a/pyproject.toml b/pyproject.toml index 388019c9..c0b0cf9e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ dependencies = [ "jsonargparse[signatures]>=4.20.1", "scikit-image", "matplotlib", + "cellpose" ] dynamic = ["version"] From 8d3bbe6a872471fc6295a1616e181f48d0d379a0 Mon Sep 17 00:00:00 2001 From: Shalin Mehta Date: Thu, 10 Aug 2023 13:02:20 -0700 Subject: [PATCH 2/5] match package description with README --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c0b0cf9e..7ee5b6b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "viscy" -description = "Learning vision for cells" +description = "computer vision for image-based phenotyping of single cells" readme = "README.md" # cannot build on 3.11 due to https://github.com/cheind/py-lapsolver/pull/18 requires-python = ">=3.9,!=3.11" From df28a7d28b8d97bb49577a930411b17bdbc9ff5a Mon Sep 17 00:00:00 2001 From: Shalin Mehta Date: Thu, 10 Aug 2023 13:11:59 -0700 Subject: [PATCH 3/5] cellpose (metrics -> required) --- README.md | 7 +++++++ pyproject.toml | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a039e119..fa8bd68f 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,15 @@ This pipeline evolved from the [TensorFlow version of virtual staining pipeline] ```sh git clone https://github.com/mehta-lab/viscy.git cd viscy +# in project root directory (where you can see README.md with `ls`) pip install . ``` +If you are using virtually stained images for segmenting structures, you should also install the metrics, + +```sh +# in project root directory (where you can see README.md with `ls`) +pip install ."[metrics]" +``` 3. Verify installation by accessing the CLI help message: diff --git a/pyproject.toml b/pyproject.toml index 7ee5b6b2..e5533e9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,13 +20,12 @@ dependencies = [ "jsonargparse[signatures]>=4.20.1", "scikit-image", "matplotlib", - "cellpose" + "cellpose==2.1.0", # currently imported by viscy.light.engine ] dynamic = ["version"] [project.optional-dependencies] metrics = [ - "cellpose==2.1.0", "lapsolver==1.1.0", "scikit-learn>=1.1.3", "scipy>=1.8.0", From 87268f7e7c28d66ef9b6cfac4318c34be6959318 Mon Sep 17 00:00:00 2001 From: Ziwen Liu Date: Thu, 10 Aug 2023 13:39:20 -0700 Subject: [PATCH 4/5] misc formatting and language edits --- README.md | 55 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index fa8bd68f..8f1bcf2d 100644 --- a/README.md +++ b/README.md @@ -2,54 +2,57 @@ viscy is a deep learning pipeline for training and deploying computer vision models for image-based phenotyping at single cell resolution. -The current focus of the pipeline is on the image translation models for virtual staining of multiple cellular compartments from label-free images. We are building these models for simultaneous segmentation of nuclei and membrane, which are the first steps in a single-cell phenotyping pipeline. Our pipeline also provides utilities to export the models to onnx format for use at runtime. We will grow the collection of the models suitable for high-throughput imaging and phenotyping. Expect rough edges until we release a pypi package. +The current focus of the pipeline is on the image translation models for virtual staining of multiple cellular compartments from label-free images. +We are building these models for simultaneous segmentation of nuclei and membrane, which are the first steps in a single-cell phenotyping pipeline. +Our pipeline also provides utilities to export the models to ONNX format for use at runtime. +We will grow the collection of the models suitable for high-throughput imaging and phenotyping. +Expect rough edges until we release a PyPI package. ![virtual_staining](docs/figures/phase_to_nuclei_membrane.svg) This pipeline evolved from the [TensorFlow version of virtual staining pipeline](https://github.com/mehta-lab/microDL), which we reported in [this paper in 2020](https://elifesciences.org/articles/55502). The previous pipeline is now a public archive, and we will be focusing our efforts on viscy. -## Installing viscy +## Installing viscy -1. We highly encourage you to create a new Conda environment. We prefer using mamba, but conda will work just as well. +1. We highly encourage using new Conda/virtual environment. + ([Mamba](https://github.com/mamba-org/mamba) is a faster re-implementation Conda.) -```sh - mamba create -n viscy python=3.10 + ```sh + mamba create --name viscy python=3.10 + # OR + mamba create --prefix /path/to/conda/envs/viscy python=3.10 + ``` - OR +2. Clone this repository and install with pip: - mamba create -p /viscy python=3.10 -``` - -2. Clone this repository and install viscy: + ```sh + git clone https://github.com/mehta-lab/viscy.git + # change to project root directory (parent folder of pyproject.toml) + cd viscy + pip install . + ``` -```sh -git clone https://github.com/mehta-lab/viscy.git -cd viscy -# in project root directory (where you can see README.md with `ls`) -pip install . -``` -If you are using virtually stained images for segmenting structures, you should also install the metrics, + If evaluating virtually stained images for segmentation tasks, + additional dependencies need to be installed: -```sh -# in project root directory (where you can see README.md with `ls`) -pip install ."[metrics]" -``` + ```sh + pip install ".[metrics]" + ``` 3. Verify installation by accessing the CLI help message: -```sh -viscy --help -``` + ```sh + viscy --help + ``` For development installation, see [the contributing guide](CONTRIBUTING.md). -The pipeline is built using the [pytorch lightning](https://www.pytorchlightning.ai/index.html) framework and [iohub](https://github.com/czbiohub-sf/iohub) library for reading and writing data in [ome-zarr](https://www.nature.com/articles/s41592-021-01326-w) format. +The pipeline is built using the [PyTorch Lightning](https://www.pytorchlightning.ai/index.html) framework and [iohub](https://github.com/czbiohub-sf/iohub) library for reading and writing data in [OME-Zarr](https://www.nature.com/articles/s41592-021-01326-w) format. The full functionality is tested only on Linux `x86_64` with NVIDIA Ampere GPUs (CUDA 12.0). Some features (e.g. mixed precision and distributed training) may not work with other setups, see [PyTorch documentation](https://pytorch.org) for details. - ## Virtual staining of cellular compartments from label-free images Predicting sub-cellular landmarks such as nuclei and membrane from label-free (e.g. phase) images From c28a6cc624a7d81764e35950658e2c90db0f1586 Mon Sep 17 00:00:00 2001 From: Ziwen Liu Date: Thu, 10 Aug 2023 13:49:32 -0700 Subject: [PATCH 5/5] fix optional dependency on cellpose --- pyproject.toml | 2 +- viscy/light/engine.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e5533e9a..6a85a05a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,12 +20,12 @@ dependencies = [ "jsonargparse[signatures]>=4.20.1", "scikit-image", "matplotlib", - "cellpose==2.1.0", # currently imported by viscy.light.engine ] dynamic = ["version"] [project.optional-dependencies] metrics = [ + "cellpose==2.1.0", "lapsolver==1.1.0", "scikit-learn>=1.1.3", "scipy>=1.8.0", diff --git a/viscy/light/engine.py b/viscy/light/engine.py index f9791864..d8a11909 100644 --- a/viscy/light/engine.py +++ b/viscy/light/engine.py @@ -5,7 +5,6 @@ import numpy as np import torch import torch.nn.functional as F -from cellpose.models import CellposeModel from imageio import imwrite from lightning.pytorch import LightningDataModule, LightningModule, Trainer from lightning.pytorch.utilities.compile import _maybe_unwrap_optimized @@ -33,6 +32,12 @@ from viscy.unet.networks.Unet21D import Unet21d from viscy.unet.networks.Unet25D import Unet25d +try: + from cellpose.models import CellposeModel +except ImportError: + CellposeModel = None + + _UNET_ARCHITECTURE = { "2D": Unet2d, "2.1D": Unet21d, @@ -303,6 +308,12 @@ def on_validation_epoch_end(self): def on_test_start(self): """Load CellPose model for segmentation.""" + if CellposeModel is None: + raise ImportError( + "CellPose not installed. " + "Please install the metrics dependency with " + "`pip install viscy\".[metrics]\"`" + ) if self.test_cellpose_model_path is not None: self.cellpose_model = CellposeModel( model_type=self.test_cellpose_model_path, device=self.device