:py:mod:`kwcoco.compat_dataset` =============================== .. py:module:: kwcoco.compat_dataset .. autoapi-nested-parse:: A wrapper around the basic kwcoco dataset with a pycocotools API. We do not recommend using this API because it has some idiosyncrasies, where names can be missleading and APIs are not always clear / efficient: e.g. (1) catToImgs returns integer image ids but imgToAnns returns annotation dictionaries. (2) showAnns takes a dictionary list as an argument instead of an integer list The cool thing is that this extends the kwcoco API so you can drop this for compatibility with the old API, but you still get access to all of the kwcoco API including dynamic addition / removal of categories / annotations / images. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: kwcoco.compat_dataset.COCO .. py:class:: COCO(annotation_file=None, **kw) Bases: :py:obj:`kwcoco.coco_dataset.CocoDataset` A wrapper around the basic kwcoco dataset with a pycocotools API. .. rubric:: Example >>> from kwcoco.compat_dataset import * # NOQA >>> import kwcoco >>> basic = kwcoco.CocoDataset.demo('shapes8') >>> self = COCO(basic.dataset) >>> self.info() >>> print('self.imgToAnns = {!r}'.format(self.imgToAnns[1])) >>> print('self.catToImgs = {!r}'.format(self.catToImgs)) .. py:method:: createIndex(self) .. py:method:: info(self) Print information about the annotation file. :return: .. py:method:: imgToAnns(self) :property: .. py:method:: catToImgs(self) :property: unlike the name implies, this actually goes from category to image ids Name retained for backward compatibility .. py:method:: getAnnIds(self, imgIds=[], catIds=[], areaRng=[], iscrowd=None) 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) :return: ids (int array) : integer array of ann ids .. rubric:: Example >>> from kwcoco.compat_dataset import * # NOQA >>> import kwcoco >>> self = COCO(kwcoco.CocoDataset.demo('shapes8').dataset) >>> self.getAnnIds() >>> self.getAnnIds(imgIds=1) >>> self.getAnnIds(imgIds=[1]) >>> self.getAnnIds(catIds=[3]) .. py:method:: getCatIds(self, catNms=[], supNms=[], catIds=[]) 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 .. rubric:: Example >>> from kwcoco.compat_dataset import * # NOQA >>> import kwcoco >>> self = COCO(kwcoco.CocoDataset.demo('shapes8').dataset) >>> self.getCatIds() >>> self.getCatIds(catNms=['superstar']) >>> self.getCatIds(supNms=['raster']) >>> self.getCatIds(catIds=[3]) .. py:method:: getImgIds(self, imgIds=[], catIds=[]) Get img ids that satisfy given filter conditions. :param imgIds (int array) : get imgs for given ids :param catIds (int array) : get imgs with all given cats :return: ids (int array) : integer array of img ids .. rubric:: Example >>> from kwcoco.compat_dataset import * # NOQA >>> import kwcoco >>> self = COCO(kwcoco.CocoDataset.demo('shapes8').dataset) >>> self.getImgIds(imgIds=[1, 2]) >>> self.getImgIds(catIds=[3, 6, 7]) >>> self.getImgIds(catIds=[3, 6, 7], imgIds=[1, 2]) .. py:method:: loadAnns(self, ids=[]) Load anns with the specified ids. :param ids (int array) : integer ids specifying anns :return: anns (object array) : loaded ann objects .. py:method:: loadCats(self, ids=[]) Load cats with the specified ids. :param ids (int array) : integer ids specifying cats :return: cats (object array) : loaded cat objects .. py:method:: loadImgs(self, ids=[]) Load anns with the specified ids. :param ids (int array) : integer ids specifying img :return: imgs (object array) : loaded img objects .. py:method:: showAnns(self, anns, draw_bbox=False) Display the specified annotations. :param anns (array of object): annotations to display :return: None .. py:method:: loadRes(self, resFile) Load result file and return a result api object. :param resFile (str) : file name of result file :return: res (obj) : result api object .. py:method:: download(self, tarDir=None, imgIds=[]) Download COCO images from mscoco.org server. :param tarDir (str): COCO results directory name imgIds (list): images to be downloaded :return: .. py:method:: loadNumpyAnnotations(self, data) Convert result data from a numpy array [Nx7] where each row contains {imageID,x1,y1,w,h,score,class} :param data (numpy.ndarray) :return: annotations (python nested list) .. py:method:: annToRLE(self, ann) Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask (numpy 2D array) .. note:: * This requires the C-extensions for kwimage to be installed due to the need to interface with the bytes RLE format. .. rubric:: Example >>> from kwcoco.compat_dataset import * # NOQA >>> import kwcoco >>> self = COCO(kwcoco.CocoDataset.demo('shapes8').dataset) >>> try: >>> rle = self.annToRLE(self.anns[1]) >>> except NotImplementedError: >>> import pytest >>> pytest.skip('missing kwimage c-extensions') >>> else: >>> assert len(rle['counts']) > 2 >>> # xdoctest: +REQUIRES(module:pycocotools) >>> self.conform(legacy=True) >>> orig = self._aspycoco().annToRLE(self.anns[1]) .. py:method:: annToMask(self, ann) Convert annotation which can be polygons, uncompressed RLE, or RLE to binary mask. :return: binary mask (numpy 2D array) .. note:: The mask is returned as a fortran (F-style) array with the same dimensions as the parent image.