8585"""
8686
8787"Select Cellpose Docker Image"
88- # V2 Dockers
89- CELLPOSE_DOCKER_NO_PRETRAINED_v232 = "cellprofiler/runcellpose_no_pretrained:2.3.2"
90- CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v232 = "cellprofiler/runcellpose_with_pretrained:2.3.2"
91- CELLPOSE_DOCKER_NO_PRETRAINED_v220 = "cellprofiler/runcellpose_no_pretrained:2.2"
92- CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v220 = "cellprofiler/runcellpose_with_pretrained:2.2"
93- # V3 Dockers
94- CELLPOSE_DOCKER_NO_PRETRAINED_v220 = "cellprofiler/runcellpose_no_pretrained:2.2" #TODO edit for v3
95- CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v220 = "cellprofiler/runcellpose_with_pretrained:2.2" #TODO edit for v3
96- # V4 Dockers
97- CELLPOSE_DOCKER_NO_PRETRAINED_v220 = "cellprofiler/runcellpose_no_pretrained:2.2" #TODO edit for SAM
98- CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v220 = "cellprofiler/runcellpose_with_pretrained:2.2" #TODO edit for SAM
88+ CELLPOSE_DOCKERS = {'v2' : ["cellprofiler/runcellpose_no_pretrained:2.3.2" ,
89+ "cellprofiler/runcellpose_with_pretrained:2.3.2" ,
90+ "cellprofiler/runcellpose_with_pretrained:2.2" ],
91+ 'v3' : ["docker3" ], #TODO
92+ 'v4' : ["docker4" ]} #TODO
9993
10094"Detection mode"
101- MODEL_NAMES_V2 = ['cyto' ,'nuclei' ,'tissuenet' ,'livecell' , 'cyto2' , 'general' ,
102- 'CP' , 'CPx' , 'TN1' , 'TN2' , 'TN3' , 'LC1' , 'LC2' , 'LC3' , 'LC4' , 'custom' ]
103- MODEL_NAMES_V3 = [
104- "cyto3" , "nuclei" , "cyto2_cp3" , "tissuenet_cp3" , "livecell_cp3" , "yeast_PhC_cp3" ,
105- "yeast_BF_cp3" , "bact_phase_cp3" , "bact_fluor_cp3" , "deepbacs_cp3" , "cyto2" , "cyto"
106- ]
107- MODEL_NAMES_V4 = [] #TODO
95+ MODEL_NAMES = {'v2' :['cyto' ,'nuclei' ,'tissuenet' ,'livecell' , 'cyto2' , 'general' ,
96+ 'CP' , 'CPx' , 'TN1' , 'TN2' , 'TN3' , 'LC1' , 'LC2' , 'LC3' , 'LC4' , 'custom' ],
97+ 'v3' :[ "cyto3" , "nuclei" , "cyto2_cp3" , "tissuenet_cp3" , "livecell_cp3" , "yeast_PhC_cp3" ,
98+ "yeast_BF_cp3" , "bact_phase_cp3" , "bact_fluor_cp3" , "deepbacs_cp3" , "cyto2" , "cyto" ],
99+ 'v4' :['model4' ]} #TODO
108100
109101DENOISER_NAMES = ['denoise_cyto3' , 'deblur_cyto3' , 'upsample_cyto3' ,
110102 'denoise_nuclei' , 'deblur_nuclei' , 'upsample_nuclei' ]
@@ -161,37 +153,29 @@ def create_settings(self):
161153
162154 self .docker_image_v2 = Choice (
163155 text = "Select Cellpose docker image" ,
164- choices = [ CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v220 , CELLPOSE_DOCKER_NO_PRETRAINED_v220 , CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v232 , CELLPOSE_DOCKER_NO_PRETRAINED_v232 ],
165- value = CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v232 ,
156+ choices = CELLPOSE_DOCKERS [ 'v2' ],
157+ value = CELLPOSE_DOCKERS [ 'v2' ][ 0 ] ,
166158 doc = """\
167159 Select which Docker image to use for running Cellpose.
168-
169- If you are not using a custom model, you can select
170- **"{CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v232}"** or "{CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v220}"**. If you are using a custom model,
160+ If you are not using a custom model, you should select a Docker image **with pretrained**. If you are using a custom model,
171161you can use any of the available Dockers, but those with pretrained models will be slightly larger (~500 MB).
172- """ .format (
173- ** {"CELLPOSE_DOCKER_NO_PRETRAINED_v220" : CELLPOSE_DOCKER_NO_PRETRAINED_v220 ,
174- "CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v220" : CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v220 ,
175- "CELLPOSE_DOCKER_NO_PRETRAINED_v232" : CELLPOSE_DOCKER_NO_PRETRAINED_v232 ,
176- "CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v232" : CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v232 }
177- ),
178- )
162+ """ )
179163 self .docker_image_v3 = Choice (
180164 text = "Select Cellpose docker image" ,
181- choices = [], #TODO
182- value = '' #TODO ,
165+ choices = CELLPOSE_DOCKERS [ 'v3' ],
166+ value = CELLPOSE_DOCKERS [ 'v3' ][ 0 ] ,
183167 doc = """\
184168 Select which Docker image to use for running Cellpose.
185- If you are not using a custom model, select a Docker image **with pretrained**. If you are using a custom model,
169+ If you are not using a custom model, you should select a Docker image **with pretrained**. If you are using a custom model,
186170you can use any of the available Dockers, but those with pretrained models will be slightly larger (~500 MB).""" ,
187171 )
188172 self .docker_image_v4 = Choice (
189173 text = "Select Cellpose docker image" ,
190- choices = [], #TODO
191- value = '' #TODO ,
174+ choices = CELLPOSE_DOCKERS [ 'v4' ],
175+ value = CELLPOSE_DOCKERS [ 'v4' ][ 0 ] ,
192176 doc = """\
193177 Select which Docker image to use for running Cellpose.
194- If you are not using a custom model, select a Docker image **with pretrained**. If you are using a custom model,
178+ If you are not using a custom model, you should select a Docker image **with pretrained**. If you are using a custom model,
195179you can use any of the available Dockers, but those with pretrained models will be slightly larger (~500 MB).""" ,
196180 )
197181
@@ -220,26 +204,26 @@ def create_settings(self):
220204
221205 self .mode_v2 = Choice (
222206 text = "Detection mode" ,
223- choices = MODEL_NAMES_V2 ,
224- value = MODEL_NAMES_V2 [0 ],
207+ choices = MODEL_NAMES [ 'v2' ] ,
208+ value = MODEL_NAMES [ 'v2' ] [0 ],
225209 doc = """\
226210 CellPose comes with models for detecting nuclei or cells. Alternatively, you can supply a custom-trained model
227211generated using the command line or Cellpose GUI. Custom models can be useful if working with unusual cell types.
228212""" ,
229213 )
230214 self .mode_v3 = Choice (
231215 text = "Detection mode" ,
232- choices = MODEL_NAMES_V3 ,
233- value = MODEL_NAMES_V3 [0 ],
216+ choices = MODEL_NAMES [ 'v3' ] ,
217+ value = MODEL_NAMES [ 'v3' ] [0 ],
234218 doc = """\
235219 CellPose comes with models for detecting nuclei or cells. Alternatively, you can supply a custom-trained model
236220generated using the command line or Cellpose GUI. Custom models can be useful if working with unusual cell types.
237221""" ,
238222 )
239223 self .mode_v4 = Choice (
240224 text = "Detection mode" ,
241- choices = MODEL_NAMES_V4 ,
242- value = MODEL_NAMES_V4 [0 ],
225+ choices = MODEL_NAMES [ 'v4' ] ,
226+ value = MODEL_NAMES [ 'v4' ] [0 ],
243227 doc = """\
244228 CellPose comes with models for detecting nuclei or cells. Alternatively, you can supply a custom-trained model
245229generated using the command line or Cellpose GUI. Custom models can be useful if working with unusual cell types.
@@ -513,11 +497,11 @@ def visible_settings(self):
513497 if self .docker_or_python .value == "Python" :
514498 vis_settings += [self .omni ]
515499
516- if self .mode .value != "nuclei" :
500+ if self .mode_v2 .value != "nuclei" :
517501 vis_settings += [self .supply_nuclei ]
518502 if self .supply_nuclei .value :
519503 vis_settings += [self .nuclei_image ]
520- if self .mode .value == "custom" :
504+ if self .mode_v2 .value == "custom" :
521505 vis_settings += [
522506 self .model_directory ,
523507 self .model_file_name ,
@@ -562,7 +546,7 @@ def visible_settings(self):
562546 def validate_module (self , pipeline ):
563547 """If using custom model, validate the model file opens and works"""
564548 from cellpose import models
565- if self .mode .value == "custom" :
549+ if self .mode_v2 .value == "custom" :
566550 model_file = self .model_file_name .value
567551 model_directory = self .model_directory .get_absolute_path ()
568552 model_path = os .path .join (model_directory , model_file )
@@ -618,7 +602,7 @@ def run(self, workspace):
618602 "Color images are not currently supported. Please provide greyscale images."
619603 )
620604
621- if self .mode .value != "nuclei" and self .supply_nuclei .value :
605+ if self .mode_v2 .value != "nuclei" and self .supply_nuclei .value :
622606 nuc_image = images .get_image (self .nuclei_image .value )
623607 # CellPose 1-3 expects RGB, we'll have a blank red channel, cells in green and nuclei in blue.
624608 if self .do_3D .value :
@@ -646,8 +630,8 @@ def run(self, workspace):
646630 if self .cellpose_version .value == 'v2' :
647631 assert int (self .cellpose_ver [0 ])<= 2 , "Cellpose version selected in RunCellpose module doesn't match version in Python"
648632 if float (self .cellpose_ver [0 :3 ]) >= 0.6 and int (self .cellpose_ver [0 ])< 2 :
649- if self .mode .value != 'custom' :
650- model = models .Cellpose (model_type = self .mode .value ,
633+ if self .mode_v2 .value != 'custom' :
634+ model = models .Cellpose (model_type = self .mode_v2 .value ,
651635 gpu = self .use_gpu .value )
652636 else :
653637 model_file = self .model_file_name .value
@@ -656,8 +640,8 @@ def run(self, workspace):
656640 model = models .CellposeModel (pretrained_model = model_path , gpu = self .use_gpu .value )
657641
658642 else :
659- if self .mode .value != 'custom' :
660- model = models .CellposeModel (model_type = self .mode .value ,
643+ if self .mode_v2 .value != 'custom' :
644+ model = models .CellposeModel (model_type = self .mode_v2 .value ,
661645 gpu = self .use_gpu .value )
662646 else :
663647 model_file = self .model_file_name .value
@@ -707,26 +691,26 @@ def run(self, workspace):
707691
708692 elif self .cellpose_version .value == 'v3' :
709693 assert int (self .cellpose_ver [0 ])== 3 , "Cellpose version selected in RunCellpose module doesn't match version in Python"
710- if self .mode .value == 'custom' :
694+ if self .mode_v3 .value == 'custom' :
711695 model_file = self .model_file_name .value
712696 model_directory = self .model_directory .get_absolute_path ()
713697 model_path = os .path .join (model_directory , model_file )
714- model_params = (self .mode .value , self .use_gpu .value )
715- LOGGER .info (f"Loading new model: { self .mode .value } " )
716- if self .mode .value in SIZED_MODELS :
698+ model_params = (self .mode_v3 .value , self .use_gpu .value )
699+ LOGGER .info (f"Loading new model: { self .mode_v3 .value } " )
700+ if self .mode_v3 .value in SIZED_MODELS :
717701 self .current_model = models .Cellpose (
718- model_type = self .mode .value , gpu = self .use_gpu .value )
702+ model_type = self .mode_v3 .value , gpu = self .use_gpu .value )
719703 else :
720704 self .current_model = models .CellposeModel (
721- model_type = self .mode .value , gpu = self .use_gpu .value )
705+ model_type = self .mode_v3 .value , gpu = self .use_gpu .value )
722706 self .current_model_params = model_params
723707
724708 if self .denoise .value :
725709 from cellpose import denoise
726710 recon_params = (
727711 self .denoise_type .value ,
728712 self .use_gpu .value ,
729- self .mode .value != "nuclei" and self .supply_nuclei .value
713+ self .mode_v3 .value != "nuclei" and self .supply_nuclei .value
730714 )
731715 self .recon_model = denoise .DenoiseModel (
732716 model_type = recon_params [0 ],
@@ -745,7 +729,7 @@ def run(self, workspace):
745729 elif self .denoise_type .value == "upsample_nuclei" :
746730 diam = 17
747731 # Result only includes input channels
748- if self .mode .value != "nuclei" and self .supply_nuclei .value :
732+ if self .mode_v2 .value != "nuclei" and self .supply_nuclei .value :
749733 channels = [0 , 1 ]
750734 else :
751735 input_data = x_data
@@ -780,6 +764,7 @@ def run(self, workspace):
780764
781765 elif self .cellpose_version .value == 'v4' :
782766 assert int (self .cellpose_ver [0 ])== 4 , "Cellpose version selected in RunCellpose module doesn't match version in Python"
767+ # TODO
783768
784769 if self .remove_edge_masks :
785770 y_data = utils .remove_edge_masks (y_data )
@@ -797,7 +782,7 @@ def run(self, workspace):
797782 os .makedirs (temp_img_dir , exist_ok = True )
798783
799784 temp_img_path = os .path .join (temp_img_dir , unique_name + ".tiff" )
800- if self .mode .value == "custom" :
785+ if self .mode_v2 .value == "custom" :
801786 model_file = self .model_file_name .value
802787 model_directory = self .model_directory .get_absolute_path ()
803788 model_path = os .path .join (model_directory , model_file )
@@ -814,8 +799,8 @@ def run(self, workspace):
814799 if self .use_gpu .value :
815800 cmd += ['--gpus' , 'all' ]
816801 cmd += ['cellpose' , '--verbose' , '--dir' , '/data/img' , '--pretrained_model' ]
817- if self .mode .value != 'custom' :
818- cmd += [self .mode .value ]
802+ if self .mode_v2 .value != 'custom' :
803+ cmd += [self .mode_v2 .value ]
819804 else :
820805 cmd += ['/data/model/' + model_file ]
821806 cmd += ['--chan' , str (channels [0 ]), '--chan2' , str (channels [1 ]), '--diameter' , str (diam )]
@@ -957,7 +942,7 @@ def upgrade_settings(self, setting_values, variable_revision_number, module_name
957942 setting_values = setting_values + ["0.0" , False , "15" , "1.0" , False , False ]
958943 variable_revision_number = 3
959944 if variable_revision_number == 3 :
960- setting_values = [setting_values [0 ]] + ["Python" ,CELLPOSE_DOCKER_IMAGE_WITH_PRETRAINED_v232 ] + setting_values [1 :]
945+ setting_values = [setting_values [0 ]] + ["Python" ,CELLPOSE_DOCKERS [ 'v2' ][ 0 ] ] + setting_values [1 :]
961946 variable_revision_number = 4
962947 if variable_revision_number == 4 :
963948 setting_values = [setting_values [0 ]] + ['No' ] + setting_values [1 :]
0 commit comments