Skip to main content

Get up and running vision foundational models locally.

Project description

logo

Osam

Get up and running with segment-anything models locally.




Osam (/oʊˈsɑm/) is a tool to run open-source segment-anything models locally (inspired by Ollama).

Osam provides:

  • Segment-Anything Models - original SAM, Efficient-SAM;
  • Local APIs - CLI & Python & HTTP interface;
  • Customization - Host custom vision models.

Installation

Pip

pip install osam

Quickstart

To run with Efficient-SAM:

osam run efficient-sam --image <image_file>

Model library

Here are models that can be downloaded:

Model Parameters Size Download
SAM 91M 91M 100MB osam run sam:91m
SAM 308M 308M 320MB osam run sam:308m
SAM 636M 636M 630MB osam run sam
Efficient-SAM 10M 10M 40MB osam run efficient-sam:10m
Efficient-SAM 25M 25M 100MB osam run efficient-sam

PS. sam, efficient-sam is equivalent to sam:latest, efficient-sam:latest.

Usage

CLI

# Run a model with an image
osam run efficient-sam --image examples/_images/dogs.jpg > output.png

# Get a JSON output
osam run efficient-sam --image examples/_images/dogs.jpg --json
# {"model": "efficient-sam", "mask": "..."}

# Give a prompt
osam run efficient-sam --image examples/_images/dogs.jpg \
  --prompt '{"points": [[1439, 504], [1439, 1289]], "point_labels": [1, 1]}' > output.png


Input and output images ('dogs.jpg', 'output.png').

Python

import osam.apis
import osam.types

request = osam.types.GenerateRequest(
    model="efficient-sam",
    image=np.asarray(PIL.Image.open("examples/_images/dogs.jpg")),
    prompt=osam.types.Prompt(points=[[1439, 504], [1439, 1289]], point_labels=[1, 1]),
)
response = osam.apis.generate(request=request)
PIL.Image.fromarray(response.mask).save("mask.png")


Input and output images ('dogs.jpg', 'mask.png').

HTTP

# Get up the server
osam serve

# POST request
curl 127.0.0.1:11368/api/generate -X POST \
  -H "Content-Type: application/json" \
  -d "{\"model\": \"efficient-sam\", \"image\": \"$(cat examples/_images/dogs.jpg | base64)\"}" \
  | jq -r .mask | base64 --decode > mask.png

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

osam-0.1.1.tar.gz (5.5 MB view hashes)

Uploaded Source

Built Distribution

osam-0.1.1-py3-none-any.whl (14.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page