Skip to content

Commit

Permalink
Add osam_yoloworld
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Jun 29, 2024
1 parent 42eccd4 commit 65df5ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions osam/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

import click
import imgviz
import numpy as np
import PIL.Image
import uvicorn
Expand Down Expand Up @@ -127,15 +128,23 @@ def run(model_name: str, image_path: str, prompt, json: bool) -> None:
click.echo(response.model_dump_json())
else:
visualization: np.ndarray
if len(response.masks) == 1:
if response.masks is not None and len(response.masks) == 1:
visualization = (
0.5 * image
+ 0.5
* np.array([0, 255, 0])[None, None, :]
* (response.masks[0] > 0)[:, :, None]
).astype(np.uint8)
else:
raise NotImplementedError
visualization = imgviz.instances2rgb(
image=image,
labels=[
1 + request.prompt.texts.index(text) for text in response.texts
],
bboxes=response.bounding_boxes,
captions=response.texts,
)

sys.stdout.buffer.write(_image_ndarray_to_data(visualization))


Expand Down
1 change: 1 addition & 0 deletions osam/_models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# import modules to register the models
import osam_efficientsam # noqa: F401
import osam_sam # noqa: F401
import osam_yoloworld # noqa: F401

0 comments on commit 65df5ab

Please sign in to comment.