Skip to content

Commit

Permalink
refactor(object_detector): add return type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Jun 25, 2024
1 parent 834a664 commit 2237edf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/nrtk_explorer/app/image_meta.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import TypedDict
from nrtk_explorer.app.trame_utils import delete_state
from nrtk_explorer.app.image_ids import DatasetId

ImageMetaId = str


def image_id_to_meta(image_id: DatasetId) -> ImageMetaId:
def image_id_to_meta(image_id: str) -> ImageMetaId:
return f"meta_{image_id}"


Expand All @@ -26,14 +25,14 @@ class DatasetImageMeta(TypedDict):
}


def update_image_meta(state, dataset_id: DatasetId, meta_patch: PartialDatasetImageMeta):
def update_image_meta(state, dataset_id: str, meta_patch: PartialDatasetImageMeta):
meta_key = image_id_to_meta(dataset_id)
current_meta = {}
if state.has(meta_key) and state[meta_key] is not None:
current_meta = state[meta_key]
state[meta_key] = {**IMAGE_META_DEFAULTS, **current_meta, **meta_patch}


def delete_image_meta(state, dataset_id: DatasetId):
def delete_image_meta(state, dataset_id: str):
meta_key = image_id_to_meta(dataset_id)
delete_state(state, meta_key)
6 changes: 4 additions & 2 deletions src/nrtk_explorer/library/object_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import torch
import transformers

from typing import Optional
from typing import Optional, Sequence

from nrtk_explorer.library import images_manager

ImageIdToAnnotations = dict[str, Sequence[dict]]


class ObjectDetector:
"""Object detection using Hugging Face's transformers library"""
Expand Down Expand Up @@ -58,7 +60,7 @@ def eval(
image_ids: list[str],
content: Optional[dict] = None,
batch_size: int = 32,
):
) -> ImageIdToAnnotations:
"""Compute object recognition. Returns Annotations grouped by input image paths."""

# Some models require all the images in a batch to be the same size,
Expand Down

0 comments on commit 2237edf

Please sign in to comment.