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

Split some HDF5 into util module

parent 68b683fc
No related branches found
No related tags found
No related merge requests found
......@@ -8,41 +8,11 @@ import skimage
import uuid
from extensions.chaeo.accessors import MonoPatchStackFromFile
from extensions.chaeo.h5util import get_dataset_info
from extensions.chaeo.models import PatchStackObjectClassifier
from model_server.accessors import generate_file_accessor, GenericImageDataAccessor, write_accessor_data_to_file
def get_dataset_info(h5: h5py.File, lane : int = 0):
"""
Report out specific datasets in ilastik project file HDF5
:param h5: handle to ilastik project file, as h5py.File object
:param lane: ilastik lane identifier
:return: (dict) selected data values from project file
"""
lns = f'{lane:04d}'
lane = f'Input Data/infos/lane{lns}'
info = {}
for gk in ['Raw Data', 'Segmentation Image']:
info[gk] = {}
for dk in ['location', 'filePath', 'shape', 'nickname']:
try:
info[gk][dk] = h5[f'{lane}/{gk}/{dk}'][()]
except Exception as e:
print(e)
try:
info[gk]['id'] = uuid.UUID(h5[f'{lane}/{gk}/datasetId'][()].decode())
except ValueError as e:
info[gk]['id'] = '<invalid UUID>'
info[gk]['axistags'] = json.loads(h5[f'{lane}/{gk}/axistags'][()].decode())
info[gk]['axes'] = [ax['key'] for ax in info[gk]['axistags']['axes']]
obj_cl_group = h5[f'ObjectClassification/LabelInputs/{lns}']
info['misc'] = {
'number_of_label_inputs': len(obj_cl_group.items())
}
return info
def generate_ilastik_object_classifier(
template_ilp: str,
where: str,
......@@ -180,15 +150,16 @@ def compare_object_maps(truth: GenericImageDataAccessor, inferred: GenericImageD
if __name__ == '__main__':
root = Path('c:/Users/rhodes/projects/proj0011-plankton-seg/')
template_ilp = root / 'exp0014/template_obj.ilp'
where_patch_stack = root / 'exp0009/output/labeled_patches-20231018-0006'
where_patch_stack = root / 'exp0009/output/labeled_patches-20231030-0001'
# auto-populate an object classifier
auto_ilp = generate_ilastik_object_classifier(
template_ilp,
where_patch_stack,
stack_name='train',
proj_name='auto_obj_before'
)
# auto_ilp = generate_ilastik_object_classifier(
# template_ilp,
# where_patch_stack,
# stack_name='train',
# proj_name='auto_obj_before'
# )
auto_ilp = 'auto_obj_before.ilp'
def infer_and_compare_training_set(ilp, suffix):
# infer object labels from the same data used to train the classifier
......
import json
import uuid
import h5py
def get_dataset_info(h5: h5py.File, lane : int = 0):
"""
Report out specific datasets in ilastik project file HDF5
:param h5: handle to ilastik project file, as h5py.File object
:param lane: ilastik lane identifier
:return: (dict) selected data values from project file
"""
lns = f'{lane:04d}'
lane = f'Input Data/infos/lane{lns}'
info = {}
for gk in ['Raw Data', 'Segmentation Image']:
info[gk] = {}
for dk in ['location', 'filePath', 'shape', 'nickname']:
try:
info[gk][dk] = h5[f'{lane}/{gk}/{dk}'][()]
except Exception as e:
print(e)
try:
info[gk]['id'] = uuid.UUID(h5[f'{lane}/{gk}/datasetId'][()].decode())
except ValueError as e:
info[gk]['id'] = '<invalid UUID>'
info[gk]['axistags'] = json.loads(h5[f'{lane}/{gk}/axistags'][()].decode())
info[gk]['axes'] = [ax['key'] for ax in info[gk]['axistags']['axes']]
obj_cl_group = h5[f'ObjectClassification/LabelInputs/{lns}']
info['misc'] = {
'number_of_label_inputs': len(obj_cl_group.items())
}
return info
\ No newline at end of file
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