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:
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=None)
Deprecated: Download images (no longer supported).
- Parameters:
tarDir (Any, optional) – Target directory. Not used.
imgIds (
list[int] |None) – Image ids. Not used.
- Raises:
DeprecationWarning – Always raised, function is deprecated.
- dump(output_file)
Dump annotations to a json file.
- Parameters:
output_file (
str|PathLike) – Path to the output json file.
- getAnnIds(imgIds=None, catIds=None, areaRng=None, iscrowd=None)
Get ann ids that satisfy given filter conditions.
- Parameters:
imgIds (
list[int] |None) – Get anns for given images. Defaults to None.catIds (
list[int] |None) – Get anns for given categories. Defaults to None.areaRng (
list[float] |None) – Get anns for given area range (e.g. [0, inf]). Defaults to None.iscrowd (
bool|None) – 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=None, supNms=None, catIds=None)
Get category ids that satisfy given filter conditions.
- Parameters:
catNms (
list[str] |None) – Get categories for given cat names. Defaults to None.supNms (
list[str] |None) – Get categories for given supercategory names. Defaults to None.catIds (
list[int] |None) – Get categories for given ids. Defaults to None.
- Returns:
Integer array of cat ids.
- Return type:
list[int]
- getImgIds(imgIds=None, catIds=None)
Get image ids that satisfy given filter conditions.
- Parameters:
imgIds (
list[int] |None) – Get images for given ids. Defaults to None.catIds (
list[int] |None) – Get images with all given categories. Defaults to None.
- Returns:
Integer array of img ids.
- Return type:
list[int]
- get_ann_ids(img_ids=None, cat_ids=None, area_rng=None, iscrowd=None)
Get ann ids that satisfy given filter conditions.
- Parameters:
img_ids (
list[int] |None) – Get anns for given imgs. Defaults to None.cat_ids (
list[int] |None) – Get anns for given cats. Defaults to None.area_rng (
list[float] |None) – Get anns with area less than this. Defaults to None.iscrowd (
bool|None) – Get anns for given crowd label. Defaults to None.
- Returns:
Integer array of ann ids.
- Return type:
list[int]
- get_cat_ids(cat_names=None, sup_names=None, cat_ids=None)
Get cat ids that satisfy given filter conditions.
- Parameters:
cat_names (
list[str] |None) – Get cats for given names. Defaults to None.sup_names (
list[str] |None) – Get cats for given supercategory names. Defaults to None.cat_ids (
list[int] |None) – Get cats for given ids. Defaults to None.
- Returns:
Integer array of cat ids.
- Return type:
list[int]
- get_img_ids(img_ids=None, cat_ids=None)
Get img ids that satisfy given filter conditions.
- Parameters:
img_ids (
list[int] |None) – Get imgs for given ids. Defaults to None.cat_ids (
list[int] |None) – Get imgs with all given cats. Defaults to None.
- 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=None)
Load annotations with the specified ids.
- Parameters:
ids (
list[int] |int|None) – Integer ids specifying annotations. Defaults to None.- Returns:
Loaded annotation objects.
- Return type:
list[dict]
- loadCats(ids=None)
Load categories with the specified ids.
- Parameters:
ids (
list[int] |int|None) – Integer ids specifying categories. Defaults to None.- Returns:
Loaded category objects.
- Return type:
list[dict]
- loadImgs(ids=None)
Load images with the specified ids.
- Parameters:
ids (
list[int] |int|None) – Integer ids specifying images. Defaults to None.- Returns:
Loaded image objects.
- Return type:
list[dict]
- loadNumpyAnnotations(data)
Convert result data from array to anns.
- Parameters:
data (
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 (
str|PathLike|PosixPath|WindowsPath|dict|list|ndarray) – File name of result file or numpy array.min_score (
float) – 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 (
str|PathLike|PosixPath|WindowsPath|dict|list) – Path to the json file or data dict/list.use_deepcopy (
bool|None) – 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 (
bool|None) – Whether to display bbox. Defaults to False.
- to_dict(separate_fn=False)
Convert to a standard python dictionary.
- Parameters:
separate_fn (
bool) – Whether to separate the fn category. Defaults to False.- Returns:
Standard python dictionary containing the COCO data.
- Return type:
dict