MobileSAM icon indicating copy to clipboard operation
MobileSAM copied to clipboard

It's too slow.

Open kanbekotori opened this issue 1 year ago • 6 comments

屏幕截图 2023-11-08 164042

from mobile_sam import sam_model_registry, SamAutomaticMaskGenerator
import cv2
import time

start_time = time.time()

sam_checkpoint = "./mobile_sam.pt"
mobile_sam = sam_model_registry["vit_t"](checkpoint=sam_checkpoint)
mobile_sam.to(device="cuda")
mobile_sam.eval()
mask_generator = SamAutomaticMaskGenerator(mobile_sam)
image_bgr = cv2.imread("C:\\Users\\kanbe\\Pictures\\aa.jpg")
image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
masks = mask_generator.generate(image_rgb)

end_time = time.time()
print("{:.2f}s".format(end_time - start_time))

Image file size 54k (1024 x 683).

It took about 7 seconds with the GPU and 70 seconds with the CPU, is this a normal speed?

kanbekotori avatar Nov 08 '23 08:11 kanbekotori

On my CPU, it will take over a minute to segment an image

zaoyueri avatar Nov 08 '23 09:11 zaoyueri

Have you considered using ONNX model?

JisuHann avatar Nov 13 '23 06:11 JisuHann

您是否考虑过使用 ONNX 模型?

能够分享一下相关的代码吗?

xiangw369 avatar Nov 13 '23 12:11 xiangw369

It takes 10minutes on my cpu for single image

tyronedong avatar Dec 13 '23 08:12 tyronedong

It takes 10minutes on my cpu for single image

large image?

zaoyueri avatar Dec 13 '23 08:12 zaoyueri

On my GPU, it take 1.6s to segment an image, img_path = "./notebooks/images/picture1.jpg"

ghm666 avatar Jan 15 '24 08:01 ghm666