uncbiag/SegNext

Evaluation

Closed this issue · 1 comments

Hi, can you tell me how you assessed on SAM?

We showed how to evaluate SAM in this notebook: https://github.com/uncbiag/SegNext/blob/main/notebooks/eval_sat_latency.ipynb

# The user needs install SAM before running the code

import torch
from time import time
from torchvision.transforms.functional import resize, to_pil_image  # type: ignore
import numpy as np
import sys
sys.path.insert(0, '../segnext')

from segment_anything import sam_model_registry, SamAutomaticMaskGenerator
from isegm.data.datasets import  DavisDataset

dataset_path = '../data/DAVIS345/'
dataset = DavisDataset(dataset_path)
sample = dataset.get_sample(0)
image = sample.image

sam_path = '../weights/sam_vit_b_01ec64.pth'
sam = sam_model_registry["vit_b"](checkpoint=sam_path)
device = torch.device('cuda:0')
sam.to(device)
mask_generator = SamAutomaticMaskGenerator(
    model=sam,
    points_per_side=16,
    points_per_batch=1
)
start_time = time()
with torch.no_grad():
    masks = mask_generator.generate(image)
end_time = time()

print(f'SAT Latency: {end_time - start_time} (s)')