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

Trying to test with batch operation but currently these do not involve object classification

parent 23b903d7
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,8 @@ from pathlib import Path
from model_server.util import autonumber_new_directory, get_matching_files, loop_workflow
from extensions.chaeo.ecotaxa import write_ecotaxa_tsv_chunked_subdirectories
from extensions.chaeo.workflows import export_patches_from_multichannel_zstack
from extensions.chaeo.params import ZMaskExportParams
from extensions.chaeo.workflows import infer_object_map_from_zstack
from extensions.ilastik.models import IlastikPixelClassifierModel
......@@ -17,6 +18,23 @@ if __name__ == '__main__':
px_ilp = Path('c:/Users/rhodes/projects/proj0011-plankton-seg/exp0017/pxAF405_dim8bit.ilp').__str__()
export_params = {
'pixel_probabilities': True,
# 'patches_3d': {},
'patches_2d_for_training': {
# 'draw_bounding_box': False,
},
'patches_2d_for_annotation': {
'draw_bounding_box': True,
'rgb_overlay_channels': (1, None, None),
'rgb_overlay_weights': (0.2, 1.0, 1.0),
},
'annotated_z_stack': {
'draw_label': True
}
}
ZMaskExportParams(**export_params)
params = {
'pxmap_threshold': 0.25,
'pxmap_foreground_channel': 0,
......@@ -26,17 +44,19 @@ if __name__ == '__main__':
'zmask_type': 'boxes',
'zmask_filters': {'area': (1e3, 1e8)},
'zmask_expand_box_by': (128, 3),
'export_pixel_probabilities': True,
'export_2d_patches_for_training': True,
'draw_bounding_box_on_2d_patch': True,
'export_2d_patches_for_annotation': True,
'export_3d_patches': False,
'export_annotated_zstack': True,
'export_patch_masks': True,
'zmask_clip': 0.01,
'rgb_overlay_channels': (1, None, None),
'rgb_overlay_weights': (0.2, 1.0, 1.0),
'draw_label_on_zstack': True,
# 'export_pixel_probabilities': True,
# 'export_2d_patches_for_training': True,
# 'draw_bounding_box_on_2d_patch': True,
# 'export_2d_patches_for_annotation': True,
# 'export_3d_patches': False,
# 'export_annotated_zstack': True,
# 'export_patch_masks': True,
# 'rgb_overlay_channels': (1, None, None),
# 'rgb_overlay_weights': (0.2, 1.0, 1.0),
# 'draw_label_on_zstack': True,
'exports': ZMaskExportParams(**export_params),
}
input_files = get_matching_files(where_czi, 'czi', coord_filter={})
......@@ -44,7 +64,7 @@ if __name__ == '__main__':
loop_workflow(
input_files,
where_output,
export_patches_from_multichannel_zstack,
infer_object_map_from_zstack,
[IlastikPixelClassifierModel(params={'project_file': Path(px_ilp)})],
params,
catch_and_continue=False,
......
......@@ -8,7 +8,7 @@ class PatchParams(BaseModel):
draw_mask: bool = False
rescale_clip: float = 0.001
focus_metric: str = 'max_sobel'
rgb_overlay_channels: List[int] = (None, None, None),
rgb_overlay_channels: List[Union[int, None]] = (None, None, None),
rgb_overlay_weights: List[float] = (1.0, 1.0, 1.0)
class AnnotatedZStackParams(BaseModel):
......
......@@ -317,6 +317,7 @@ def infer_object_map_from_zstack(
**kwargs
)
# TODO: make this a method of ZMaskObjectTable class
# extract masks
patch_masks_acc = get_patch_masks_from_zmask_meta(
stack,
......@@ -324,6 +325,7 @@ def infer_object_map_from_zstack(
**kwargs
)
# TODO: add ZMaskObjectTable method to apply object classification results as new DataFrame column
# send patches and mask stacks to object classifier
result_acc, _ = object_classifier.infer(patches_acc, patch_masks_acc)
......@@ -341,6 +343,7 @@ def infer_object_map_from_zstack(
output_map[labels_map == object_id] = object_class
meta.append({'object_id': ii, 'object_class': object_id})
# TODO: add ZMaskObjectTable method to export object map
output_path = Path(output_folder_path) / ('obj_classes_' + (fstem + '.tif'))
write_accessor_data_to_file(
output_path,
......
......@@ -30,7 +30,8 @@ class ZMaskObjectTable(object):
filters=filters,
mask_type=mask_type,
expand_box_by=expand_box_by
)
) # currently, some methods can add columns to self.df
self.acc_raw = acc_raw
self.count = len(self.zmask_meta)
......
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