Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SlideData to use existing h5path files #337

Open
wants to merge 22 commits into
base: load-data-in-workers
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Store masks as bools
  • Loading branch information
tddough98 committed Oct 4, 2022
commit cab0409c8dddeb3ee41dcc1248b7f9d64044768b
6 changes: 5 additions & 1 deletion pathml/core/h5managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ def add_tile(self, tile):
self.h5["tiles"][str(tile.coords)]["masks"].create_dataset(
str(key),
data=mask,
dtype="float16",
chunks=True,
compression="gzip",
compression_opts=9, # masks should be highly compressible
shuffle=True,
dtype="bool",
)

# add coords
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_HE_tile():
im_np_rgb = cv2.cvtColor(im_np, cv2.COLOR_RGBA2RGB)
# make mask object
masks = np.random.randint(
low=1, high=255, size=(im_np_rgb.shape[0], im_np_rgb.shape[1]), dtype=np.uint8
low=0, high=1, size=(im_np_rgb.shape[0], im_np_rgb.shape[1]), dtype=bool
)
masks = {"testmask": masks}
# labels dict
Expand Down Expand Up @@ -74,7 +74,7 @@ def tileVectra():

# make mask object
masks = np.random.randint(
low=1, high=255, size=(region.shape[0], region.shape[1]), dtype=np.uint8
low=0, high=1, size=(region.shape[0], region.shape[1]), dtype=bool
)
masks = {"testmask": masks}

Expand Down
4 changes: 2 additions & 2 deletions tests/core_tests/test_h5managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def test_tile_dtype_HE(tileHE):
slidedata.tiles.add(tileHE)
tile_retrieved = slidedata.tiles[tileHE.coords]
assert tile_retrieved.image.dtype == np.float16
assert tile_retrieved.masks["testmask"].dtype == np.float16
assert tile_retrieved.masks["testmask"].dtype == bool


def test_tile_dtype_IF(tileVectra, vectra_slide):
"""make sure that retrieved tiles and corresponding masks are float16"""
vectra_slide.tiles.add(tileVectra)
tile_retrieved = vectra_slide.tiles[tileVectra.coords]
assert tile_retrieved.image.dtype == np.float16
assert tile_retrieved.masks["testmask"].dtype == np.float16
assert tile_retrieved.masks["testmask"].dtype == bool