From e3a36e189a80a69c421c2ce62149991053d17f1a Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Sun, 13 Dec 2020 15:17:18 -0700 Subject: [PATCH 01/13] updating docs --- cellpose/models.py | 4 ---- docs/train.rst | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cellpose/models.py b/cellpose/models.py index e48f18d9..67df4eeb 100644 --- a/cellpose/models.py +++ b/cellpose/models.py @@ -1016,7 +1016,6 @@ class CellposeModel(UnetModel): net_avg: bool (optional, default True) loads the 4 built-in networks and averages them if True, loads one network if False - diam_mean: float (optional, default 27.) mean 'diameter', 27. is built in value for 'cyto' model @@ -1326,11 +1325,8 @@ def train(self, train_data, train_labels, train_files=None, if True it assumes you will fit a size model after training or resize your images accordingly, if False it will try to train the model to be scale-invariant (works worse) - """ - nimg = len(train_data) - train_data, train_labels, test_data, test_labels, run_test = transforms.reshape_train_test(train_data, train_labels, test_data, test_labels, channels, normalize) diff --git a/docs/train.rst b/docs/train.rst index 16ace704..f7959c55 100644 --- a/docs/train.rst +++ b/docs/train.rst @@ -7,7 +7,12 @@ mask image (``dynamics.labels_to_flows``). The cellpose pretrained models are trained using resized images so that the cells have the same median diameter across all images. If you choose to use a pretrained model, then this fixed median diameter is used. -If you choose to train from scratch, you can set the median diameter you want to use for rescaling with the ``--diameter`` flag, or set it to 0 to disable rescaling. +If you choose to train from scratch, you can set the median diameter you want to use for rescaling with the ``--diameter`` flag, or set it to 0 to disable rescaling. +We trained the `cyto` model with a diameter of 30 pixels and the `nuclei` model with a diameter of 17 pixels. + +When you rescale everything to 30. pixel diameter, if you have images with varying diameters + you may also want to learn a `SizeModel` that predicts the diameter from the styles that the + network outputs. Add the flag `--train_size` and this will be learned. The same channel settings apply for training models (see all Command line `options `_). @@ -47,7 +52,14 @@ You can train from scratch as well: python -m cellpose --train --dir ~/images_nuclei/train/ --pretrained_model None -You can specify the full path to a pretrained model to use: +To train the cyto model from scratch using the same parameters we did, download the dataset and run + +:: + + python -m cellpose --train --train_size --use_gpu --dir ~/cellpose_dataset/train/ --test_dir ~/cellpose_dataset/test/ --img_filter _img --pretrained_model None --chan 2 --chan2 1 + + +You can also specify the full path to a pretrained model to use: :: From 684ed706cbf7f26cea09404128009a455084f79f Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Sun, 13 Dec 2020 16:05:59 -0700 Subject: [PATCH 02/13] updating docs --- README.md | 42 +++++++++++------------- docs/inputs.rst | 3 ++ docs/installation.rst | 39 ++++++++++++++++------ docs/settings.rst | 75 ++++++++++++++++++++++++++++--------------- docs/train.rst | 9 +++--- 5 files changed, 106 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 5fda89f2..7cad5eb8 100644 --- a/README.md +++ b/README.md @@ -45,25 +45,12 @@ Linux, Windows and Mac OS are supported for running the code. For running the gr This process should take less than 5 minutes. -### (Option 1) Standard install in base environment - 1. Install an [Anaconda](https://www.anaconda.com/download/) distribution of Python -- Choose **Python 3.7** and your operating system. Note you might need to use an anaconda prompt if you did not add anaconda to the path. -2. From your base environment in an anaconda prompt/command prompt, run -~~~~ -pip install cellpose[gui] -~~~~ - -If you want to install without the GUI dependencies, run `pip install cellpose`. - -### (Option 2) Install in a new environment - -Alternatively you can use the included environment file (if you'd like a cellpose-specific environment). This environment file includes all the dependencies for using the GUI. Using the environment file is **recommended** if you have problems with *option 1*. Please follow these instructions: - -1. Download the [`environment.yml`](https://github.com/MouseLand/cellpose/blob/master/environment.yml?raw=true) file from the repository. You can do this by cloning the repository, or copy-pasting the text from the file into a text document on your local computer. -2. Open an anaconda prompt / command prompt with `conda` for **python 3** in the path -3. Change directories to where the `environment.yml` is and run `conda env create -f environment.yml` -4. To activate this new environment, run `conda activate cellpose` -5. You should see `(cellpose)` on the left side of the terminal line. Now run `python -m cellpose` and you're all set. +2. Download the [`environment.yml`](https://github.com/MouseLand/cellpose/blob/master/environment.yml?raw=true) file from the repository. You can do this by cloning the repository, or copy-pasting the text from the file into a text document on your local computer. +3. Open an anaconda prompt / command prompt with `conda` for **python 3** in the path +4. Change directories to where the `environment.yml` is and run `conda env create -f environment.yml` +5. To activate this new environment, run `conda activate cellpose` +6. You should see `(cellpose)` on the left side of the terminal line. Now run `python -m cellpose` and you're all set. To upgrade cellpose (package [here](https://pypi.org/project/cellpose/)), run the following in the environment: ~~~~ @@ -74,21 +61,28 @@ If you have an older `cellpose` environment you can remove it with `conda env re Note you will always have to run **conda activate cellpose** before you run cellpose. If you want to run jupyter notebooks in this environment, then also `conda install jupyter` and `pip install matplotlib`. +If you're feeling adventurous you can also try to install cellpose from your base environment using the command +~~~~ +pip install cellpose[gui] +~~~~ + If you have **issues** with installation, see the [docs](https://cellpose.readthedocs.io/en/latest/installation.html) for more details, and then if the suggestions fail, open an issue. ### CUDA version -If you plan on running many images, you may want to install a GPU version of *mxnet*. I recommend using CUDA 10.0 or greater. Follow the instructions [here](https://mxnet.apache.org/get_started?). +If you plan on running many images, you may want to install a GPU version of *mxnet*. I recommend using CUDA 10.0 or greater. Follow the instructions [here](https://mxnet.apache.org/get_started?) to find the version to install. -Before installing the GPU version, remove the CPU version: +Note when upgrading cellpose in the future, you will want to ignore dependencies (so that mxnet-mkl does not install): ~~~ -pip uninstall mxnet-mkl -pip uninstall mxnet +pip install --no-deps cellpose --upgrade ~~~ -When upgrading cellpose, you will want to ignore dependencies (so that mxnet-mkl does not install): +**ON LINUX** + +Before installing the GPU version, remove the CPU version: ~~~ -pip install --no-deps cellpose --upgrade +pip uninstall mxnet-mkl +pip uninstall mxnet ~~~ ### Installation of github version diff --git a/docs/inputs.rst b/docs/inputs.rst index f25963b4..adea08ab 100644 --- a/docs/inputs.rst +++ b/docs/inputs.rst @@ -34,3 +34,6 @@ You can give a list of 3D inputs, or a single 3D/4D stack. When running on the command line, add the flag ``--do_3D`` (it will run all tiffs in the folder as 3D tiffs). +If the 3D segmentation is not working well and there is inhomogeneity in Z, try stitching +masks in Z instead of running ``do_3D=True``. See details for this option here: +`stitch_threshold `__. diff --git a/docs/installation.rst b/docs/installation.rst index 0c12cf75..c0d3c894 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -1,9 +1,30 @@ Installation ------------------------------ -We recommend installing an `Anaconda`_ distribution of Python -- Choose -**Python 3.7** and your operating system. Note you might need to use an -anaconda prompt if you did not add anaconda to the path. From your base +1. Install an Anaconda distribution of Python -- Choose **Python 3.7** and your operating system. Note you might need to use an anaconda prompt if you did not add anaconda to the path. +2. Download the `environment.yml `_ +file from the repository. You can do this by cloning the repository, or copy-pasting the text from the file into a text document on your local computer. +3. Open an anaconda prompt / command prompt with ``conda`` for **python 3** in the path +4. Change directories to where the ``environment.yml`` is and run ``conda env create -f environment.yml`` +5. To activate this new environment, run `conda activate cellpose` +6. You should see ``(cellpose)`` on the left side of the terminal line. Now run ``python -m cellpose`` and you're all set. + +To upgrade cellpose (pypi `package `_), run the following in the environment: +:: + + pip install cellpose --upgrade + +If you have an older `cellpose` environment you can remove it with ``conda env remove -n cellpose`` before creating a new one. + +Note you will always have to run **conda activate cellpose** before you run cellpose. If you want to run jupyter notebooks in this environment, then also `conda install jupyter` and `pip install matplotlib`. + +If you're feeling adventurous you can also try to install cellpose from your base environment using the command +:: + + pip install cellpose[gui] + + +From your base environment (or you can make a new environment) in an anaconda prompt/command prompt, run @@ -107,19 +128,19 @@ If you plan on running many images, you may want to install a GPU version of *mxnet*. I recommend using CUDA 10.0 or greater. Follow the instructions `here `__. -Before installing the GPU version, remove the CPU version: +When upgrading cellpose, you will want to ignore dependencies (so that +mxnet-mkl does not install): :: - pip uninstall mxnet-mkl - pip uninstall mxnet + pip install --no-deps cellpose --upgrade -When upgrading cellpose, you will want to ignore dependencies (so that -mxnet-mkl does not install): +ON LINUX before installing the GPU version, remove the CPU version: :: - pip install --no-deps cellpose --upgrade + pip uninstall mxnet-mkl + pip uninstall mxnet **Installation of github version** diff --git a/docs/settings.rst b/docs/settings.rst index 1bd60462..cf7d065a 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -21,6 +21,33 @@ running a list of images for reference: You can make lists of channels/diameter for each image, or set the same channels/diameter for all images as shown in the example above. +Channels +~~~~~~~~~~~~~~~~~~~~~~~~ + +Cytoplasm model (`'cyto'`) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The cytoplasm model in cellpose is trained on two-channel images, where +the first channel is the channel to segment, and the second channel is +an optional nuclear channel. Here are the options for each: +1. 0=grayscale, 1=red, 2=green, 3=blue +2. 0=None (will set to zero), 1=red, 2=green, 3=blue + +Set channels to a list with each of these elements, e.g. +``channels = [0,0]`` if you want to segment cells in grayscale or for single channel images, or +``channels = [2,3]`` if you green cells with blue nuclei. + +Nucleus model (`'nuclei'`) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The nuclear model in cellpose is trained on two-channel images, where +the first channel is the channel to segment, and the second channel is +always set to an array of zeros. Therefore set the first channel as +0=grayscale, 1=red, 2=green, 3=blue; and set the second channel to zero, e.g. +``channels = [0,0]`` if you want to segment nuclei in grayscale or for single channel images, or +``channels = [3,0]`` if you want to segment blue nuclei. + + Diameter ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -46,34 +73,21 @@ outputs. When the diameter is set smaller than the true size then cellpose may over-split cells. Similarly, if the diameter is set too big then cellpose may over-merge cells. -Channels +Resample ~~~~~~~~~~~~~~~~~~~~~~~~ -Cytoplasm model (`'cyto'`) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The cytoplasm model in cellpose is trained on two-channel images, where -the first channel is the channel to segment, and the second channel is -an optional nuclear channel. Here are the options for each: -1. 0=grayscale, 1=red, 2=green, 3=blue -2. 0=None (will set to zero), 1=red, 2=green, 3=blue - -Set channels to a list with each of these elements, e.g. -``channels = [0,0]`` if you want to segment cells in grayscale or for single channel images, or -``channels = [2,3]`` if you green cells with blue nuclei. - -Nucleus model (`'nuclei'`) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The nuclear model in cellpose is trained on two-channel images, where -the first channel is the channel to segment, and the second channel is -always set to an array of zeros. Therefore set the first channel as -0=grayscale, 1=red, 2=green, 3=blue; and set the second channel to zero, e.g. -``channels = [0,0]`` if you want to segment nuclei in grayscale or for single channel images, or -``channels = [3,0]`` if you want to segment blue nuclei. +The cellpose network is run on your rescaled image -- where the rescaling factor is determined +by the diameter you input (or determined automatically as above). For instance, if you have +an image with 60 pixel diameter cells, the rescaling factor is 30./60. = 0.5. After determining +the flows (dX, dY, cellprob), the model runs the dynamics. The dynamics can be run at the rescaled +size (``resample=False``), or the dynamics can be run on the resampled, interpolated flows +at the true image size (``resample=True``). ``resample=True`` will create smoother masks when the +cells are large but will be slower in case; ``resample=False`` will find more masks when the cells +are small but will be slower in this case. By default in v0.5 ``resample=False``, but in +previous releases the default was ``resample=True``. -Flow threshold -~~~~~~~~~~~~~~~~~~~~~~ +Flow threshold (aka model fit threshold in GUI) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Note there is nothing keeping the neural network from predicting horizontal and vertical flows that do not correspond to any real @@ -104,3 +118,14 @@ is ``cellprob_threshold=0.0``. Decrease this threshold if cellpose is not return as many masks as you'd expect. Similarly, increase this threshold if cellpose is returning too masks particularly from dim areas. +3D settings +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Volumetric stacks do not always have the same sampling in XY as they do in Z. +Therefore you can set an ``anisotropy`` parameter to allow for differences in +sampling, e.g. set to 2.0 if Z is sampled half as dense as X or Y. + + + + + diff --git a/docs/train.rst b/docs/train.rst index f7959c55..6d08f066 100644 --- a/docs/train.rst +++ b/docs/train.rst @@ -11,8 +11,9 @@ If you choose to train from scratch, you can set the median diameter you want to We trained the `cyto` model with a diameter of 30 pixels and the `nuclei` model with a diameter of 17 pixels. When you rescale everything to 30. pixel diameter, if you have images with varying diameters - you may also want to learn a `SizeModel` that predicts the diameter from the styles that the - network outputs. Add the flag `--train_size` and this will be learned. +you may also want to learn a `SizeModel` that predicts the diameter from the styles that the +network outputs. Add the flag ``--train_size`` and this model will be trained and saved as an +``*.npy`` file. The same channel settings apply for training models (see all Command line `options `_). @@ -24,14 +25,14 @@ Note Cellpose expects the labelled masks (0=no mask, 1,2...=masks) in a separate wells_000.tif wells_000_masks.tif -If you use the --img_filter option (`--img_filter img` in this case): +If you use the --img_filter option (``--img_filter img`` in this case): :: wells_000_img.tif wells_000_masks.tif -/!\ The path given to `--dir` and `--test` must be absolute path. +/!\ The path given to ``--dir`` and ``--test_dir`` must be an absolute path. Training-specific options From af4792502da761bcc4395c43018afc4b91796979 Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Sun, 13 Dec 2020 16:07:15 -0700 Subject: [PATCH 03/13] bug with list in install --- docs/installation.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index c0d3c894..5717f894 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -2,8 +2,7 @@ Installation ------------------------------ 1. Install an Anaconda distribution of Python -- Choose **Python 3.7** and your operating system. Note you might need to use an anaconda prompt if you did not add anaconda to the path. -2. Download the `environment.yml `_ -file from the repository. You can do this by cloning the repository, or copy-pasting the text from the file into a text document on your local computer. +2. Download the `environment.yml `_ file from the repository. You can do this by cloning the repository, or copy-pasting the text from the file into a text document on your local computer. 3. Open an anaconda prompt / command prompt with ``conda`` for **python 3** in the path 4. Change directories to where the ``environment.yml`` is and run ``conda env create -f environment.yml`` 5. To activate this new environment, run `conda activate cellpose` From d40a75275b6702742718d0073a6c10e21f6d83ef Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Sun, 13 Dec 2020 16:08:39 -0700 Subject: [PATCH 04/13] bug in note in docs --- docs/installation.rst | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 5717f894..f325bce9 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -13,9 +13,11 @@ To upgrade cellpose (pypi `package `_), run pip install cellpose --upgrade -If you have an older `cellpose` environment you can remove it with ``conda env remove -n cellpose`` before creating a new one. +If you have an older ``cellpose`` environment you can remove it with ``conda env remove -n cellpose`` before creating a new one. -Note you will always have to run **conda activate cellpose** before you run cellpose. If you want to run jupyter notebooks in this environment, then also `conda install jupyter` and `pip install matplotlib`. +Note you will always have to run **conda activate cellpose** before you run cellpose. +If you want to run jupyter notebooks in this environment, then also +``conda install jupyter`` and ``pip install matplotlib``. If you're feeling adventurous you can also try to install cellpose from your base environment using the command :: @@ -33,41 +35,6 @@ prompt/command prompt, run If you want to install without the GUI dependencies, run ``pip install cellpose``. -.. note:: - The first time you run cellpose it downloads the latest available trained - model weights from the cellpose website. These models are saved in your home - directory in a .cellpose folder, not in the code package. - -With an environment file -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Alternatively you can use the included environment file (if you'd like a -cellpose-specific environment). This environment file includes all the -dependencies for using the GUI. Using the environment file is -**recommended** if you have problems with the pip. -Please follow these instructions: - -1. Download the `environment.yml`_ file from the repository. You can - do this by cloning the repository, or copy-pasting the text from the - file into a text document on your local computer. -2. Open an anaconda prompt / command prompt with ``conda`` for **python - 3** in the path -3. Change directories to where the ``environment.yml`` is and run - ``conda env create -f environment.yml`` -4. To activate this new environment, run ``conda activate cellpose`` -5. You should see ``(cellpose)`` on the left side of the terminal line. - Now run ``python -m cellpose`` and you're all set. - -To upgrade cellpose (package `here`_), run the following in the -environment: - -:: - - pip install cellpose --upgrade - -If you have an older ``cellpose`` environment you can remove it with -``conda env remove -n cellpose`` before creating a new one. - .. note:: Now you will always have to run **conda activate cellpose** before you run cellpose. If you want to run jupyter notebooks in this environment, From d5a61cdd94c665710d3780e2a7981e67fd48fdec Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Sun, 13 Dec 2020 16:09:26 -0700 Subject: [PATCH 05/13] repeat in docs --- docs/installation.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index f325bce9..33bd840c 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -35,11 +35,6 @@ prompt/command prompt, run If you want to install without the GUI dependencies, run ``pip install cellpose``. -.. note:: - Now you will always have to run **conda activate cellpose** before you - run cellpose. If you want to run jupyter notebooks in this environment, - then also ``conda install jupyter``. - Common issues ~~~~~~~~~~~~~~~~~~~~~~~ From a3e5f83b5d26a19148d8fd6c3aa096892fbdd145 Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Sun, 13 Dec 2020 16:14:03 -0700 Subject: [PATCH 06/13] adding stitching instructions --- docs/settings.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/settings.rst b/docs/settings.rst index cf7d065a..ef9e2735 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -123,7 +123,16 @@ returning too masks particularly from dim areas. Volumetric stacks do not always have the same sampling in XY as they do in Z. Therefore you can set an ``anisotropy`` parameter to allow for differences in -sampling, e.g. set to 2.0 if Z is sampled half as dense as X or Y. +sampling, e.g. set to 2.0 if Z is sampled half as dense as X or Y. + +There may be additional differences in YZ and XZ slices +that make them unable to be used for 3D segmentation. +I'd recommend viewing the volume in those dimensions if +the segmentation is failing. In those instances, you may want to turn off +3D segmentation (``do_3D=False``) and run instead with ``stitch_threshold>0``. +Cellpose will create masks in 2D on each XY slice and then stitch them across +slices if the IoU between the mask on the current slice and the next slice is +greater than or equal to the ``stitch_threshold``. From d66a38823133b77b5b75f658847ed1ad54a6ce6a Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Sun, 13 Dec 2020 16:22:28 -0700 Subject: [PATCH 07/13] fixing internal doc link --- docs/inputs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/inputs.rst b/docs/inputs.rst index adea08ab..94f59bf9 100644 --- a/docs/inputs.rst +++ b/docs/inputs.rst @@ -36,4 +36,4 @@ in the folder as 3D tiffs). If the 3D segmentation is not working well and there is inhomogeneity in Z, try stitching masks in Z instead of running ``do_3D=True``. See details for this option here: -`stitch_threshold `__. +`stitch_threshold `__. From fc19c7cd5413338d16578002af59227937ef204a Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Sun, 13 Dec 2020 16:24:21 -0700 Subject: [PATCH 08/13] adding warning in docs for CLI --- docs/command.rst | 4 ++++ docs/train.rst | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/command.rst b/docs/command.rst index f67f5434..bba04801 100644 --- a/docs/command.rst +++ b/docs/command.rst @@ -69,6 +69,10 @@ estimated: python -m cellpose --dir ~/images_nuclei/test/ --pretrained_model nuclei --diameter 0. --save_png +.. warning:: + The path given to ``--dir`` must be an absolute path. + + Options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/train.rst b/docs/train.rst index 6d08f066..e99038d1 100644 --- a/docs/train.rst +++ b/docs/train.rst @@ -32,7 +32,8 @@ If you use the --img_filter option (``--img_filter img`` in this case): wells_000_img.tif wells_000_masks.tif -/!\ The path given to ``--dir`` and ``--test_dir`` must be an absolute path. +.. warning:: + The path given to ``--dir`` and ``--test_dir`` must be an absolute path. Training-specific options From 0b6fdd8194fcfe9f874a72050ce0e8916935fe3a Mon Sep 17 00:00:00 2001 From: Carsen Stringer Date: Sun, 13 Dec 2020 20:29:53 -0700 Subject: [PATCH 09/13] fixing bug with training size --- cellpose/io.py | 3 +++ cellpose/models.py | 2 ++ tests/test_train.py | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/cellpose/io.py b/cellpose/io.py index 8d68fa40..57fda67a 100644 --- a/cellpose/io.py +++ b/cellpose/io.py @@ -77,6 +77,9 @@ def get_image_files(folder, mask_filter, imf=None): if igood: imn.append(im) image_names = imn + + if len(image_names)==0: + raise ValueError('ERROR: no images in --dir folder') return image_names diff --git a/cellpose/models.py b/cellpose/models.py index 67df4eeb..f343e7c5 100644 --- a/cellpose/models.py +++ b/cellpose/models.py @@ -834,6 +834,7 @@ def train(self, train_data, train_labels, train_files=None, print('>>>> finding best thresholds using validation set') cell_threshold, boundary_threshold = self.threshold_validation(val_data, val_labels) np.save(model_path+'_cell_boundary_threshold.npy', np.array([cell_threshold, boundary_threshold])) + self.pretrained_model = model_path def threshold_validation(self, val_data, val_labels): cell_thresholds = np.arange(-4.0, 4.25, 0.5) @@ -1342,6 +1343,7 @@ def train(self, train_data, train_labels, train_files=None, test_data, test_flows, pretrained_model, save_path, save_every, learning_rate, n_epochs, weight_decay, batch_size, rescale) + self.pretrained_model = model_path return model_path class SizeModel(): diff --git a/tests/test_train.py b/tests/test_train.py index 1a3c14b8..aa6368ca 100644 --- a/tests/test_train.py +++ b/tests/test_train.py @@ -16,6 +16,17 @@ def test_class_train(data_dir, image_names): print('>>>> model trained and saved to %s'%cpmodel_path) def test_cli_train(data_dir, image_names): + train_dir = str(data_dir.joinpath('2D').joinpath('train')) + model_dir = str(data_dir.joinpath('2D').joinpath('train').joinpath('models')) + shutil.rmtree(model_dir, ignore_errors=True) + cmd = 'python -m cellpose --train --train_size --n_epochs 10 --dir %s --mask_filter _cyto_masks --pretrained_model None --chan 2 --chan2 1 --diameter 17'%train_dir + try: + cmd_stdout = check_output(cmd, stderr=STDOUT, shell=True).decode() + except Exception as e: + print(e) + raise ValueError(e) + +def test_cli_train_pretrained(data_dir, image_names): train_dir = str(data_dir.joinpath('2D').joinpath('train')) model_dir = str(data_dir.joinpath('2D').joinpath('train').joinpath('models')) shutil.rmtree(model_dir, ignore_errors=True) From be8701b0f14e48fab96e03dc156422ca007ce1c8 Mon Sep 17 00:00:00 2001 From: Marius Pachitariu Date: Mon, 14 Dec 2020 10:22:35 -0500 Subject: [PATCH 10/13] updated installation instructions --- README.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7cad5eb8..addc54f6 100644 --- a/README.md +++ b/README.md @@ -68,13 +68,16 @@ pip install cellpose[gui] If you have **issues** with installation, see the [docs](https://cellpose.readthedocs.io/en/latest/installation.html) for more details, and then if the suggestions fail, open an issue. -### CUDA version +### GPU version (CUDA) -If you plan on running many images, you may want to install a GPU version of *mxnet*. I recommend using CUDA 10.0 or greater. Follow the instructions [here](https://mxnet.apache.org/get_started?) to find the version to install. +If you plan on running many images, you may want to install a GPU version of *mxnet*. We recommend using CUDA 10.0 or greater. + +**ON WINDOWS** + +Just install the GPU version of mxnet directly in the environment, i.e.: -Note when upgrading cellpose in the future, you will want to ignore dependencies (so that mxnet-mkl does not install): ~~~ -pip install --no-deps cellpose --upgrade +pip install mxnet-cu101 ~~~ **ON LINUX** @@ -83,6 +86,12 @@ Before installing the GPU version, remove the CPU version: ~~~ pip uninstall mxnet-mkl pip uninstall mxnet +pip install mxnet-cu101 +~~~ + +Follow the instructions [here](https://mxnet.apache.org/get_started?) to determine what version to install to match your CUDA install. When upgrading GPU Cellpose in the future, you will want to ignore dependencies (so that mxnet-mkl does not install): +~~~ +pip install --no-deps cellpose --upgrade ~~~ ### Installation of github version From 5a0bbcc12109e2808bfeaec27c2a6c89c4f74d5e Mon Sep 17 00:00:00 2001 From: Marius Pachitariu Date: Mon, 14 Dec 2020 10:24:53 -0500 Subject: [PATCH 11/13] Update installation.rst --- docs/installation.rst | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 33bd840c..6b813531 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -1,39 +1,7 @@ Installation ------------------------------ -1. Install an Anaconda distribution of Python -- Choose **Python 3.7** and your operating system. Note you might need to use an anaconda prompt if you did not add anaconda to the path. -2. Download the `environment.yml `_ file from the repository. You can do this by cloning the repository, or copy-pasting the text from the file into a text document on your local computer. -3. Open an anaconda prompt / command prompt with ``conda`` for **python 3** in the path -4. Change directories to where the ``environment.yml`` is and run ``conda env create -f environment.yml`` -5. To activate this new environment, run `conda activate cellpose` -6. You should see ``(cellpose)`` on the left side of the terminal line. Now run ``python -m cellpose`` and you're all set. - -To upgrade cellpose (pypi `package `_), run the following in the environment: -:: - - pip install cellpose --upgrade - -If you have an older ``cellpose`` environment you can remove it with ``conda env remove -n cellpose`` before creating a new one. - -Note you will always have to run **conda activate cellpose** before you run cellpose. -If you want to run jupyter notebooks in this environment, then also -``conda install jupyter`` and ``pip install matplotlib``. - -If you're feeling adventurous you can also try to install cellpose from your base environment using the command -:: - - pip install cellpose[gui] - - -From your base -environment (or you can make a new environment) in an anaconda -prompt/command prompt, run - -:: - - pip install cellpose[gui] - -If you want to install without the GUI dependencies, run ``pip install cellpose``. +For basic install instructions, look up the main github readme. Common issues ~~~~~~~~~~~~~~~~~~~~~~~ @@ -139,4 +107,4 @@ automatically installed with conda/pip if missing): .. _scipy: https://www.scipy.org/ .. _scikit-image: https://scikit-image.org/ .. _natsort: https://natsort.readthedocs.io/en/master/ -.. _matplotlib: https://matplotlib.org/ \ No newline at end of file +.. _matplotlib: https://matplotlib.org/ From 5779019346513e6523ad9ef5b3eec7f21cfffb17 Mon Sep 17 00:00:00 2001 From: Marius Pachitariu Date: Mon, 14 Dec 2020 11:03:53 -0500 Subject: [PATCH 12/13] Update installation.rst --- docs/installation.rst | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 6b813531..4c50b9cb 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -50,34 +50,6 @@ OS are fine. The software has been heavily tested on Windows 10 and Ubuntu 18.04, and less well tested on Mac OS. Please post an issue if you have installation problems. -CUDA version -~~~~~~~~~~~~~~~~~~~~~~ - -If you plan on running many images, you may want to install a GPU -version of *mxnet*. I recommend using CUDA 10.0 or greater. Follow the -instructions `here `__. - -When upgrading cellpose, you will want to ignore dependencies (so that -mxnet-mkl does not install): - -:: - - pip install --no-deps cellpose --upgrade - -ON LINUX before installing the GPU version, remove the CPU version: - -:: - - pip uninstall mxnet-mkl - pip uninstall mxnet - -**Installation of github version** - -Follow steps from above to install the dependencies. In the github -repository, run ``pip install -e .`` and the github version will be -installed. If you want to go back to the pip version of cellpose, then -say ``pip install cellpose``. - Dependencies ~~~~~~~~~~~~~~~~~~~~~~ From 981effb6d5fcabec0cded5bde39d7ee7f1475782 Mon Sep 17 00:00:00 2001 From: Marius Pachitariu Date: Wed, 16 Dec 2020 00:24:39 -0500 Subject: [PATCH 13/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index addc54f6..2d15dc9a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ A generalist algorithm for cell and nucleus segmentation. -This code was written by Carsen Stringer and Marius Pachitariu. To learn about Cellpose, read the [paper](https://t.co/4HFsxDezAP?amp=1) or watch the [talk](https://t.co/JChCsTD0SK?amp=1). For support, please open an [issue](https://github.com/MouseLand/cellpose/issues). +This code was written by Carsen Stringer and Marius Pachitariu. To learn about Cellpose, read the [paper](https://t.co/kBMXmPp3Yn?amp=1) or watch the [talk](https://t.co/JChCsTD0SK?amp=1). For support, please open an [issue](https://github.com/MouseLand/cellpose/issues). If you want to improve Cellpose for yourself and for everyone else, please consider contributing manual segmentations for a few of your images via the built-in GUI interface (see instructions below).