From e2b759e42a862312e66ac16fffdbd911d5d44eae Mon Sep 17 00:00:00 2001 From: Christopher Rhodes <christopher.rhodes@embl.de> Date: Wed, 17 Apr 2024 12:31:51 +0200 Subject: [PATCH] Disabled generation of ilastik object model that receives segmentation masks from one that receives pixel probabilities; this was causing inaccurate results --- model_server/extensions/ilastik/models.py | 20 ------------------- .../extensions/ilastik/tests/test_ilastik.py | 16 --------------- 2 files changed, 36 deletions(-) diff --git a/model_server/extensions/ilastik/models.py b/model_server/extensions/ilastik/models.py index af3b1edc..90edcec5 100644 --- a/model_server/extensions/ilastik/models.py +++ b/model_server/extensions/ilastik/models.py @@ -266,26 +266,6 @@ class IlastikObjectClassifierFromPixelPredictionsModel(IlastikModel, ImageToImag obmap, _ = self.infer(img, mask) return obmap - def make_instance_segmentation_model(self, px_ch: int): - """ - Generate an instance segmentation model, i.e. one that takes binary masks instead of pixel probabilities as a - second input. - :param px_ch: channel of pixel probability map to use - :return: - InstanceSegmentationModel object - """ - class _Mod(self.__class__, InstanceSegmentationModel): - def label_instance_class( - self, img: GenericImageDataAccessor, mask: GenericImageDataAccessor, **kwargs - ) -> GenericImageDataAccessor: - if mask.dtype == 'bool': - norm_mask = 1.0 * mask.data - else: - norm_mask = mask.data / np.iinfo(mask.dtype).max - norm_mask_acc = InMemoryDataAccessor(norm_mask.astype('float32')) - return super().label_instance_class(img, norm_mask_acc, pixel_classification_channel=px_ch) - return _Mod(params={'project_file': self.project_file}) - class Error(Exception): diff --git a/model_server/extensions/ilastik/tests/test_ilastik.py b/model_server/extensions/ilastik/tests/test_ilastik.py index a30c4cba..7a3a9c38 100644 --- a/model_server/extensions/ilastik/tests/test_ilastik.py +++ b/model_server/extensions/ilastik/tests/test_ilastik.py @@ -163,22 +163,6 @@ class TestIlastikPixelClassification(unittest.TestCase): ) self.assertEqual(objmap.data.max(), 2) - def test_make_seg_obj_model_from_pxmap_obj(self): - self.test_run_pixel_classifier() - fp = czifile['path'] - pxmap_model = ilm.IlastikObjectClassifierFromPixelPredictionsModel( - {'project_file': ilastik_classifiers['pxmap_to_obj']} - ) - seg_model = pxmap_model.make_instance_segmentation_model(px_ch=0) - objmap = seg_model.label_instance_class(self.mono_image, self.mask) - - self.assertTrue( - write_accessor_data_to_file( - output_path / f'obmap_seg_from_pxmap_{fp.stem}.tif', - objmap, - ) - ) - self.assertEqual(objmap.data.max(), 2) def test_run_object_classifier_from_segmentation(self): self.test_run_pixel_classifier() -- GitLab