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

Raise error if ilastik data not embedded in project file; but it appears that...

Raise error if ilastik data not embedded in project file; but it appears that most test classifiers fail this
parent 13915f25
No related branches found
No related tags found
2 merge requests!16Completed (de)serialization of RoiSet,!5Resolve "ilastik models do not validate dimensionality of input data"
This commit is part of merge request !5. Comments created here will be created in the context of that merge request.
......@@ -12,8 +12,17 @@ from model_server.base.models import Model, ImageToImageModel, InstanceSegmentat
class IlastikModel(Model):
def __init__(self, params, autoload=True):
def __init__(self, params, autoload=True, enforce_embedded=True):
"""
Base class for models that run via ilastik shell API
:param params:
project_file: path to ilastik project file
:param autoload: automatically load model into memory if true
: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.enforce_embedded = enforce_embedded
params['project_file'] = self.project_file.__str__()
if self.project_file.is_absolute():
pap = self.project_file
......@@ -42,6 +51,15 @@ class IlastikModel(Model):
args.project = self.project_file_abspath.__str__()
shell = app.main(args, init_logging=False)
# validate if inputs are embedded in project file
input_groups = shell.projectManager.currentProjectFile['Input Data']['infos']
lanes = input_groups.keys()
for ll in lanes:
input_types = input_groups[ll]
for tt in input_types:
ds_loc = input_groups[ll][tt].get('location', False)
if self.enforce_embedded and ds_loc and ds_loc[()] == b'FileSystem':
raise IlastikInputEmbedding('Cannot load ilastik project file where inputs are on filesystem')
if not isinstance(shell.workflow, self.get_workflow()):
raise ParameterExpectedError(
f'Ilastik project file {self.project_file} does not describe an instance of {shell.workflow.__class__}'
......@@ -216,4 +234,10 @@ class PatchStackObjectClassifier(IlastikObjectClassifierFromSegmentationModel):
[0, 4, 1, 2, 3]
)
return PatchStack(data=pyxcz), {'success': True}
\ No newline at end of file
return PatchStack(data=pyxcz), {'success': True}
class Error(Exception):
pass
class IlastikInputEmbedding(Error):
pass
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment