Skip to content

Commit

Permalink
chore(data): save memory for COCO dataset (Megvii-BaseDetection#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
FateScript authored Jan 12, 2022
1 parent 6c874ce commit 147a8a3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions yolox/data/datasets/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@
from .datasets_wrapper import Dataset


def remove_useless_info(coco):
"""
Remove useless info in coco dataset. COCO object is modified inplace.
This function is mainly used for saving memory (save about 30% mem).
"""
if isinstance(coco, COCO):
dataset = coco.dataset
dataset.pop("info", None)
dataset.pop("licenses", None)
for img in dataset["images"]:
img.pop("license", None)
img.pop("coco_url", None)
img.pop("date_captured", None)
img.pop("flickr_url", None)
for anno in coco.dataset["annotations"]:
anno.pop("segmentation", None)


class COCODataset(Dataset):
"""
COCO dataset class.
Expand Down Expand Up @@ -43,6 +61,7 @@ def __init__(
self.json_file = json_file

self.coco = COCO(os.path.join(self.data_dir, "annotations", self.json_file))
remove_useless_info(self.coco)
self.ids = self.coco.getImgIds()
self.class_ids = sorted(self.coco.getCatIds())
cats = self.coco.loadCats(self.coco.getCatIds())
Expand Down

0 comments on commit 147a8a3

Please sign in to comment.