From 0b61c7d8f9eaee05e95337633fd00126af412563 Mon Sep 17 00:00:00 2001 From: Yonghye Kwon Date: Sat, 8 Mar 2025 14:52:39 +0900 Subject: [PATCH] sava image_path in target --- torchvision/datasets/coco.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/torchvision/datasets/coco.py b/torchvision/datasets/coco.py index 64543036640..36f21a0597d 100644 --- a/torchvision/datasets/coco.py +++ b/torchvision/datasets/coco.py @@ -43,7 +43,10 @@ def _load_image(self, id: int) -> Image.Image: return Image.open(os.path.join(self.root, path)).convert("RGB") def _load_target(self, id: int) -> List[Any]: - return self.coco.loadAnns(self.coco.getAnnIds(id)) + target = self.coco.loadAnns(self.coco.getAnnIds(id)) + path = self.coco.loadImgs(id)[0]["file_name"] + target[0]["image_path"] = os.path.join(self.root, path) + return target def __getitem__(self, index: int) -> Tuple[Any, Any]: