Skip to content

Commit 87539a9

Browse files
Merge pull request #13 from mlexchange/create_seg_tiled_container
Create Seg Tiled Container
2 parents b3c6fb5 + 3af17ed commit 87539a9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/seg_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ def train_segmentation(
258258
live.next_step()
259259

260260
print(f'Epoch: {epoch}')
261+
262+
# Note: This is a very temporary solution to address the single frame mask case.
263+
if validationloader is None:
264+
F1_val_micro = None
265+
F1_val_macro = None
266+
261267
table = save_loss(
262268
validationloader,
263269
savepath,

src/utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from tiled.client import from_uri
33
from tiled.structures.array import ArrayStructure
44
import numpy as np
5+
from urllib.parse import urlparse, urlunparse
56

67
# Create directory
78
def create_directory(path):
@@ -11,6 +12,24 @@ def create_directory(path):
1112
else:
1213
print(f"Local directory '{path}' already exsists.")
1314

15+
def ensure_parent_containers(tiled_uri, tiled_api_key):
16+
parsed_url = urlparse(tiled_uri)
17+
path = parsed_url.path
18+
# Splitting path into parts
19+
path_parts = path.split('/')[1:] # Split and remove the first empty element
20+
root_path = '/'.join(path_parts[:3])
21+
tiled_root = urlunparse((parsed_url.scheme, parsed_url.netloc, root_path,
22+
parsed_url.params, parsed_url.query, parsed_url.fragment))
23+
24+
last_container = from_uri(tiled_root, api_key=tiled_api_key)
25+
26+
for part in path_parts:
27+
if part in last_container.keys():
28+
last_container = last_container[part]
29+
else:
30+
last_container = last_container.create_container(key=part)
31+
return last_container
32+
1433

1534
# Tiled Saving
1635
def allocate_array_space(
@@ -22,7 +41,11 @@ def allocate_array_space(
2241
array_name,
2342
):
2443

25-
last_container = from_uri(seg_tiled_uri, api_key=seg_tiled_api_key)
44+
45+
last_container = ensure_parent_containers(seg_tiled_uri, seg_tiled_api_key)
46+
47+
assert uid not in last_container.keys(), f'uid_save: {uid} already existed in Tiled Server'
48+
2649
last_container = last_container.create_container(key=uid)
2750
array_shape = tiled_dataset.mask_client.shape if tiled_dataset.mask_client else tiled_dataset.data_client.shape
2851
structure = ArrayStructure.from_array(np.zeros(array_shape,dtype=np.int8))

0 commit comments

Comments
 (0)