Skip to content

Commit 0b61c7d

Browse files
sava image_path in target
1 parent 124dfa4 commit 0b61c7d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

torchvision/datasets/coco.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def _load_image(self, id: int) -> Image.Image:
4343
return Image.open(os.path.join(self.root, path)).convert("RGB")
4444

4545
def _load_target(self, id: int) -> List[Any]:
46-
return self.coco.loadAnns(self.coco.getAnnIds(id))
46+
target = self.coco.loadAnns(self.coco.getAnnIds(id))
47+
path = self.coco.loadImgs(id)[0]["file_name"]
48+
target[0]["image_path"] = os.path.join(self.root, path)
49+
return target
4750

4851
def __getitem__(self, index: int) -> Tuple[Any, Any]:
4952

0 commit comments

Comments
 (0)