출처 : https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/coco.py

0.  COCO 초기화

- COCO api class that loads COCO annotation file and prepare data structures.

train_json : coco format 들어있는 json 파일 경로

from pycocotools import COCO

coco = COCO(train_json)

 

1. coco.getAnnIds()

- Get ann ids that satisfy given filter conditions (주어진 조건에 맞는 annotation id 반환)

    def 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
        """

 

(설정할 수 있는 조건)

imgIds : 특정 이미지 id

catIds : 특정 카테고리 id

areaRng : bbox 범위

 

를 통해서 조건에 해당하는 annotation id 를 반환해준다. (한 이미지에 여러개의 bbox가 있다면 각각 box의 annotation 이 다르게 정의된다. )

 

2. coco.getCatIds()

- Get cat ids that satisfy given filter conditions. (주어진 조건에 맞는 category id 반환)

    def 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
        """

 

(설정할 수 있는 조건)

catNms : 특정 카테고리 이름

supNms : 특정 상위카테고리 이름

catIds : 특정 catId에 해당하는 catId 반환 (이 조건만 사용하게 되면 넣은 값 그대로 반환되지만 위의 다른 조건과 같이 사용하면 특정 조건에 해당하는 catId 를 얻을 수 있음)

 

3. coco.getImgIds()

- Get img ids that satisfy given filter conditions. (주어진 조건에 맞는 image id 반환)

    def 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
        '''

 

(설정할 수 있는 조건)

imgIds : 특정 id 에 해당하는 Img

catIds : catIds에 해당하는 모든 category를 가지는 img id 를 찾고 싶을 때 

 

4. coco.loadAnns()

- Load anns with the specified ids. (특정 id에 해당하는 annotation load)

   def loadAnns(self, ids=[]):
        """
        Load anns with the specified ids.
        :param ids (int array)       : integer ids specifying anns
        :return: anns (object array) : loaded ann objects
        """

 

알고 싶은 annotation id 값들을 array 형태로 넣어주면

해당 id에 해당하는 anntation 정보(image_id, category_id, area, bbox, iscrowd) 를 dict 형태로 반환

 

 

 

 

5. coco.loadCats()

- Load cats with the specified ids. (특정 id에 해당하는 catetory load)

    def loadCats(self, ids=[]):
        """
        Load cats with the specified ids.
        :param ids (int array)       : integer ids specifying cats
        :return: cats (object array) : loaded cat objects
        """

 

알고 싶은 category id 값들을 array 형태로 넣어주면

해당 id에 해당하는 category 정보(id, name, supercategory) 를 dict 형태로 반환

 

6. coco.loadImgs()

- Load imgs with the specified ids. (특정 id에 해당하는 image load)

    def loadImgs(self, ids=[]):
        """
        Load anns with the specified ids.
        :param ids (int array)       : integer ids specifying img
        :return: imgs (object array) : loaded img objects
        """

 

알고 싶은 image id 값들을 array 형태로 넣어주면

해당 id에 해당하는 image 정보를 dict 형태로 반환

'AI Tech 7기' 카테고리의 다른 글

segmentation loss 정리  (3) 2024.11.15
object detection에서 train_cfg 설정  (0) 2024.10.16
NMS, SoftNMS  (0) 2024.10.16
sweetpotato7