diff --git a/extensions/chaeo/examples/batch_run_patches.py b/extensions/chaeo/examples/batch_run_patches.py index 46b5327a4562978adef07d111c602577d9ac7091..cebc0b405b28761e8debf5bebd2b0288e9ceb05a 100644 --- a/extensions/chaeo/examples/batch_run_patches.py +++ b/extensions/chaeo/examples/batch_run_patches.py @@ -6,7 +6,6 @@ from time import localtime, strftime import pandas as pd from extensions.chaeo.workflows import export_patches_from_multichannel_zstack -from extensions.ilastik.models import IlastikPixelClassifierModel from model_server.accessors import InMemoryDataAccessor, write_accessor_data_to_file if __name__ == '__main__': @@ -27,9 +26,6 @@ if __name__ == '__main__': csv_args = {'mode': 'w', 'header': True} # when creating file px_ilp = Path.home() / 'model-server' / 'ilastik' / 'AF405-bodies_boundaries.ilp' - px_model = IlastikPixelClassifierModel( - params={'project_file': px_ilp} - ) for ff in where_czi.iterdir(): pattern = 'Selection--W([\d]+)--P([\d]+)-T([\d]+)' @@ -41,10 +37,9 @@ if __name__ == '__main__': if int(ma.groups()[1]) > 10: # skip second half of set continue - export_kwargs = { 'input_zstack_path': (where_czi / ff).__str__(), - 'px_model': px_model.model_id, + 'ilastik_project_file': px_ilp.__str__(), 'pxmap_threshold': 0.25, 'pixel_class': 0, 'zmask_channel': 0, @@ -55,19 +50,6 @@ if __name__ == '__main__': '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 @@ -75,6 +57,7 @@ if __name__ == '__main__': df['filename'] = ff.name df.to_csv(where_output / 'df_objects.csv', **csv_args) pd.DataFrame(result['timer_results'], index=[0]).to_csv(where_output / 'timer_results.csv', **csv_args) + pd.json_normalize(export_kwargs).to_csv(where_output / 'workflow_params.csv', **csv_args) csv_args = {'mode': 'a', 'header': False} # append to CSV from here on # export intermediate data if flagged @@ -82,5 +65,4 @@ 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 999b533733c961bbc46ca065a92a6763d10b486f..a47986f8b480bf6092b87f73191b52fde36521d4 100644 --- a/extensions/chaeo/workflows.py +++ b/extensions/chaeo/workflows.py @@ -1,9 +1,6 @@ from pathlib import Path from typing import Dict -from pydantic import BaseModel - - from extensions.ilastik.models import IlastikPixelClassifierModel from extensions.chaeo.annotators import draw_boxes_on_3d_image from extensions.chaeo.products import export_patches_from_zstack @@ -13,7 +10,7 @@ from model_server.workflows import Timer def export_patches_from_multichannel_zstack( input_zstack_path: str, - px_model_id: str, + ilastik_project_file: str, pxmap_threshold: float, pixel_class: int, zmask_channel: int, @@ -34,7 +31,9 @@ def export_patches_from_multichannel_zstack( mip = InMemoryDataAccessor( stack.get_one_channel_data(channel=0).data.max(axis=-1, keepdims=True) ) - # px_model = + px_model = IlastikPixelClassifierModel( + params={'project_file': Path(ilastik_project_file)} + ) pxmap, _ = px_model.infer(mip) ti.click('infer_pixel_probability')