Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] fix cocoapi in parser #218

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions mmtrack/datasets/parsers/coco_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This file add snake case alias for coco api

import warnings

import pycocotools
from pycocotools.coco import COCO as _COCO
from pycocotools.cocoeval import COCOeval as _COCOeval


class COCO(_COCO):
"""This class is almost the same as official pycocotools package.

It implements some snake case function aliases. So that the COCO class has
the same interface as LVIS class.
"""

def __init__(self, annotation_file=None):
if getattr(pycocotools, '__version__', '0') >= '12.0.2':
warnings.warn(
'mmpycocotools is deprecated. Please install official pycocotools by "pip install pycocotools"', # noqa: E501
UserWarning)
super().__init__(annotation_file=annotation_file)
self.img_ann_map = self.imgToAnns
self.cat_img_map = self.catToImgs

def get_ann_ids(self, img_ids=[], cat_ids=[], area_rng=[], iscrowd=None):
return self.getAnnIds(img_ids, cat_ids, area_rng, iscrowd)

def get_cat_ids(self, cat_names=[], sup_names=[], cat_ids=[]):
return self.getCatIds(cat_names, sup_names, cat_ids)

def get_img_ids(self, img_ids=[], cat_ids=[]):
return self.getImgIds(img_ids, cat_ids)

def load_anns(self, ids):
return self.loadAnns(ids)

def load_cats(self, ids):
return self.loadCats(ids)

def load_imgs(self, ids):
return self.loadImgs(ids)


# just for the ease of import
COCOeval = _COCOeval
3 changes: 2 additions & 1 deletion mmtrack/datasets/parsers/coco_video_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from collections import defaultdict

import numpy as np
from pycocotools.coco import COCO, _isArrayLike
from .coco_api import COCO
from pycocotools.coco import _isArrayLike


class CocoVID(COCO):
Expand Down