Skip to content

COCO Mask API is leaking memory when used with Multithreading #202

Description

@HenryJia

Minimal example to reproduce

from multiprocessing.pool import Pool

from pycocotools.coco import COCO

ann_file = '/home/nvme/MS-COCO/annotations/instances_train2017.json'

coco = COCO(ann_file)

category_ids = coco.getCatIds()
categories = coco.loadCats(category_ids)
img_ids = coco.getImgIds()
img_dicts = coco.loadImgs(img_ids)
num_classes = max(category_ids) + 1


def run(img_dict):
    ann_ids = coco.getAnnIds(imgIds = img_dict['id'], iscrowd = None)
    anns = coco.loadAnns(ann_ids)
    for a in anns:
        mask = coco.annToMask(a)
    return None

p = Pool(16)

# This does not use much memory
#out = list(map(run, img_dicts))

# This chews up pretty much all of the memory of my system and doesn't give it back once map has finished
out = p.map(run, img_dicts)

del out

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions