Skip to content

Commit

Permalink
Merge pull request #13 from mlexchange/create_seg_tiled_container
Browse files Browse the repository at this point in the history
Create Seg Tiled Container
  • Loading branch information
dylanmcreynolds authored Mar 9, 2024
2 parents b3c6fb5 + 3af17ed commit 87539a9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/seg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 24 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, urlunparse

# Create directory
def create_directory(path):
Expand All @@ -11,6 +12,24 @@ 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
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:
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(
Expand All @@ -22,7 +41,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))
Expand Down

0 comments on commit 87539a9

Please sign in to comment.