From cf331d8951b823c536ca53596ad6c52eba33cdc7 Mon Sep 17 00:00:00 2001 From: TibbersHao Date: Fri, 8 Mar 2024 16:14:12 -0800 Subject: [PATCH 1/3] added temporary code to save single mask case --- src/seg_utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/seg_utils.py b/src/seg_utils.py index 8702c6b..ef10815 100644 --- a/src/seg_utils.py +++ b/src/seg_utils.py @@ -258,6 +258,12 @@ def train_segmentation( live.next_step() print(f'Epoch: {epoch}') + + # Note: This is a very temporary solution to address the single frame mask case. + if validationloader is None: + F1_val_micro = None + F1_val_macro = None + table = save_loss( validationloader, savepath, From 114a3380acff05dfac7496c9aaa027c22d59be7f Mon Sep 17 00:00:00 2001 From: TibbersHao Date: Fri, 8 Mar 2024 16:15:01 -0800 Subject: [PATCH 2/3] added functionality to validate seg_tiled_uri containers and create new if not existed --- src/utils.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/utils.py b/src/utils.py index c574448..8ea37e1 100644 --- a/src/utils.py +++ b/src/utils.py @@ -2,6 +2,7 @@ from tiled.client import from_uri from tiled.structures.array import ArrayStructure import numpy as np +from urllib.parse import urlparse # Create directory def create_directory(path): @@ -11,6 +12,21 @@ def create_directory(path): else: print(f"Local directory '{path}' already exsists.") +def ensure_parent_containers(tiled_uri, tiled_api_key): + parsed_url = urlparse(tiled_uri) + path = parsed_url.path + # Splitting path into parts + path_parts = path.split('/')[1:] # Split and remove the first empty element + tiled_root = f'{parsed_url.scheme}://{parsed_url.netloc}/{path_parts[0]}/{path_parts[1]}/{path_parts[2]}' + last_container = from_uri(tiled_root, api_key=tiled_api_key) + + for part in path_parts: + if part in last_container.keys(): + last_container = last_container[part] + else: + last_container = last_container.create_container(key=part) + return last_container + # Tiled Saving def allocate_array_space( @@ -22,7 +38,11 @@ def allocate_array_space( array_name, ): - last_container = from_uri(seg_tiled_uri, api_key=seg_tiled_api_key) + + last_container = ensure_parent_containers(seg_tiled_uri, seg_tiled_api_key) + + assert uid not in last_container.keys(), f'uid_save: {uid} already existed in Tiled Server' + last_container = last_container.create_container(key=uid) array_shape = tiled_dataset.mask_client.shape if tiled_dataset.mask_client else tiled_dataset.data_client.shape structure = ArrayStructure.from_array(np.zeros(array_shape,dtype=np.int8)) From 3af17ede2b40eae92cee74074470ba74b0b559e8 Mon Sep 17 00:00:00 2001 From: TibbersHao Date: Fri, 8 Mar 2024 17:14:49 -0800 Subject: [PATCH 3/3] changed to urlunparse for url stitching --- src/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils.py b/src/utils.py index 8ea37e1..adfa151 100644 --- a/src/utils.py +++ b/src/utils.py @@ -2,7 +2,7 @@ from tiled.client import from_uri from tiled.structures.array import ArrayStructure import numpy as np -from urllib.parse import urlparse +from urllib.parse import urlparse, urlunparse # Create directory def create_directory(path): @@ -17,7 +17,10 @@ def ensure_parent_containers(tiled_uri, tiled_api_key): path = parsed_url.path # Splitting path into parts path_parts = path.split('/')[1:] # Split and remove the first empty element - tiled_root = f'{parsed_url.scheme}://{parsed_url.netloc}/{path_parts[0]}/{path_parts[1]}/{path_parts[2]}' + root_path = '/'.join(path_parts[:3]) + tiled_root = urlunparse((parsed_url.scheme, parsed_url.netloc, root_path, + parsed_url.params, parsed_url.query, parsed_url.fragment)) + last_container = from_uri(tiled_root, api_key=tiled_api_key) for part in path_parts: