Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions deepem/data/dataset/multi_zettaset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re

from cloudvolume import CloudVolume, Bbox
from cloudvolume.exceptions import InfoUnavailableError

from zettasets.dataset import Dataset as Zettaset
from zettasets.sample import Sample
Expand Down Expand Up @@ -199,14 +200,26 @@ def convert_array(arr: ArrayLike) -> np.ndarray:
else (0, 0, 0)
)
image_bbox = Bbox(bbox.minpt - xyz_padding, bbox.maxpt + xyz_padding)

# Image
vol = CloudVolume( # pylint: disable=unsubscriptable-object
sample.src_image_path,
mip=resolution,
fill_missing=True,
bounded=False,
)[image_bbox.to_slices()]

# Image: try src_image_path first for backward compatibility,
# fall back to sample's own image volume
try:
if sample.src_image_path is None:
raise ValueError("No src_image_path available")
vol = CloudVolume( # pylint: disable=unsubscriptable-object
sample.src_image_path,
mip=resolution,
fill_missing=True,
bounded=False,
)[image_bbox.to_slices()]
except (InfoUnavailableError, ValueError) as e:
print(f"\tWarning: src_image_path failed ({e}), falling back to sample image volume")
vol = CloudVolume( # pylint: disable=unsubscriptable-object
sample.volumes["image"].cloudpath,
mip=resolution,
fill_missing=True,
bounded=False,
)[image_bbox.to_slices()]
dset["input"] = convert_array(vol) / 255.0
print(f"\tinput: {dset['input'].shape}")

Expand Down
27 changes: 20 additions & 7 deletions deepem/data/dataset/zettaset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from cloudvolume import CloudVolume, Bbox
from cloudvolume.exceptions import InfoUnavailableError
import numpy as np
from numpy.typing import ArrayLike
import re
Expand Down Expand Up @@ -90,13 +91,25 @@ def convert_array(arr: ArrayLike) -> np.ndarray:
)
image_bbox = Bbox(bbox.minpt - xyz_padding, bbox.maxpt + xyz_padding)

# Image
vol = CloudVolume( # pylint: disable=unsubscriptable-object
sample.src_image_path,
mip=resolution,
fill_missing=True,
bounded=False,
)[image_bbox.to_slices()]
# Image: try src_image_path first for backward compatibility,
# fall back to sample's own image volume
try:
if sample.src_image_path is None:
raise ValueError("No src_image_path available")
vol = CloudVolume( # pylint: disable=unsubscriptable-object
sample.src_image_path,
mip=resolution,
fill_missing=True,
bounded=False,
)[image_bbox.to_slices()]
except (InfoUnavailableError, ValueError) as e:
print(f"\tWarning: src_image_path failed ({e}), falling back to sample image volume")
vol = CloudVolume( # pylint: disable=unsubscriptable-object
sample.volumes["image"].cloudpath,
mip=resolution,
fill_missing=True,
bounded=False,
)[image_bbox.to_slices()]
dset["input"] = convert_array(vol)
dset["input"] = (dset["input"] / 255.).astype('float32')
print(f"input: {dset['input'].shape}")
Expand Down