Skip to content

Commit 5575517

Browse files
committed
draft efficient mask tiling
1 parent 50c498e commit 5575517

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pathml/core/slide_data.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ def generate_tiles(self, shape=3000, stride=None, pad=False, level=0):
133133
n_chunk_i = (i - shape[0]) // stride_i + 1
134134
n_chunk_j = (j - shape[1]) // stride_j + 1
135135

136+
'''
137+
# TODO: check if this keeps order?
138+
coordinates = np.array([(x*stride_i,y*stride_j) for x in range(n_chunk_i) for y in range(n_chunk_j)])
139+
for mask in self.masks.h5managers.h5['masks'].keys():
140+
m = self.masks[mask]
141+
first = np.array_split(m, axis=0)
142+
masktiles = []
143+
for outs in first:
144+
second.append(np.array_split(outs, axis=1))
145+
masks = {mask : second}
146+
'''
147+
136148
for ix_i in range(n_chunk_i):
137149
for ix_j in range(n_chunk_j):
138150
coords = (int(ix_j * stride_j), int(ix_i * stride_i))

pathml/datasets/peso.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from pathml.core.slide_classes import HESlide
1717
from pathml.core.masks import Masks
1818

19+
import cProfile
20+
import pstats
21+
1922
class PesoDataModule(BaseDataModule):
2023
def __init__(self,
2124
data_dir,
@@ -67,6 +70,10 @@ def _download_peso(self, download_dir):
6770
for trainingwsifolder in trainingwsifolders:
6871
for file in os.listdir(Path(download_dir)/Path(trainingwsifolder)):
6972
if file.endswith('.tif'):
73+
74+
profile = cProfile.Profile()
75+
profile.enable()
76+
7077
name = '_'.join(file.split('_')[:-1])
7178
maskpath = Path(name+'_HE_training_mask.tif')
7279
mask = HESlide(filepath = str(Path(download_dir)/Path('peso_training_masks')/maskpath), name = name)
@@ -85,7 +92,10 @@ def _download_peso(self, download_dir):
8592
threshold = 30, outer_contours_only = True)
8693
])
8794
# TODO: choose tile size
88-
wsi.run(pipeline, tile_size=3000)
95+
wsi.run(pipeline, tile_size=250)
96+
profile.disable()
97+
ps = pstats.Stats(profile)
98+
ps.print_stats()
8999
wsi.write(str(Path(download_dir)/Path('h5')/Path(name+'.h5')))
90100
os.remove(str(Path(download_dir)/Path(traininwsifolder)/Path(file)))
91101
os.remove(str(Path(download_dir)/Path('peso_training_masks')/maskpath))

0 commit comments

Comments
 (0)