Skip to content

Commit

Permalink
fix(datasets): lvis and coco annotations can be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
LutingWang committed Aug 13, 2024
1 parent e35f691 commit c95811b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 7 additions & 3 deletions todd/configs/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing_extensions import Self

from ..bases.configs import Config
from ..loggers import logger
from ..loggers import master_logger


class SerializeMixin(Config):
Expand All @@ -27,9 +27,13 @@ def loads(cls, s: str, **kwargs) -> Self:
def load(cls, file: str | pathlib.Path, **kwargs) -> Self:
if len(kwargs) > 0:
kwargs_str = ', '.join(f'{k}={v}' for k, v in kwargs.items())
logger.debug("Loading config from %s with %s", file, kwargs_str)
master_logger.debug(
"Loading config from %s with %s",
file,
kwargs_str,
)
else:
logger.debug("Loading config from %s", file)
master_logger.debug("Loading config from %s", file)

if isinstance(file, str):
file = pathlib.Path(file)
Expand Down
8 changes: 5 additions & 3 deletions todd/datasets/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ def is_crowd(self) -> torch.Tensor:
@property
def bboxes(self) -> 'FlattenBBoxesXYWH':
from todd.tasks.object_detection import FlattenBBoxesXYWH
return FlattenBBoxesXYWH(
torch.tensor([annotation.bbox for annotation in self]),
)
if len(self) > 0:
bboxes = torch.tensor([annotation.bbox for annotation in self])
else:
bboxes = torch.zeros(0, 4)
return FlattenBBoxesXYWH(bboxes)

@property
def categories(self) -> torch.Tensor:
Expand Down
8 changes: 5 additions & 3 deletions todd/datasets/lvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ def masks(self) -> torch.Tensor:
@property
def bboxes(self) -> 'FlattenBBoxesXYWH':
from todd.tasks.object_detection import FlattenBBoxesXYWH
return FlattenBBoxesXYWH(
torch.tensor([annotation.bbox for annotation in self]),
)
if len(self) > 0:
bboxes = torch.tensor([annotation.bbox for annotation in self])
else:
bboxes = torch.zeros(0, 4)
return FlattenBBoxesXYWH(bboxes)

@property
def categories(self) -> torch.Tensor:
Expand Down

0 comments on commit c95811b

Please sign in to comment.