facebookresearch / segment-anything

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
47.29k stars 5.6k forks source link

what is the gpu memory needed by the h model #33

Open mengxia1994 opened 1 year ago

mengxia1994 commented 1 year ago

cuda out of memory 3060 8g

zhaozhengChen commented 1 year ago

I use 3090 with 24GB memory, but it only need 7GB to load ViT-H SAM model.

CamilleMaurice commented 1 year ago

There is good news! If you have troubles using ViT-H SAM you can decrease the default value for points_per_batch parameter from 64 to 16 for instance.

SamAutomaticMaskGenerator(sam, points_per_batch=16)

I was able to use 8Go VRAM GPU on big images.

Happy segmentation !

KnitVikas commented 1 year ago

for me reducing the image resolution worked with colab specs!

encouver commented 1 year ago

I have a 1660 Ti with 6gb vram, I tried the points_per_batch=16 parameter even with 2, and still use the same amount of memory.

Also tried decreasing the image resolution up to a quarter of the original image and still out of memory.

What is the recommended specs to run with the default model?

AmartyaCSB commented 1 year ago

I found the default model takes around 4GB memory with points_per_batch=16 and around 7GB with default params. I was wondering if we can generate masks while running on cpu!

hanranCode commented 1 year ago

4090 , sam_vit_h_4b8939.pth

image image
kadirnar commented 1 year ago

6gb vram ile 1660 Ti'm var, points_per_batch=16 parametresini 2 ile bile denedim ve hala aynı miktarda bellek kullanıyorum.

Ayrıca görüntü çözünürlüğünü orijinal görüntünün dörtte birine kadar düşürmeyi denediniz ve yine de bellek yetersiz.

Varsayılan modelle çalıştırmak için önerilen özellikler nelerdir?

You should try the vit_b model. Gtx 1050ti(2gb) worked. Default Model: image

encouver commented 1 year ago

6gb vram ile 1660 Ti'm var, points_per_batch=16 parametresini 2 ile bile denedim ve hala aynı miktarda bellek kullanıyorum. Ayrıca görüntü çözünürlüğünü orijinal görüntünün dörtte birine kadar düşürmeyi denediniz ve yine de bellek yetersiz. Varsayılan modelle çalıştırmak için önerilen özellikler nelerdir?

You should try the vit_b model. Gtx 1050ti(2gb) worked. Default Model: image

With the vit_l model, it works perfectly without any extra params. And it give results similar to the vit_h model.

kadirnar commented 1 year ago

I added pip and video support. You were to try:

https://github.com/kadirnar/segment-anything-video

StraigenDaigen commented 1 year ago

Is there a possibility to run Vit_h with RTX 3060 (laptop) 6GB using predictor = SamPredictor(sam)?

I only can run it using SamAutomaticMaskGenerator modifying points_per_batch.

thhung commented 1 year ago

I tried with h models on colab and I get this :

OutOfMemoryError: CUDA out of memory. Tried to allocate 7.40 GiB (GPU 0; 14.75 GiB total capacity; 11.25 GiB already allocated; 3.28 GiB free; 11.33 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

Any suggestions?

Conecsion commented 1 year ago

I set a batch size of 3 (3 images of resolution 512x512) in boxes promption mode and it took me ~20GB GPU memory. This seems to be the maximum batch size I can set for NVIDIA 3090 GPU.

mengxia1994 commented 1 year ago

您好,我已收到您的邮件,我将尽快查阅并给予回复,谢谢!(孟夏的自动回复)