gitmyhub

FastSAM

Python ★ 8.4k updated 1y ago

Fast Segment Anything

FastSAM is a real-time image segmentation tool that draws precise outlines around every object in a photo, reportedly 50x faster than Meta's SAM, with support for text, bounding box, point, or automatic prompts.

PythonPyTorchYOLOv8Gradiosetup: moderatecomplexity 3/5

FastSAM is a tool for image segmentation, which means it draws precise outlines around every distinct object or region in a photo. You give it an image and it returns masks showing exactly which pixels belong to which thing. It was built as a faster alternative to Meta's Segment Anything Model (SAM), with the README claiming roughly 50 times the speed while delivering comparable accuracy. It was trained on a small fraction (2%) of the large dataset that SAM used.

The tool supports four ways of telling it what to segment. The first is an "everything" mode that automatically outlines all objects it can find without any guidance from you. The second is a text prompt, where you describe what you want in plain language, for example "the yellow dog." The third is a bounding box, where you draw a rectangle around the area of interest. The fourth is a points prompt, where you click specific pixel coordinates to indicate foreground or background regions.

You interact with it through a Python script or a short code snippet using the FastSAM library. You load a downloaded model file, point it at an image, choose a mode, and it produces annotated output images showing the detected segments. An optional Gradio web interface lets you upload images and test the modes without writing any code. Live demos are also hosted on HuggingFace and Replicate for trying it in a browser.

Two model sizes are available: a larger default version based on YOLOv8x for higher accuracy, and a smaller FastSAM-s version based on YOLOv8s that runs faster on limited hardware. Installation requires Python 3.7 or later, PyTorch, and a few other packages listed in a requirements file. GPU support is strongly recommended for reasonable speed.

Where it fits