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.87k stars 5.66k forks source link

segment anything model running out of memory #789

Closed MalikHaroonKhokhar closed 3 weeks ago

MalikHaroonKhokhar commented 3 weeks ago

hi im trying to run the model on an image with size: 76.4 kB ,Width : 1024 pixels and height : 1775 pixels and points_per_side are set to 256 i have tried with 64 points_per_side too unfortunately only available memory i got is 8gb and that doesnt seem to be enough is there a way to optimize it to run it on low memory device

Jordan-Pierce commented 3 weeks ago

256 is really high. You should either decrease the number of points to 32, or reduce the longest side of the image from 1024 to 512.

MalikHaroonKhokhar commented 3 weeks ago

@Jordan-Pierce I was eventually able to run it by adjusting the image size and also reducing all background apps to zero! But you need at least 6gb of vram to load this model so I ended up shifting to a better machine with 32gb ram and 11gb vram

Jordan-Pierce commented 3 weeks ago

Nice. Also recommend using MobileSAM or EdgeSAM if you have less computer resources, as they have identical APIs but run faster.

I made a pip install yesterday for a combined API for SAM, EdgeSAM, and MobileSAM in case it's of use

https://github.com/Jordan-Pierce/xSAM

The predictor works fine for all, haven't tried the generator yet, but will next week