当前位置: 首页>>代码示例>>Python>>正文


Python COCO.download方法代码示例

本文整理汇总了Python中pycocotools.coco.COCO.download方法的典型用法代码示例。如果您正苦于以下问题:Python COCO.download方法的具体用法?Python COCO.download怎么用?Python COCO.download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycocotools.coco.COCO的用法示例。


在下文中一共展示了COCO.download方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pycocotools.coco import COCO [as 别名]
# 或者: from pycocotools.coco.COCO import download [as 别名]

#.........这里部分代码省略.........
    
    def loadCats(self, ids=[]):
        """
        Load categories with the specified ids.
        :param   ids        (int array)    : integer ids specifying categories
        :return: categories (object array) : loaded ann objects
        """
        ids = self._filterCatIds(ids)
        return self.coco.loadCats(ids)
    
    def loadImgs(self, ids=[]):
        """
        Load images with the specified ids.
        :param   ids        (int array)    : integer ids specifying images
        :return: images     (object array) : loaded images objects
        """
        ids = ids if isinstance(ids, list) else [ids]
        ids = self._filterImgIds(ids)
        if len(ids) == 0:
            return []
        images = self.dataset['images']
        return [images[id] for id in ids]

    
    def loadRefexps(self, ids=[]):
        """
        Load referring expressions with the specified ids.
        :param   ids        (int array)    : integer ids specifying referring expressions
        :return: images     (object array) : loaded referring expressions objects
        """
        refexps = self.dataset['refexps']
        if type(ids) == list:
            return [refexps[id] for id in ids]
        elif type(ids) == int:
            return [refexps[ids]]
    
    def download(self, tarDir=None, imgIds=[]):
        """
        Wrapper for COCO.download(). Defaults to GoogleRefexp images only.
        """
        imgIds = self._filterImgIds(imgIds)
        return self.coco.download(tarDir, imgIds)
    
    def showAnn(self, ann, ax=None, printRefexps=True):
        """
        Display the bbox and referring expressions of the given annotation.
        For segmentation display refer to COCO toolkit.
        :param anns (array of object): annotations to display
        :return: None
        """
        import matplotlib.pyplot as plt
        if ax is None:
            ax = plt.gca()
        bbox = ann['bbox']
        draw_bbox(ax, bbox, edge_color='green')
        if printRefexps:
            print('Referring expressions for the object in the bounding box: ')
            for ref_id in ann['refexp_ids']:
                print(self.dataset['refexps'][ref_id]['raw'])
        
    def showRegionCandidates(self, image, ax=None):
        """
        Display the region candidates for the given image.
        :param imgId (int): image id for which we display region candidates
        :param ax: matplotlib axes to draw on, or if unspecified, the current axis from `plt.gca()`
        :return: None
        """
        import matplotlib.pyplot as plt
        if ax is None:
            ax = plt.gca()

        candidates = image['region_candidates']
        for candidate in candidates:
            bbox = candidate['bounding_box']
            draw_bbox(ax, bbox, edge_color='blue')
    
    # Methods specific to Refexp.
    def getRefexpIds(self, tokens=[], len_min=0, len_max=-1, referent=None, referent_has_attributes=False):
        """
        Get description ids that contain all the tokens in the given list, 
        legnth in the specified range and in which the referent has attributes.
        :param:  contains_tokens            (str array) : get refexps containing all given tokens. Defaults to all referring expressions.
        :param:  len_min                    (int)       : minimum number of tokens in the referring expression
        :param:  len_max                    (int)       : maximum number of tokens in the referring expression
        :param:  referent                   (str)       : the referent word in the referring expression
        :param:  referent_has_attributes   (bool)      : if True return referring expressions in which the referent has attributes
        :return: ids                        (int array) : integer array of refexp 
        """
        tokens = tokens if isinstance(tokens, list) else [tokens]
        tokensSet = set(tokens)
        refexps_ids = set([])
        for ref_id, ref in self.dataset['refexps'].iteritems():
            if (set(ref['tokens']).issuperset(tokensSet) 
                    and len(ref['tokens']) >= len_min
                    and (len_max == -1 or len(ref['tokens']) <= len_max)
                    and (referent == None or ('word' in ref['parse']['referent'] and ref['parse']['referent']['word'] == referent))
                    and (not referent_has_attributes or 
                        ('amods' in ref['parse']['referent'] and len(ref['parse']['referent']['amods']) > 0))):
                refexps_ids.add(ref_id)
        return list(refexps_ids)
开发者ID:BenJamesbabala,项目名称:Google_Refexp_toolbox,代码行数:104,代码来源:refexp.py


注:本文中的pycocotools.coco.COCO.download方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。