Skip to content

Commit

Permalink
feature: detector
Browse files Browse the repository at this point in the history
pass optional information about the image source to the detector so it can be uploaded to the learning loop
  • Loading branch information
denniswittich committed Oct 2, 2024
1 parent 7bd4e89 commit c75253b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions rosys/vision/detector_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def upload_priority_images():
rosys.background_tasks.create(upload_priority_images(), name='upload_priority_images')
self.uploads.priority_queue.clear()

async def upload(self, image: Image, *, tags: list[str] | None = None) -> None:
async def upload(self, image: Image, *, tags: list[str] | None = None, source: str | None = None) -> None:
assert len(image.data or []) < self.MAX_IMAGE_SIZE, f'image too large: {len(image.data or [])}'
tags = tags or []
try:
Expand All @@ -103,6 +103,8 @@ async def upload(self, image: Image, *, tags: list[str] | None = None) -> None:
detections_dict['segmentation_detections'] = detections_dict.pop('segmentations')
data_dict['detections'] = detections_dict
data_dict['tags'] = list(image.tags.union(tags))
data_dict['source'] = source

await self.sio.emit('upload', data_dict)

except Exception:
Expand All @@ -112,12 +114,18 @@ async def detect(self,
image: Image,
autoupload: Autoupload = Autoupload.FILTERED,
tags: list[str] | None = None,
source: str | None = None
) -> Detections | None:
assert len(image.data or []) < self.MAX_IMAGE_SIZE, f'image too large: {len(image.data or [])}'
tags = tags or []
return await self.lazy_worker.run(self._detect(image, autoupload, tags))

async def _detect(self, image: Image, autoupload: Autoupload, tags: list[str]) -> Detections | None:
return await self.lazy_worker.run(self._detect(image, autoupload, tags, source))

async def _detect(self,
image: Image,
autoupload: Autoupload,
tags: list[str],
source: str | None = None
) -> Detections | None:
if image.is_broken:
return None
try:
Expand All @@ -126,6 +134,7 @@ async def _detect(self, image: Image, autoupload: Autoupload, tags: list[str]) -
'mac': image.camera_id,
'autoupload': autoupload.value,
'tags': tags,
'source': source,
}, timeout=3)
if image.is_broken: # NOTE: image can be marked broken while detection is underway
return None
Expand Down

0 comments on commit c75253b

Please sign in to comment.