diff --git a/extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py b/extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py index 8b8f16de9d9ae33a2fd516f0f375abe413aa30a3..9d5c273e7191b384d693758aba05ba903ea82e58 100644 --- a/extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py +++ b/extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py @@ -10,6 +10,8 @@ from extensions.ilastik.models import IlastikObjectClassifierModel def transfer_labels_to_ilastik_ilp(ilp, df_stack_meta): 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 # export complete HDF5 tree @@ -34,12 +36,12 @@ def transfer_labels_to_ilastik_ilp(ilp, df_stack_meta): la_old = ds[1] # 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]}') if __name__ == '__main__': ilp = 'c:/Users/rhodes/model-server/ilastik/test_autolabel_obj.ilp' 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) \ No newline at end of file diff --git a/extensions/chaeo/workflows.py b/extensions/chaeo/workflows.py index 1a1ef8ce61662e1caf7fa7f2affe110b8271bfcc..4d7e0ccd176a04d7d79083c8041d937410914172 100644 --- a/extensions/chaeo/workflows.py +++ b/extensions/chaeo/workflows.py @@ -205,7 +205,7 @@ def transfer_ecotaxa_labels_to_patch_stacks( ) ) df_labels = pd.DataFrame({ - 'annotation_class_id': df_split.index, + 'annotation_class_id': df_split.index + 1, 'hierarchy': se_unique, 'annotation_class': df_split.loc[:, 1].str.lower() }) @@ -241,7 +241,7 @@ def transfer_ecotaxa_labels_to_patch_stacks( # export patches as z-stacks for (dfk, dfv) in {'train': df_tr, 'test': df_te}.items(): 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 = [] for fi, pl in enumerate(dfv.itertuples(name='PatchFile')): fn = pl._asdict()['patch_filename']