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

Batch runner passes only JSON-normalized data to workflow, and saves this to CSV for each iteration

parent 50eb5c6e
No related branches found
No related tags found
No related merge requests found
......@@ -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
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')
......
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