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

Clear torch memory cache in tests #179

Merged
Merged
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
18 changes: 18 additions & 0 deletions test/test_instance_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ def test_embedding_mask_generator(self):
def test_tiled_embedding_mask_generator(self):
from micro_sam.instance_segmentation import TiledEmbeddingMaskGenerator

# Release all unoccupied cached memory, tiling requires a lot of memory
device = util._get_device(None)
if device == "cuda":
import torch.cuda
torch.cuda.empty_cache()
elif device == "mps":
import torch.mps
torch.mps.empty_cache()

mask, image = self.large_mask, self.large_image
predictor, image_embeddings = self.predictor, self.tiled_embeddings
pred_iou_thresh, stability_score_thresh = 0.90, 0.60
Expand All @@ -144,6 +153,15 @@ def test_tiled_embedding_mask_generator(self):
def test_tiled_automatic_mask_generator(self):
from micro_sam.instance_segmentation import TiledAutomaticMaskGenerator, mask_data_to_segmentation

# Release all unoccupied cached memory, tiling requires a lot of memory
device = util._get_device(None)
if device == "cuda":
import torch.cuda
torch.cuda.empty_cache()
elif device == "mps":
import torch.mps
torch.mps.empty_cache()

mask, image = self.large_mask, self.large_image
predictor, image_embeddings = self.predictor, self.tiled_embeddings

Expand Down
Loading