Skip to content

Commit

Permalink
Fix misalignement between Local and Remote model infer input types.
Browse files Browse the repository at this point in the history
  • Loading branch information
fcdl94 authored and fcdl94 committed Dec 10, 2024
1 parent b70d4a2 commit 4b57251
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions focoos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .focoos import Focoos
from .local_model import LocalModel
from .ports import *
from .remote_model import RemoteModel
8 changes: 6 additions & 2 deletions focoos/remote_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from time import sleep
from typing import Optional, Tuple, Union

import cv2
import numpy as np
from supervision import BoxAnnotator, Detections, LabelAnnotator, MaskAnnotator

Expand Down Expand Up @@ -120,16 +121,19 @@ def _annotate(self, im: np.ndarray, detections: Detections) -> np.ndarray:

def infer(
self,
image: Union[str, Path, bytes],
image: Union[str, Path, np.ndarray, bytes],
threshold: float = 0.5,
annotate: bool = False,
) -> Tuple[FocoosDetections, Optional[np.ndarray]]:
image_bytes = None
if not isinstance(image, bytes):
if isinstance(image, str) or isinstance(image, Path):
if not os.path.exists(image):
logger.error(f"Image file not found: {image}")
raise FileNotFoundError(f"Image file not found: {image}")
image_bytes = open(image, "rb").read()
elif isinstance(image, np.ndarray):
_, buffer = cv2.imencode(".jpg", image)
image_bytes = buffer.tobytes()
else:
image_bytes = image
files = {"file": image_bytes}
Expand Down

0 comments on commit 4b57251

Please sign in to comment.