Skip to content

Commit

Permalink
feature: detector
Browse files Browse the repository at this point in the history
add an intermediate abstraction level that can allows the logic to use the tags when doing the inference.
  • Loading branch information
denniswittich committed Oct 1, 2024
1 parent 5bcdf36 commit a65074b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion learning_loop_node/detector/detector_logic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from abc import abstractmethod
from typing import Optional
from typing import List, Optional

import numpy as np

Expand Down Expand Up @@ -46,6 +46,12 @@ def load_model(self):
def init(self):
"""Called when a (new) model was loaded. Initialize the model. Model information available via `self.model_info`"""

def evaluate_with_tags(self, image: np.ndarray, tags: List[str]) -> Detections: # pylint: disable=unused-argument
"""Called by the detector node when an image should be evaluated (REST or SocketIO).
Tags come from the caller and may be used in this function.
By default, this function simply calls `evaluate`"""
return self.evaluate(image)

@abstractmethod
def evaluate(self, image: np.ndarray) -> Detections:
"""Evaluate the image and return the detections.
Expand Down
6 changes: 4 additions & 2 deletions learning_loop_node/detector/detector_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,14 @@ def reload(self, reason: str):
self.log.error('could not reload app')

async def get_detections(self, raw_image: np.ndarray, camera_id: Optional[str], tags: List[str], autoupload: Optional[str] = None) -> Optional[Dict]:
"""Note: raw_image is a numpy array of type uint8, but not in the correrct shape!
""" Main processing function for the detector node when an image is received via REST or SocketIO.
This function infers the detections from the image, cares about upload ing to the loop and returns the detections as a dictionary.
Note: raw_image is a numpy array of type uint8, but not in the correrct shape!
It can be converted e.g. using cv2.imdecode(raw_image, cv2.IMREAD_COLOR)"""

await self.detection_lock.acquire()
loop = asyncio.get_event_loop()
detections = await loop.run_in_executor(None, self.detector_logic.evaluate, raw_image)
detections = await loop.run_in_executor(None, self.detector_logic.evaluate_with_tags, raw_image, tags)
self.detection_lock.release()

fix_shape_detections(detections)
Expand Down

0 comments on commit a65074b

Please sign in to comment.