Skip to content
Snippets Groups Projects
Commit 986066a0 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Moved project file into model.params; removed autogeneration of segmentation...

Moved project file into model.params; removed autogeneration of segmentation model from pixel predictions model
parent 93d843b5
Branches
Tags
2 merge requests!50Release 2024.06.03,!42Models are now initialized with pydantic models
......@@ -22,13 +22,13 @@ class IlastikModel(Model):
:param enforce_embedded:
raise an error if all input data are not embedded in the project file, i.e. on the filesystem
"""
self.project_file = Path(params['project_file'])
self.params = params
pf = Path(params['project_file'])
self.enforce_embedded = enforce_embedded
params['project_file'] = self.project_file.__str__()
if self.project_file.is_absolute():
pap = self.project_file
if pf.is_absolute():
pap = pf
else:
pap = model_server.extensions.ilastik.conf.paths['project_files'] / self.project_file
pap = model_server.extensions.ilastik.conf.paths['project_files'] / pf
self.project_file_abspath = pap
if not pap.exists():
raise FileNotFoundError(f'Project file does not exist: {pap}')
......@@ -62,7 +62,7 @@ class IlastikModel(Model):
assert True
if not isinstance(shell.workflow, self.get_workflow()):
raise ParameterExpectedError(
f'Ilastik project file {self.project_file} does not describe an instance of {self.__class__}'
f'Ilastik project file {self.project_file_abspath} does not describe an instance of {self.__class__}'
)
self.shell = shell
......@@ -300,27 +300,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 = mask._derived_accessor(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):
pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment