Skip to content

Commit

Permalink
Support empty bounding_box
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Jun 29, 2024
1 parent 0fd2a17 commit d8e3041
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions osam/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,35 @@ def run(model_name: str, image_path: str, prompt, json: bool) -> None:
else:
labels = [1] * len(response.annotations)

if request.prompt and request.prompt.texts is not None:
captions = [
f"{annotation.text}: {annotation.score:.2f}"
captions = []
for annotation in response.annotations:
if annotation.text is not None and annotation.score is not None:
caption = f"{annotation.text}: {annotation.score:.2f}"
elif annotation.text is not None:
caption = f"{annotation.text}"
elif annotation.score is not None:
caption = f"{annotation.score:.2f}"
else:
caption = None
captions.append(caption)

if all(
annotation.bounding_box is not None for annotation in response.annotations
):
bboxes = [
[
getattr(annotation.bounding_box, key)
for key in ["ymin", "xmin", "ymax", "xmax"]
]
for annotation in response.annotations
]
else:
captions = None
bboxes = None

visualization = imgviz.instances2rgb(
image=image,
labels=labels,
bboxes=[
[
getattr(annotation.bounding_box, key)
for key in ["ymin", "xmin", "ymax", "xmax"]
]
for annotation in response.annotations
],
bboxes=bboxes,
masks=[annotation.mask for annotation in response.annotations],
captions=captions,
alpha=0.5,
Expand Down

0 comments on commit d8e3041

Please sign in to comment.