Skip to content

Commit

Permalink
When chunk the images, release mem after each run
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Milk committed Dec 1, 2023
1 parent fd8b996 commit 3480aec
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lazyslide/wsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ def create_tissue_mask(self, name="tissue", level=0,
row_mask = []
for ixs in row:
h1, h2, w1, w2 = ixs
img_chunk = self.reader.get_patch(w1, h1, w2-w1, h2-h1, level=level)
img_chunk = self.reader.get_patch(w1, h1, w2 - w1, h2 - h1, level=level)
mask = seg.apply(img_chunk)
row_mask.append(mask)
del img_chunk # Explicitly release memory
masks.append(row_mask)
mask = np.block(masks)
del masks # Explicitly release memory
else:
image = self.reader.get_level(level)
mask = seg.apply(image)
Expand Down Expand Up @@ -390,7 +392,7 @@ def plot_tissue(self,
savefig_kws=None,
):

level = self.tile_ops.level if tiles else 0
level = self.tile_ops.level if tiles else self.metadata.n_level - 1
image_arr = self.reader.get_level(level)
scale_ratio, thumbnail = self._get_thumbnail(image_arr, size)

Expand Down Expand Up @@ -420,7 +422,7 @@ def plot_tissue(self,
if savefig:
savefig_kws = {} if savefig_kws is None else savefig_kws
save_kws = {'dpi': 150, **savefig_kws}
fig.savefig(fig, save_kws)
fig.savefig(savefig, **save_kws)

return ax

Expand All @@ -445,7 +447,7 @@ def plot_mask(self,
if savefig:
savefig_kws = {} if savefig_kws is None else savefig_kws
save_kws = {'dpi': 150, **savefig_kws}
fig.savefig(fig, save_kws)
fig.savefig(savefig, **save_kws)
return ax

def to_dataset(self, transform=None, run_pretrained=False, **kwargs):
Expand Down

0 comments on commit 3480aec

Please sign in to comment.