COCO
- class faster_coco_eval.core.COCO(annotation_file=None, use_deepcopy=False, print_function=<bound method Logger.debug of <Logger faster_coco_eval.core.coco (WARNING)>>)
Bases:
object
- annToMask(ann)
Convert annotation which can be polygons, uncompressed RLE, or RLE to binary mask.
- Parameters:
ann (dict) – Annotation information.
- Returns:
Binary mask of the annotation.
- Return type:
np.ndarray
- annToRLE(ann)
Convert annotation which can be polygons, uncompressed RLE to RLE.
- Parameters:
ann (dict) – Annotation information.
- Returns:
Run-length encoding of the annotation.
- Return type:
dict
- property cat_img_map: dict
Return a mapping from category ids to image ids.
- Returns:
Mapping from category ids to image ids.
- Return type:
dict
- createIndex()
Create index for coco annotation data.
Creates internal indices for the COCO dataset to enable fast lookups. Builds mappings between images, annotations and categories.
- download(tarDir=None, imgIds=[])
Deprecated: Download images (no longer supported).
- Parameters:
tarDir (Any, optional) – Target directory. Not used.
imgIds (list, optional) – Image ids. Not used.
- Raises:
DeprecationWarning – Always raised, function is deprecated.
- dump(output_file)
Dump annotations to a json file.
- Parameters:
output_file (Union[str, os.PathLike]) – Path to the output json file.
- getAnnIds(imgIds=[], catIds=[], areaRng=[], iscrowd=None)
Get ann ids that satisfy given filter conditions.
- Parameters:
imgIds (List[int], optional) – Get anns for given images. Defaults to [].
catIds (List[int], optional) – Get anns for given categories. Defaults to [].
areaRng (List[float], optional) – Get anns for given area range (e.g. [0, inf]). Defaults to [].
iscrowd (bool, optional) – Get anns for given crowd label (False or True). Defaults to None.
- Returns:
Integer array of ann ids that satisfy the criteria.
- Return type:
List[int]
- getCatIds(catNms=[], supNms=[], catIds=[])
Get category ids that satisfy given filter conditions.
- Parameters:
catNms (List[str], optional) – Get categories for given cat names. Defaults to [].
supNms (List[str], optional) – Get categories for given supercategory names. Defaults to [].
catIds (List[int], optional) – Get categories for given ids. Defaults to [].
- Returns:
Integer array of cat ids.
- Return type:
List[int]
- getImgIds(imgIds=[], catIds=[])
Get image ids that satisfy given filter conditions.
- Parameters:
imgIds (List[int], optional) – Get images for given ids. Defaults to [].
catIds (List[int], optional) – Get images with all given categories. Defaults to [].
- Returns:
Integer array of img ids.
- Return type:
List[int]
- get_ann_ids(img_ids=[], cat_ids=[], area_rng=[], iscrowd=None)
Get ann ids that satisfy given filter conditions.
- Parameters:
img_ids (List[int], optional) – Get anns for given imgs. Defaults to [].
cat_ids (List[int], optional) – Get anns for given cats. Defaults to [].
area_rng (List[float], optional) – Get anns with area less than this. Defaults to [].
iscrowd (bool, optional) – Get anns for given crowd label. Defaults to None.
- Returns:
Integer array of ann ids.
- Return type:
List[int]
- get_cat_ids(cat_names=[], sup_names=[], cat_ids=[])
Get cat ids that satisfy given filter conditions.
- Parameters:
cat_names (List[str], optional) – Get cats for given names. Defaults to [].
sup_names (List[str], optional) – Get cats for given supercategory names. Defaults to [].
cat_ids (List[int], optional) – Get cats for given ids. Defaults to [].
- Returns:
Integer array of cat ids.
- Return type:
List[int]
- get_img_ids(img_ids=[], cat_ids=[])
Get img ids that satisfy given filter conditions.
- Parameters:
img_ids (List[int], optional) – Get imgs for given ids. Defaults to [].
cat_ids (List[int], optional) – Get imgs with all given cats. Defaults to [].
- Returns:
Integer array of img ids.
- Return type:
List[int]
- property img_ann_map: dict
Return a mapping from image ids to annotation ids.
- Returns:
Mapping from image ids to annotation ids.
- Return type:
dict
- info()
Print information about the annotation file.
Prints the info section of the annotation file using the print function.
- loadAnns(ids=[])
Load annotations with the specified ids.
- Parameters:
ids (Union[List[int], int], optional) – Integer ids specifying annotations. Defaults to [].
- Returns:
Loaded annotation objects.
- Return type:
List[dict]
- loadCats(ids=[])
Load categories with the specified ids.
- Parameters:
ids (Union[List[int], int], optional) – Integer ids specifying categories. Defaults to [].
- Returns:
Loaded category objects.
- Return type:
List[dict]
- loadImgs(ids=[])
Load images with the specified ids.
- Parameters:
ids (Union[List[int], int], optional) – Integer ids specifying images. Defaults to [].
- Returns:
Loaded image objects.
- Return type:
List[dict]
- loadNumpyAnnotations(data)
Convert result data from array to anns.
- Parameters:
data (np.ndarray) – 2d array where each row contains [imageID, x1, y1, w, h, score, class]
- Returns:
Converted annotations as a list of dicts.
- Return type:
List[dict]
- loadRes(resFile, min_score=0.0)
Load result file and return a result api object.
- Parameters:
resFile (Union[str, os.PathLike, pathlib.PosixPath, dict, list, np.ndarray]) – File name of result file or numpy array.
min_score (float, optional) – Minimum score to consider a result. Defaults to 0.0.
- Returns:
Result api object.
- Return type:
- load_anns(ids)
Load anns with the specified ids.
- Parameters:
ids (List[int]) – Integer ids specifying anns.
- Returns:
Loaded annotation objects.
- Return type:
List[dict]
- load_cats(ids)
Load cats with the specified ids.
- Parameters:
ids (List[int]) – Integer ids specifying cats.
- Returns:
Loaded category objects.
- Return type:
List[dict]
- load_imgs(ids)
Load imgs with the specified ids.
- Parameters:
ids (List[int]) – Integer ids specifying imgs.
- Returns:
Loaded image objects.
- Return type:
List[dict]
- static load_json(json_file, use_deepcopy=False)
Load a json file.
- Parameters:
json_file (Union[str, os.PathLike, pathlib.PosixPath, dict, list]) – Path to the json file or data dict/list.
use_deepcopy (Optional[bool], optional) – If True, use deep copy. Defaults to False.
- Returns:
Loaded json data.
- Return type:
dict
- property print_function: Callable
Get the function used for printing/logging messages.
- Returns:
Print/log function.
- Return type:
Callable
- showAnns(anns, draw_bbox=False)
Display the specified annotations.
- Parameters:
anns (List[dict]) – Annotations to display.
draw_bbox (Optional[bool], optional) – Whether to display bbox. Defaults to False.
- to_dict(separate_fn=False)
Convert to a standard python dictionary.
- Parameters:
separate_fn (bool, optional) – Whether to separate the fn category. Defaults to False.
- Returns:
Standard python dictionary containing the COCO data.
- Return type:
dict