Fix todo in pycocotools (#13182)

Adds numpy types.
All the types were already there as comments.
This commit is contained in:
Konstantin Baikov
2024-12-28 05:06:19 +01:00
committed by GitHub
parent 43f637b5e2
commit 0ce397796c
4 changed files with 32 additions and 50 deletions

View File

@@ -1,2 +1,5 @@
version = "2.0.*"
upstream_repository = "https://github.com/ppwwyyxx/cocoapi"
requires = ["numpy>=2.0.0rc1; python_version>='3.9'"]
# numpy>=2.0.0 requires Python >=3.9
requires_python = ">=3.9"

View File

@@ -1,17 +1,14 @@
from _typeshed import Incomplete
from collections.abc import Collection, Sequence
from pathlib import Path
from typing import Generic, Literal, TypedDict, TypeVar, overload
from typing_extensions import TypeAlias
import numpy as np
import numpy.typing as npt
from . import _EncodedRLE
# TODO: Use numpy types when #5768 is resolved.
# import numpy as np
# import numpy.typing as npt
PYTHON_VERSION: Incomplete
_NDArray: TypeAlias = Incomplete
PYTHON_VERSION: int
class _Image(TypedDict):
id: int
@@ -82,13 +79,11 @@ class COCO:
def showAnns(self, anns: Sequence[_Annotation], draw_bbox: bool = False) -> None: ...
def loadRes(self, resFile: str) -> COCO: ...
def download(self, tarDir: str | None = None, imgIds: Collection[int] = []) -> Literal[-1] | None: ...
def loadNumpyAnnotations(self, data: _NDArray) -> list[_Annotation]: ...
# def loadNumpyAnnotations(self, data: npt.NDArray[np.float64]) -> list[_Annotation]: ...
def loadNumpyAnnotations(self, data: npt.NDArray[np.float64]) -> list[_Annotation]: ...
@overload
def annToRLE(self, ann: _AnnotationG[_RLE]) -> _RLE: ...
@overload
def annToRLE(self, ann: _AnnotationG[_EncodedRLE]) -> _EncodedRLE: ...
@overload
def annToRLE(self, ann: _AnnotationG[_TPolygonSegmentation]) -> _EncodedRLE: ...
def annToMask(self, ann: _Annotation) -> _NDArray: ...
# def annToMask(self, ann: _Annotation) -> npt.NDArray[np.uint8]: ...
def annToMask(self, ann: _Annotation) -> npt.NDArray[np.uint8]: ...

View File

@@ -1,14 +1,12 @@
from _typeshed import Incomplete
from typing import Literal, TypedDict
from typing_extensions import TypeAlias
import numpy as np
import numpy.typing as npt
from .coco import COCO
# TODO: Use numpy types when #5768 is resolved.
# import numpy as np
# import numpy.typing as npt
_NDArray: TypeAlias = Incomplete
_NDFloatArray: TypeAlias = npt.NDArray[np.float64]
_TIOU: TypeAlias = Literal["segm", "bbox", "keypoints"]
class _ImageEvaluationResult(TypedDict):
@@ -18,26 +16,19 @@ class _ImageEvaluationResult(TypedDict):
maxDet: int
dtIds: list[int]
gtIds: list[int]
dtMatches: _NDArray
# dtMatches: npt.NDArray[np.float64]
gtMatches: _NDArray
# gtMatches: npt.NDArray[np.float64]
dtMatches: _NDFloatArray
gtMatches: _NDFloatArray
dtScores: list[float]
gtIgnore: _NDArray
# gtIgnore: npt.NDArray[np.float64]
dtIgnore: _NDArray
# dtIgnore: npt.NDArray[np.float64]
gtIgnore: _NDFloatArray
dtIgnore: _NDFloatArray
class _EvaluationResult(TypedDict):
params: Params
counts: list[int]
date: str
# precision: npt.NDArray[np.float64]
precision: _NDArray
# recall: npt.NDArray[np.float64]
recall: _NDArray
# scores: npt.NDArray[np.float64]
scores: _NDArray
precision: _NDFloatArray
recall: _NDFloatArray
scores: _NDFloatArray
class COCOeval:
cocoGt: COCO
@@ -45,14 +36,12 @@ class COCOeval:
evalImgs: list[_ImageEvaluationResult]
eval: _EvaluationResult
params: Params
stats: _NDArray
# stats: npt.NDArray[np.float64]
stats: _NDFloatArray
ious: dict[tuple[int, int], list[float]]
def __init__(self, cocoGt: COCO | None = None, cocoDt: COCO | None = None, iouType: _TIOU = "segm") -> None: ...
def evaluate(self) -> None: ...
def computeIoU(self, imgId: int, catId: int) -> list[float]: ...
def computeOks(self, imgId: int, catId: int) -> _NDArray: ...
# def computeOks(self, imgId: int, catId: int) -> npt.NDArray[np.float64]: ...
def computeOks(self, imgId: int, catId: int) -> _NDFloatArray: ...
def evaluateImg(self, imgId: int, catId: int, aRng: list[int], maxDet: int) -> _ImageEvaluationResult: ...
def accumulate(self, p: Params | None = None) -> None: ...
def summarize(self) -> None: ...
@@ -60,16 +49,13 @@ class COCOeval:
class Params:
imgIds: list[int]
catIds: list[int]
iouThrs: _NDArray
# iouThrs: npt.NDArray[np.float64]
recThrs: _NDArray
# recThrs: npt.NDArray[np.float64]
iouThrs: _NDFloatArray
recThrs: _NDFloatArray
maxDets: list[int]
areaRng: list[list[float]]
areaRngLbl: list[str]
useCats: int
kpt_oks_sigmas: _NDArray
# kpt_oks_sigmas: npt.NDArray[np.float64]
kpt_oks_sigmas: _NDFloatArray
iouType: _TIOU
useSegm: int | None
def __init__(self, iouType: _TIOU = "segm") -> None: ...

View File

@@ -1,17 +1,15 @@
from _typeshed import Incomplete
from typing import Any, overload
from typing_extensions import TypeAlias
import numpy as np
import numpy.typing as npt
from . import _EncodedRLE
# TODO: Use numpy types when #5768 is resolved.
# import numpy as np
# import numpy.typing as npt
_NPUInt32: TypeAlias = Incomplete # np.uint32
_NDArrayUInt8: TypeAlias = Incomplete # npt.NDArray[np.uint8]
_NDArrayUInt32: TypeAlias = Incomplete # npt.NDArray[np.uint32]
_NDArrayFloat64: TypeAlias = Incomplete # npt.NDArray[np.float64]
_NPUInt32: TypeAlias = np.uint32
_NDArrayUInt8: TypeAlias = npt.NDArray[np.uint8]
_NDArrayUInt32: TypeAlias = npt.NDArray[np.uint32]
_NDArrayFloat64: TypeAlias = npt.NDArray[np.float64]
def iou(
dt: _NDArrayUInt32 | list[float] | list[_EncodedRLE],