def getCatIds(self, catNms=[], supNms=[], catIds=[], category_type='categories'): """ filtering parameters. default skips that filter. :param catNms (str array) : get cats for given cat names :param supNms (str array) : get cats for given supercategory names :param catIds (int array) : get cats for given cat ids :return: ids (int array) : integer array of cat ids """ if category_type not in self.dataset.keys(): return None catNms = catNms if _isArrayLike(catNms) else [catNms] supNms = supNms if _isArrayLike(supNms) else [supNms] catIds = catIds if _isArrayLike(catIds) else [catIds] if len(catNms) == len(supNms) == len(catIds) == 0: cats = self.dataset[category_type] else: cats = self.dataset[category_type] cats = cats if len(catNms) == 0 else [ cat for cat in cats if cat['name'] in catNms ] cats = cats if len(supNms) == 0 else [ cat for cat in cats if cat['supercategory'] in supNms ] cats = cats if len(catIds) == 0 else [ cat for cat in cats if cat['id'] in catIds ] ids = [cat['id'] for cat in cats] return ids
def getAnnIds(self, imgIds=[], catIds=[], areaRng=[], iscrowd=None, typeIds=[]): """ Get ann ids that satisfy given filter conditions. default skips that filter :param imgIds (int array) : get anns for given imgs catIds (int array) : get anns for given cats areaRng (float array) : get anns for given area range (e.g. [0 inf]) iscrowd (boolean) : get anns for given crowd label (False or True) typeIds (int array) : get anns for given type ids :return: ids (int array) : integer array of ann ids """ imgIds = imgIds if _isArrayLike(imgIds) else [imgIds] catIds = catIds if _isArrayLike(catIds) else [catIds] typeIds = typeIds if _isArrayLike(typeIds) else [typeIds] if len(imgIds) == len(catIds) == len(areaRng) == len(typeIds) == 0: anns = self.dataset['annotations'] else: if not len(imgIds) == 0: lists = [ self.imgToAnns[imgId] for imgId in imgIds if imgId in self.imgToAnns ] anns = list(itertools.chain.from_iterable(lists)) else: anns = self.dataset['annotations'] anns = anns if len(catIds) == 0 else [ ann for ann in anns if ann['category_id'] in catIds ] anns = anns if len(areaRng) == 0 else [ ann for ann in anns if ann['area'] > areaRng[0] and ann['area'] < areaRng[1] ] anns = anns if len(typeIds) == 0 else [ ann for ann in anns if ann['type_id'] in typeIds ] if not iscrowd == None: ids = [ann['id'] for ann in anns if ann['iscrowd'] == iscrowd] else: ids = [ann['id'] for ann in anns] return ids
def get_vid_ids(self, vidIds=[]): vidIds = vidIds if _isArrayLike(vidIds) else [vidIds] if len(vidIds) == 0: ids = self.videos.keys() else: ids = set(vidIds) return list(ids)
def load_vids(self, ids=[]): """Get video information of given video ids. Default return all videos information. Args: ids (list[int]): The given video ids. Defaults to []. Returns: list[dict]: List of video information. """ if _isArrayLike(ids): return [self.videos[id] for id in ids] elif type(ids) == int: return [self.videos[ids]]
def getBBoxes(self, catIds=[]): """ Get bboxes of given cat ids. Args: catIds (int array): Returns: bboxes: numpy array of bboxes. """ catIds = catIds if _isArrayLike(catIds) else [catIds] bboxes = [] if len(catIds) == 0: catIds = self.getCatIds() for id in catIds: bboxes.extend(self.catToBBoxes[id]) return np.array(bboxes)
def get_vid_ids(self, vidIds=[]): """Get video ids that satisfy given filter conditions. Default return all video ids. Args: vidIds (list[int]): The given video ids. Defaults to []. Returns: list[int]: Video ids. """ vidIds = vidIds if _isArrayLike(vidIds) else [vidIds] if len(vidIds) == 0: ids = self.videos.keys() else: ids = set(vidIds) return list(ids)
def load_vids(self, ids=[]): if _isArrayLike(ids): return [self.videos[id] for id in ids] elif type(ids) == int: return [self.videos[ids]]