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

RunDeepProfiler #182

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
453 changes: 453 additions & 0 deletions active_plugins/rundeepprofiler.py

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions documentation/CP-plugins-documentation/RunDeepProfiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# RunDeepProfiler

## How to use RunDeepProfiler

### Windows

1. Follow the instructions to install CellProfiler from source: [Installing plugins with dependencies, using CellProfiler from source](using_plugins.md);

2. Clone DeepProfiler repository:

```
git clone https://github.com/broadinstitute/DeepProfiler.git
```

4. Install DeepProfiler

```
cd DeepProfiler /
pip install -e .
```

5. Install dependencies by running:

```bash
cd CellProfiler-plugins
pip install -e .[deepprofiler]
```

## Run Example

1. Use the folder with images and files available on CellProfiler-plugins > test > test_deepprofiler [link here](https://github.com/CellProfiler/CellProfiler-plugins/pull/182/commits/62874b4a28a370cea069662d3804a68b651130ec) as an example to run the test pipeline test_deepprofiler.cppipe

2. Don't forget to select the config, model, and DeepProfiler directories to your local paths.


## Using GPU

If you want to use a GPU to run the model (this is recommended for speed), you'll need a compatible version of Tensorflow and a supported GPU.
General instructions are available at this [link](https://www.tensorflow.org/guide/gpu).

1. Your GPU should be visible in Device Manager under Display Adaptors.
If your GPU isn't there, you likely need to install drivers.
[Here](https://www.nvidia.com/Download/Find.aspx) is where you can find NVIDIA GPU drivers if you need to install them.


2. To test whether the GPU is configured correctly:
* Run `python` on the command line (i.e., in Command Prompt or Terminal) to start an interactive session
* Then run the following
```
import tensorflow as tf
tf.test.is_gpu_available(
cuda_only=False, min_cuda_compute_capability=None
)
```
* If this returns `True`, you're all set
* If this returns `False`, you likely need to install/reinstall torch. See [here](https://www.tensorflow.org/guide/gpu) for your exact command.
* Exit the session with `exit()` then install tensorflow if necessary.


**NOTE**: You might get a warning like this:
```
W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-05-26 20:24:21.906286: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
```
If you don't have a GPU, this is not a problem. If you do, your configuration is incorrect and you need to try reinstalling drivers and the correct version of CUDA for your system.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ Those plugins that do have extra documentation contain links below.
| RunImageJScript | RunImageJScript allows you to run any supported ImageJ script directly within CellProfiler. It is significantly more performant than RunImageJMacro, and is also less likely to leave behind temporary files. | Yes | XXXXX |
| RunOmnipose | RunOmnipose allows you to run Omnipose within CellProfiler. Omnipose is a general image segmentation tool that builds on Cellpose. | Yes | `omnipose` |
| RunStarDist | RunStarDist allows you to run StarDist within CellProfiler. StarDist is a machine-learning algorithm for object detection with star-convex shapes making it best suited for nuclei or round-ish cells. You can use pre-trained StarDist models or your custom model with this plugin. You can use a GPU with this module to dramatically increase your speed/efficiency. RunStarDist is generally faster than RunCellpose. | Yes | `stardist` |
| [RunDeepProfiler](RunDeepProfiler.md) | RunDeepProfiler allows you to run DeepProfiler within CellProfiler. DeepProfiler can measure features from single-cells using pre-trained CNN. | Yes | `deepprofiler` |
| VarianceTransform | This module allows you to calculate the variance of an image, using a determined window size. It also has the option to find the optimal window size from a predetermined range to obtain the maximum variance of an image. | No | |
2 changes: 2 additions & 0 deletions documentation/CP-plugins-documentation/using_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ See [Installing plugins with dependencies, using CellProfiler from source](#inst
The second option allows you to use pre-built CellProfiler, but plugin installation is more complex.
See [Installing plugins with dependencies, using pre-built CellProfiler](#installing-plugins-with-dependencies-using-pre-built-cellprofiler).

If using RunDeepProfiler, check for alternative installation instructions in [RunDeepProfiler](RunDeepProfiler.md).

### Installing plugins without dependencies

1. **Install CellProfiler.**
Expand Down
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"stardist"
]

deepprofiler_deps = [
"numpy==1.23.0",
"inflect==6.0.0"
]

imagejscript_deps = [
"pyimagej"
]
Expand All @@ -32,6 +37,7 @@
"cellpose": cellpose_deps,
"omnipose": omnipose_deps,
"stardist": stardist_deps,
"deepprofiler":deepprofiler_deps,
"imagejscript": imagejscript_deps,
}
)
77 changes: 77 additions & 0 deletions tests/test_deepprofiler/config/profiling.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"dataset": {
"metadata": {
"label_field": "Metadata_Plate",
"control_value": "X"
},
"images": {
"channels": [
"DNA",
"RNA",
"ER",
"AGP",
"Mito"
],
"file_format": "tif",
"bits": 16,
"width": 1224,
"height": 904
},
"locations":{
"mode": "single_cells",
"area_coverage": 0.75,
"box_size": 128,
"mask_objects": false
}
},
"prepare": {
"illumination_correction": {
"down_scale_factor": 4,
"median_filter_size": 24
},
"compression": {
"implement": false,
"scaling_factor": 1.0
}
},
"train": {
"partition": {
"targets": [
"Metadata_Plate"
],
"split_field": "Split",
"training": [0],
"validation": [1]
},
"model": {
"name": "efficientnet",
"crop_generator": "sampled_crop_generator",
"augmentations": true,
"metrics": ["accuracy", "top_k", "average_class_precision"],
"epochs": 3,
"initialization":"ImageNet",
"params": {
"label_smoothing":0.0,
"learning_rate": 0.005,
"batch_size": 32,
"conv_blocks": 0
}
},
"sampling": {
"factor": 1,
"workers": 1
},
"validation": {
"frequency": 1,
"top_k": 5,
"batch_size": 32,
"frame": "val",
"sample_first_crops": true
}
},
"profile": {
"feature_layer": "block6a_activation",
"checkpoint": "Cell_Painting_CNN_v1.hdf5",
"batch_size": 32
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
128 changes: 128 additions & 0 deletions tests/test_deepprofiler/test_deepprofiler.cppipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
CellProfiler Pipeline: http://www.cellprofiler.org
Version:5
DateRevision:425
GitHash:
ModuleCount:6
HasImagePlaneDetails:False

Images:[module_num:1|svn_version:'Unknown'|variable_revision_number:2|show_window:False|notes:['To begin creating your project, use the Images module to compile a list of files and/or folders that you want to analyze. You can also specify a set of rules to include only the desired files in your selected folders.']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False]
:
Filter images?:Images only
Select the rule criteria:and (extension does isimage) (directory doesnot containregexp "[\\\\/]\\.")

Metadata:[module_num:2|svn_version:'Unknown'|variable_revision_number:6|show_window:False|notes:['The Metadata module optionally allows you to extract information describing your images (i.e, metadata) which will be stored along with your measurements. This information can be contained in the file name and/or location, or in an external file.']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False]
Extract metadata?:Yes
Metadata data type:Text
Metadata types:{}
Extraction method count:1
Metadata extraction method:Extract from file/folder names
Metadata source:File name
Regular expression to extract from file name:^(?P<Well>.*)_.*_.*_(?P<Site>.*)_(?P<Channel>.*)_001.tif
Regular expression to extract from folder name:(?P<Date>[0-9]{4}_[0-9]{2}_[0-9]{2})$
Extract metadata from:All images
Select the filtering criteria:and (file does contain "")
Metadata file location:Elsewhere...|
Match file and image metadata:[]
Use case insensitive matching?:No
Metadata file name:None
Does cached metadata exist?:No

NamesAndTypes:[module_num:3|svn_version:'Unknown'|variable_revision_number:8|show_window:False|notes:['The NamesAndTypes module allows you to assign a meaningful name to each image by which other modules will refer to it.']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False]
Assign a name to:Images matching rules
Select the image type:Grayscale image
Name to assign these images:DNA
Match metadata:[]
Image set matching method:Order
Set intensity range from:Image metadata
Assignments count:5
Single images count:0
Maximum intensity:255.0
Process as 3D?:No
Relative pixel spacing in X:1.0
Relative pixel spacing in Y:1.0
Relative pixel spacing in Z:1.0
Select the rule criteria:and (file does contain "DAPI")
Name to assign these images:DNA
Name to assign these objects:Cell
Select the image type:Grayscale image
Set intensity range from:Image metadata
Maximum intensity:255.0
Select the rule criteria:and (file does contain "GFP")
Name to assign these images:ER
Name to assign these objects:Nucleus
Select the image type:Grayscale image
Set intensity range from:Image metadata
Maximum intensity:255.0
Select the rule criteria:and (file does contain "Propidium")
Name to assign these images:AGP
Name to assign these objects:Cytoplasm
Select the image type:Grayscale image
Set intensity range from:Image metadata
Maximum intensity:255.0
Select the rule criteria:and (file does contain "CY5")
Name to assign these images:Mito
Name to assign these objects:Speckle
Select the image type:Grayscale image
Set intensity range from:Image metadata
Maximum intensity:255.0
Select the rule criteria:and (file does contain "CY5")
Name to assign these images:RNA
Name to assign these objects:Object1
Select the image type:Grayscale image
Set intensity range from:Image metadata
Maximum intensity:255.0

Groups:[module_num:4|svn_version:'Unknown'|variable_revision_number:2|show_window:False|notes:['The Groups module optionally allows you to split your list of images into image subsets (groups) which will be processed independently of each other. Examples of groupings include screening batches, microtiter plates, time-lapse movies, etc.']|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False]
Do you want to group your images?:No
grouping metadata count:1
Metadata category:None

IdentifyPrimaryObjects:[module_num:5|svn_version:'Unknown'|variable_revision_number:15|show_window:False|notes:[]|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False]
Select the input image:DNA
Name the primary objects to be identified:IdentifyPrimaryObjects
Typical diameter of objects, in pixel units (Min,Max):30,200
Discard objects outside the diameter range?:Yes
Discard objects touching the border of the image?:Yes
Method to distinguish clumped objects:Intensity
Method to draw dividing lines between clumped objects:Intensity
Size of smoothing filter:10
Suppress local maxima that are closer than this minimum allowed distance:7.0
Speed up by using lower-resolution image to find local maxima?:Yes
Fill holes in identified objects?:After both thresholding and declumping
Automatically calculate size of smoothing filter for declumping?:Yes
Automatically calculate minimum allowed distance between local maxima?:Yes
Handling of objects if excessive number of objects identified:Continue
Maximum number of objects:500
Use advanced settings?:Yes
Threshold setting version:12
Threshold strategy:Global
Thresholding method:Otsu
Threshold smoothing scale:1.3488
Threshold correction factor:1.0
Lower and upper bounds on threshold:0.0,1.0
Manual threshold:0.0
Select the measurement to threshold with:None
Two-class or three-class thresholding?:Three classes
Log transform before thresholding?:No
Assign pixels in the middle intensity class to the foreground or the background?:Background
Size of adaptive window:50
Lower outlier fraction:0.05
Upper outlier fraction:0.05
Averaging method:Mean
Variance method:Standard deviation
# of deviations:2.0
Thresholding method:Minimum Cross-Entropy

RunDeepProfiler:[module_num:6|svn_version:'Unknown'|variable_revision_number:1|show_window:False|notes:[]|batch_state:array([], dtype=uint8)|enabled:True|wants_pause:False]
Select images to measure:AGP, DNA, ER, Mito, RNA
Input nuclei object name:IdentifyPrimaryObjects
Name this experiment.:FeaturesDeepProfiler
Output file location:Elsewhere...|C:\\Users\\fossa\\Desktop\\deepprofiler\\example\\run
DeepProfiler directory:Elsewhere...|C:\Users\fossa\DeepProfiler
Model directory:Elsewhere...|C:\Users\fossa\Desktop\deepprofiler\example
Model file:Cell_Painting_CNN_v1.hdf5
Select Metadata_Plate:Metadata_Frame
Select Metadata_Well:Metadata_Well
Select Metadata_Site:Metadata_Site
Config directory:Elsewhere...|C:\\Users\\fossa\\Desktop\\deepprofiler\\example
Model file:profiling.json
Loading