diff --git a/extensions/chaeo/examples/batch_run_patches.py b/extensions/chaeo/examples/batch_run_patches.py index 0c220d72d99d69392771432cde06a8929d7cdfe2..46b5327a4562978adef07d111c602577d9ac7091 100644 --- a/extensions/chaeo/examples/batch_run_patches.py +++ b/extensions/chaeo/examples/batch_run_patches.py @@ -1,3 +1,4 @@ +import json from pathlib import Path import re from time import localtime, strftime @@ -41,18 +42,33 @@ if __name__ == '__main__': continue - result = export_patches_from_multichannel_zstack( - input_zstack_path=where_czi/ff, - px_model=px_model, - pxmap_threshold=0.25, - pixel_class=0, - zmask_channel=0, - patches_channel=4, - where_output=where_output, - mask_type='boxes', - zmask_filters={'area': (1e3, 1e8)}, - zmask_expand_box_by=(128, 0), - ) + export_kwargs = { + 'input_zstack_path': (where_czi / ff).__str__(), + 'px_model': px_model.model_id, + 'pxmap_threshold': 0.25, + 'pixel_class': 0, + 'zmask_channel': 0, + 'patches_channel': 4, + 'where_output': where_output.__str__(), + 'mask_type': 'boxes', + 'zmask_filters': {'area': (1e3, 1e8)}, + 'zmask_expand_box_by': (128, 0), + } + + # result = export_patches_from_multichannel_zstack( + # input_zstack_path=where_czi / ff, + # px_model=px_model, + # pxmap_threshold=0.25, + # pixel_class=0, + # zmask_channel=0, + # patches_channel=4, + # where_output=where_output, + # mask_type='boxes', + # zmask_filters={'area': (1e3, 1e8)}, + # zmask_expand_box_by=(128, 0), + # ) + + result = export_patches_from_multichannel_zstack(**export_kwargs) # parse and record results df = result['dataframe'] @@ -66,4 +82,5 @@ if __name__ == '__main__': write_accessor_data_to_file( where_output / k / (ff.stem + '.tif'), InMemoryDataAccessor(result['interm'][k]) - ) \ No newline at end of file + ) + diff --git a/extensions/chaeo/workflows.py b/extensions/chaeo/workflows.py index 8130414b413876baf026535c69b570e816348dc4..999b533733c961bbc46ca065a92a6763d10b486f 100644 --- a/extensions/chaeo/workflows.py +++ b/extensions/chaeo/workflows.py @@ -12,21 +12,21 @@ from model_server.accessors import generate_file_accessor, InMemoryDataAccessor, from model_server.workflows import Timer def export_patches_from_multichannel_zstack( - input_zstack_path: Path, - px_model: IlastikPixelClassifierModel, + input_zstack_path: str, + px_model_id: str, pxmap_threshold: float, pixel_class: int, zmask_channel: int, patches_channel: int, - where_output: Path, + where_output: str, mask_type: str = 'boxes', zmask_filters: Dict = None, zmask_expand_box_by: int = None, ) -> Dict: ti = Timer() - stack = generate_file_accessor(input_zstack_path) - fstem = input_zstack_path.stem + stack = generate_file_accessor(Path(input_zstack_path)) + fstem = Path(input_zstack_path).stem ti.click('file_input') assert stack.nz > 1, 'Expecting z-stack' @@ -34,11 +34,12 @@ def export_patches_from_multichannel_zstack( mip = InMemoryDataAccessor( stack.get_one_channel_data(channel=0).data.max(axis=-1, keepdims=True) ) + # px_model = pxmap, _ = px_model.infer(mip) ti.click('infer_pixel_probability') write_accessor_data_to_file( - where_output / 'pixel_probabilities' / (fstem + '.tif'), + Path(where_output) / 'pixel_probabilities' / (fstem + '.tif'), pxmap ) ti.click('export_pixel_probability') @@ -61,7 +62,7 @@ def export_patches_from_multichannel_zstack( # export patches files = export_patches_from_zstack( - where_output / '2d_patches', + Path(where_output) / '2d_patches', stack.get_one_channel_data(patches_channel), zmask_meta, prefix=fstem, @@ -78,14 +79,14 @@ def export_patches_from_multichannel_zstack( ) ) write_accessor_data_to_file( - where_output / 'annotated_zstacks' / (fstem + '.tif'), + Path(where_output) / 'annotated_zstacks' / (fstem + '.tif'), annotated ) ti.click('export_annotated_zstack') return { 'pixel_model_id': px_model.model_id, - 'input_filepath': str(input_zstack_path), + 'input_filepath': input_zstack_path, 'number_of_objects': len(zmask_meta), 'success': True, 'timer_results': ti.events,