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, EfficientSAM;
  • Local APIs - CLI & Python & HTTP interface;
  • Customization - Host custom vision models.

Installation

Pip

pip install osam

For osam serve:

pip install osam[serve]

Quickstart

To run with EfficientSAM:

osam run efficientsam --image <image_file>

To run with YoloWorld:

osam run yoloworld --image <image_file>

Model library

Here are models that can be downloaded:

Model Parameters Size Download
SAM 100M 100M 100MB osam run sam:100m
SAM 300M 300M 300MB osam run sam:300m
SAM 600M 600M 600MB osam run sam
EfficientSAM 10M 10M 40MB osam run efficientsam:10m
EfficientSAM 30M 30M 100MB osam run efficientsam
YoloWorld XL 100M 400MB osam run yoloworld

PS. sam, efficientsam is equivalent to sam:latest, efficientsam:latest.

Usage

CLI

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

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

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


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

Python

import osam.apis
import osam.types

request = osam.types.GenerateRequest(
    model="efficientsam",
    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

# pip install osam[serve]  # required for `osam serve`

# 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\": \"efficientsam\", \"image\": \"$(cat examples/_images/dogs.jpg | base64)\"}" \
  | jq -r .mask | base64 --decode > mask.png

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.2.1.tar.gz (12.6 MB view details)

Uploaded Source

Built Distribution

osam-0.2.1-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file osam-0.2.1.tar.gz.

File metadata

  • Download URL: osam-0.2.1.tar.gz
  • Upload date:
  • Size: 12.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for osam-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b76be38ff95881c1a3ed022c7a3a956db340c9528f85f0f1cc4f915b43e14bfc
MD5 7b9b07244f63d8cd1b9f8eeb9fa83c46
BLAKE2b-256 7cc12f8502d81be305bc099b6bdbbc432e719146c3719c6007caffe3dd2b500a

See more details on using hashes here.

File details

Details for the file osam-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: osam-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for osam-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c24cc7f4197ff4dbc1c8c82c8e0c97f034f4b98eb322b13c49d368e0d3d9b88
MD5 be9b70fb11fa7a19f45989a6915701e1
BLAKE2b-256 11aef0c00504a54f52c580ace31827b28c43f540c15ed2de7bfbe847c83c0d06

See more details on using hashes here.

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