Skip to content

Commit

Permalink
feat(datasets): coco do not transform annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
LutingWang committed Aug 12, 2024
1 parent e8fe332 commit df55a1a
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions todd/datasets/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing_extensions import Self

import torch
import torchvision.transforms.functional as F
from pycocotools.coco import COCO

from ..registries import DatasetRegistry
Expand Down Expand Up @@ -178,20 +177,15 @@ def coco(self) -> COCO:

def __getitem__(self, index: int) -> T:
key, image = self._access(index)
image_id = self._keys.image_ids[index]

# annotations are not transformed
tensor = self._transform(image)

annotations = (
Annotations.load(self._coco, image_id, self._categories)
if self._load_annotations else Annotations()
Annotations.load(
self._coco,
self._keys.image_ids[index],
self._categories,
) if self._load_annotations else Annotations()
)
item: T
if self._transforms is None:
item = T(
id_=key,
image=F.pil_to_tensor(image),
annotations=annotations,
)
else:
item = self._transforms(
dict(id_=key, image=image, annotations=annotations),
)
return item
return T(id_=key, image=tensor, annotations=annotations)

0 comments on commit df55a1a

Please sign in to comment.