Newer
Older

Christopher Randolph Rhodes
committed
def main(request_func, in_abspath, params):
"""
Execute a sequence of client requests that load ilastik pixel and object classifiers, then infer on an image file
:param request_func: (func) function that implements HTTP client, dependent on which environment request are called from
:param in_abspath: (str) absolute path to image file to infer
:param params:
pixel_classifier_path: (str) absolute path to ilastik project file that defines a pixel classifier
object_classifier_path: (str) absolute path to ilastik project file that defines an object classifier
channel (optional): (int) channel of the input image to process, use all channels if not specified
:return: (str) absolute path where a new object map is written
"""

Christopher Randolph Rhodes
committed
where = dirname(in_abspath)
in_file = basename(in_abspath)
px_ilp = params['pixel_classifier_path']
ob_ilp = params['object_classifier_path']

Christopher Randolph Rhodes
committed
channel = params.get('channel', None)
mip = params.get('mip', False)

Christopher Randolph Rhodes
committed
# configure input and output paths
resp = request_func(
'PUT',

Christopher Randolph Rhodes
committed
'/paths/watch_input',
{
'path': where,
}
)
assert resp['status'] == 200, 'Error setting up image directory'

Christopher Randolph Rhodes
committed
resp = request_func(
'PUT',
'/paths/watch_output',
{
'path': where,
}
)
assert resp['status'] == 200, 'Error setting up image directory'
# load pixel classifier
resp = request_func(
'PUT',
'/ilastik/seg/load/',
body={
'project_file': px_ilp,
'duplicate': False,
},
)

Christopher Randolph Rhodes
committed
assert resp['status'], 'Error loading classifier: ' + px_ilp
id_px_mod = resp['content']['model_id']
# load object classifier
resp = request_func(
'PUT', '/ilastik/pxmap_to_obj/load/',
body={
'project_file': ob_ilp,
'duplicate': False,
},
)
assert resp['status'] == 200, 'Error loading object classifier: ' + {ob_ilp}
id_ob_mod = resp['content']['model_id']
# run inference
resp = request_func(
'PUT',
'/ilastik/pixel_then_object_classification/infer',
{
'px_model_id': id_px_mod,
'ob_model_id': id_ob_mod,
'input_filename': in_file,
'channel': channel,

Christopher Randolph Rhodes
committed
'mip': mip,

Christopher Randolph Rhodes
committed
)
assert resp['status'] == 200, 'Error calling workfow'
return resp['content']['object_map_filepath']