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

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

# 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.0.tar.gz (15.4 MB view details)

Uploaded Source

Built Distribution

osam-0.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: osam-0.2.0.tar.gz
  • Upload date:
  • Size: 15.4 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.0.tar.gz
Algorithm Hash digest
SHA256 540f5677c36fda94b042e7d9c5705d965940167b58cb8b2d633ee76d045ca744
MD5 c7589e3d808af3c4f162c047d86e8e13
BLAKE2b-256 5412e51da18103d31b31ed47fc22b8e88f245f94b344d634349142442e0419d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: osam-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for osam-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d01dea6fc6cc2bd91573af1c239482023f40376ef0711b265d08b4cd6e152ca0
MD5 5c03687a64aaf6d2022d15c76554c79d
BLAKE2b-256 9fa4c3ed6083f773c72e202c1d244f7e93557a98243163b7c2eb3471c3a65dce

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