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

Harmonized unit index of object class

parent 68f0f8a9
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,8 @@ from extensions.ilastik.models import IlastikObjectClassifierModel ...@@ -10,6 +10,8 @@ from extensions.ilastik.models import IlastikObjectClassifierModel
def transfer_labels_to_ilastik_ilp(ilp, df_stack_meta): def transfer_labels_to_ilastik_ilp(ilp, df_stack_meta):
with h5py.File(ilp, 'r+') as h5: with h5py.File(ilp, 'r+') as h5:
# TODO: force make copy if ilp file starts with template_
# TODO: enforce somehow that zstack and df_stack_meta are from same export run
where_out = Path(ilp).parent where_out = Path(ilp).parent
# export complete HDF5 tree # export complete HDF5 tree
...@@ -34,12 +36,12 @@ def transfer_labels_to_ilastik_ilp(ilp, df_stack_meta): ...@@ -34,12 +36,12 @@ def transfer_labels_to_ilastik_ilp(ilp, df_stack_meta):
la_old = ds[1] la_old = ds[1]
# unit index, i.e. reserve 1 for no object # unit index, i.e. reserve 1 for no object
ds[1] = float(1 + df_stack_meta.loc[df_stack_meta.zi == idx, 'annotation_class_id'].iat[0]) ds[1] = float(df_stack_meta.loc[df_stack_meta.zi == idx, 'annotation_class_id'].iat[0])
print(f'Changed label {ti} from {la_old} to {ds[1]}') print(f'Changed label {ti} from {la_old} to {ds[1]}')
if __name__ == '__main__': if __name__ == '__main__':
ilp = 'c:/Users/rhodes/model-server/ilastik/test_autolabel_obj.ilp' ilp = 'c:/Users/rhodes/model-server/ilastik/test_autolabel_obj.ilp'
df = pd.read_csv( df = pd.read_csv(
'c:/Users/rhodes/projects/proj0011-plankton-seg/exp0009/output/labeled_patches-20231013-0022/training_stack.csv' 'c:/Users/rhodes/projects/proj0011-plankton-seg/exp0009/output/labeled_patches-20231014-0002/train_stack.csv'
) )
transfer_labels_to_ilastik_ilp(ilp, df) transfer_labels_to_ilastik_ilp(ilp, df)
\ No newline at end of file
...@@ -205,7 +205,7 @@ def transfer_ecotaxa_labels_to_patch_stacks( ...@@ -205,7 +205,7 @@ def transfer_ecotaxa_labels_to_patch_stacks(
) )
) )
df_labels = pd.DataFrame({ df_labels = pd.DataFrame({
'annotation_class_id': df_split.index, 'annotation_class_id': df_split.index + 1,
'hierarchy': se_unique, 'hierarchy': se_unique,
'annotation_class': df_split.loc[:, 1].str.lower() 'annotation_class': df_split.loc[:, 1].str.lower()
}) })
...@@ -241,7 +241,7 @@ def transfer_ecotaxa_labels_to_patch_stacks( ...@@ -241,7 +241,7 @@ def transfer_ecotaxa_labels_to_patch_stacks(
# export patches as z-stacks # export patches as z-stacks
for (dfk, dfv) in {'train': df_tr, 'test': df_te}.items(): for (dfk, dfv) in {'train': df_tr, 'test': df_te}.items():
zstack_keys = ['mask', 'label', 'raw'] zstack_keys = ['mask', 'label', 'raw']
zstacks = {f'{dfk}_{zsk}': np.zeros((*patch_size, 1, len(df_tr)), dtype='uint8') for zsk in zstack_keys} zstacks = {f'{dfk}_{zsk}': np.zeros((*patch_size, 1, len(dfv)), dtype='uint8') for zsk in zstack_keys}
stack_meta = [] stack_meta = []
for fi, pl in enumerate(dfv.itertuples(name='PatchFile')): for fi, pl in enumerate(dfv.itertuples(name='PatchFile')):
fn = pl._asdict()['patch_filename'] fn = pl._asdict()['patch_filename']
......
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