From 5aca68af4c6ca5d8ba29b2ecc7253889b44cdc43 Mon Sep 17 00:00:00 2001 From: Christopher Rhodes <christopher.rhodes@embl.de> Date: Wed, 18 Oct 2023 14:54:05 +0200 Subject: [PATCH] Needed to make copy of project file --- ...fer_labels_to_ilastik_object_classifier.py | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) 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 a02840be..f3b5a5bc 100644 --- a/extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py +++ b/extensions/chaeo/examples/transfer_labels_to_ilastik_object_classifier.py @@ -203,7 +203,7 @@ 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-0000' + where_patch_stack = root / 'exp0009/output/labeled_patches-20231018-0001' # auto-populate an object classifier new_ilp = generate_ilastik_object_classifier( @@ -212,11 +212,11 @@ if __name__ == '__main__': stack_name='train' ) - def infer_and_compare(suffix): + def infer_and_compare(ilp, suffix): # infer object labels from the same data used to train the classifier train_zstack_raw = generate_file_accessor(where_patch_stack / 'zstack_train_raw.tif') train_zstack_mask = generate_file_accessor(where_patch_stack / 'zstack_train_mask.tif') - mod = PatchStackObjectClassifier({'project_file': where_patch_stack / new_ilp}) + mod = PatchStackObjectClassifier({'project_file': where_patch_stack / ilp}) result_acc, _ = mod.infer(train_zstack_raw, train_zstack_mask) write_accessor_data_to_file(where_patch_stack / f'zstack_train_result_{suffix}.tif', result_acc) @@ -229,17 +229,22 @@ if __name__ == '__main__': ), index=False ) + print(f'Generated ilastik project {ilp}') print('Truth and inferred labels match?') print(pd.value_counts(df_comp['truth_label'] == df_comp['inferred_label'])) # infer object labels from the same data used to train the classifier - infer_and_compare('before') + infer_and_compare(new_ilp, 'before') - # prompt user input when ilastik file has been modified in-app - print(f'Press enter when project file {new_ilp} has been updated in ilastik') + # copy project and prompt user input once ilastik file has been modified in-app + mod_ilp = shutil.copy( + new_ilp, + where_patch_stack / autonumber_new_file(where_patch_stack, 'auto-obj', 'ilp') + ) + print(f'Press enter when project file {mod_ilp} has been updated in ilastik') input() - # repeat inference with the same project file, but a fresh model handle - infer_and_compare('after') + # repeat inference with the modified project file + infer_and_compare(mod_ilp, 'after') -- GitLab