Skip to content

Commit

Permalink
chores
Browse files Browse the repository at this point in the history
  • Loading branch information
denniswittich committed Dec 12, 2024
1 parent 5cbd68b commit 872baa3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
40 changes: 21 additions & 19 deletions rosys/vision/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@


class Autoupload(Enum):
"""Configures the auto-submitting of images to the Learning Loop"""
'''Configures the auto-submitting of images to the Learning Loop'''

FILTERED = 'filtered'
"""only submit images with novel detections and in an uncertainty range (this is the default)"""
'''only submit images with novel detections and in an uncertainty range (this is the default)'''

DISABLED = 'disabled'
"""no auto-submitting"""
'''no auto-submitting'''

ALL = 'all'
"""submit all images which are run through the detector"""
'''submit all images which are run through the detector'''


class DetectorException(Exception):
"""An exception that is raised by a detector."""
'''An exception that is raised by a detector.'''


@dataclass(slots=True, kw_only=True)
class DetectorInfo:
"""Information about the detector."""
'''Information about the detector.'''
operation_mode: str = field(
metadata={"description": "The operation mode of the detector node"})
state: str | None = field(
Expand Down Expand Up @@ -70,15 +70,15 @@ class ModelVersioningInfo:


class Detector(abc.ABC):
"""A detector allows detecting objects in images.
'''A detector allows detecting objects in images.
It also holds an upload queue for sending images with uncertain results to an active learning infrastructure like the [Zauberzeug Learning Loop](https://zauberzeug.com/products/learning-loop).
"""
'''

def __init__(self, *, name: str | None = None) -> None:
self.name = name or str(uuid4())
self.NEW_DETECTIONS = Event()
"""detection on an image is completed (argument: image)"""
'''detection on an image is completed (argument: image)'''
self.log = logging.getLogger('rosys.detector')
self.uploads = Uploads()

Expand All @@ -91,7 +91,7 @@ async def detect(self,
source: str | None = None,
creation_date: datetime | str | None = None,
) -> Detections | None:
"""Runs detections on the image. Afterwards the `image.detections` property is filled.
'''Runs detections on the image. Afterwards the `image.detections` property is filled.
The parameters `tags`, `source`, and `creation_date` are added as metadata if the image is uploaded.
Expand All @@ -100,7 +100,7 @@ async def detect(self,
Raises:
DetectorException: if the detection fails.
"""
'''

@abc.abstractmethod
async def upload(self,
Expand All @@ -110,43 +110,45 @@ async def upload(self,
source: str | None = None,
creation_date: datetime | str | None = None,
) -> None:
"""Uploads the image to the Learning Loop.
'''Uploads the image to the Learning Loop.
The parameters `tags`, `source`, and `creation_date` are added as metadata.
If the image has detections, they are also uploaded.
Raises:
DetectorException: if the upload fails.
"""
'''

@abc.abstractmethod
async def fetch_detector_info(self) -> DetectorInfo:
"""Retrieve information about the detector.
'''Retrieve information about the detector.
Returns:
DetectorInfo: information about the detector.
Raises:
DetectorException: if the about information cannot be retrieved.
"""
'''

@abc.abstractmethod
async def fetch_model_version_info(self) -> ModelVersioningInfo:
"""Retrieve information about the model version and versioning mode.
'''Retrieve information about the model version and versioning mode.
Returns:
ModelVersioningInfo: the information about the model versioning as data class.
Raises:
DetectorException: if the detector is not connected or the information cannot be retrieved.
"""
'''

@abc.abstractmethod
async def set_model_version(self, version: Literal['follow_loop', 'pause'] | str) -> None:
"""Set the model version or versioning mode.
'''Set the model version or versioning mode.
Set to 'follow_loop' to automatically update the model version to the latest version in the learning loop.
Set to 'pause' to stop automatic updates and keep the current model version.
Set to a version number (e.g. '1.2') to use a specific version.
Raises:
DetectorException: if the version control mode is not valid or the version could not be set.
"""
'''
10 changes: 5 additions & 5 deletions rosys/vision/detector_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async def _detect(self,
if self.timeout_count > 5 and self.auto_disconnect:
self.log.error('Detection timed out 5 times in a row. Disconnecting from detector %s', self.name)
await self.disconnect()
raise DetectorException('Detection timeout') # pylint: disable=raise-missing-from
raise DetectorException('Detection timeout') from None
except Exception as e:
raise DetectorException('Detection failed') from e

Expand Down Expand Up @@ -208,7 +208,7 @@ async def fetch_detector_info(self) -> DetectorInfo:
response = await self.sio.call('about', timeout=5)
except socketio.exceptions.TimeoutError:
self.log.error('Communication timeout for detector %s', self.name)
raise DetectorException('Communication timeut') # pylint: disable=raise-missing-from
raise DetectorException('Communication timeut') from None
except Exception as e:
raise DetectorException('Communication failed') from e

Expand Down Expand Up @@ -241,7 +241,7 @@ async def fetch_model_version_info(self) -> ModelVersioningInfo:
response = await self.sio.call('get_model_version', timeout=5)
except socketio.exceptions.TimeoutError:
self.log.error('Communication timeout for detector %s', self.name)
raise DetectorException('Communication timed out') # pylint: disable=raise-missing-from
raise DetectorException('Communication timed out') from None
except Exception as e:
raise DetectorException('Communication failed') from e

Expand Down Expand Up @@ -270,7 +270,7 @@ async def set_model_version(self, version: Literal['follow_loop', 'pause'] | str
response = await self.sio.call('set_model_version_mode', version, timeout=5)
except socketio.exceptions.TimeoutError:
self.log.error('Communication timeout for detector %s', self.name)
raise DetectorException('Communication timeout') # pylint: disable=raise-missing-from
raise DetectorException('Communication timeout') from None
except Exception as e:
self.log.error('Communication failed for detector %s: %s', self.name, e)
raise DetectorException('Communication failed') from e
Expand All @@ -292,7 +292,7 @@ async def soft_reload(self) -> None:
await self.sio.call('soft_reload', timeout=5)
except socketio.exceptions.TimeoutError:
self.log.error('Communication timeout for detector %s', self.name)
raise DetectorException('Communication timeout') # pylint: disable=raise-missing-from
raise DetectorException('Communication timeout') from None
except Exception as e:
self.log.error('Communication failed for detector %s: %s', self.name, e)
raise DetectorException('Communication failed') from e
Expand Down

0 comments on commit 872baa3

Please sign in to comment.