Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix todo in pycocotools #13182

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stubs/pycocotools/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
version = "2.0.*"
upstream_repository = "https://github.com/ppwwyyxx/cocoapi"
requires = ["numpy"]
kbaikov marked this conversation as resolved.
Show resolved Hide resolved
# numpy>=2.0.0 requires Python >=3.9
requires_python = ">=3.9"
17 changes: 6 additions & 11 deletions stubs/pycocotools/pycocotools/coco.pyi
Original file line number Diff line number Diff line change
@@ -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

from . import _EncodedRLE
import numpy as np
import numpy.typing as npt

# TODO: Use numpy types when #5768 is resolved.
# import numpy as np
# import numpy.typing as npt
from . import _EncodedRLE

PYTHON_VERSION: Incomplete
_NDArray: TypeAlias = Incomplete
PYTHON_VERSION: int

class _Image(TypedDict):
id: int
Expand Down Expand Up @@ -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]: ...
22 changes: 4 additions & 18 deletions stubs/pycocotools/pycocotools/cocoeval.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from _typeshed import Incomplete
from typing import Literal, TypedDict
from typing_extensions import TypeAlias

from .coco import COCO
import numpy as np
import numpy.typing as npt

# TODO: Use numpy types when #5768 is resolved.
# import numpy as np
# import numpy.typing as npt
from .coco import COCO

_NDArray: TypeAlias = Incomplete
_NDArray: TypeAlias = npt.NDArray[np.float64]
_TIOU: TypeAlias = Literal["segm", "bbox", "keypoints"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to rename this to _NDFloatArray or something similar ?


class _ImageEvaluationResult(TypedDict):
Expand All @@ -19,24 +17,17 @@ class _ImageEvaluationResult(TypedDict):
dtIds: list[int]
gtIds: list[int]
dtMatches: _NDArray
# dtMatches: npt.NDArray[np.float64]
gtMatches: _NDArray
# gtMatches: npt.NDArray[np.float64]
dtScores: list[float]
gtIgnore: _NDArray
# gtIgnore: npt.NDArray[np.float64]
dtIgnore: _NDArray
# dtIgnore: npt.NDArray[np.float64]

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

class COCOeval:
Expand All @@ -46,13 +37,11 @@ class COCOeval:
eval: _EvaluationResult
params: Params
stats: _NDArray
# stats: npt.NDArray[np.float64]
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 evaluateImg(self, imgId: int, catId: int, aRng: list[int], maxDet: int) -> _ImageEvaluationResult: ...
def accumulate(self, p: Params | None = None) -> None: ...
def summarize(self) -> None: ...
Expand All @@ -61,15 +50,12 @@ class Params:
imgIds: list[int]
catIds: list[int]
iouThrs: _NDArray
# iouThrs: npt.NDArray[np.float64]
recThrs: _NDArray
# recThrs: npt.NDArray[np.float64]
maxDets: list[int]
areaRng: list[list[float]]
areaRngLbl: list[str]
useCats: int
kpt_oks_sigmas: _NDArray
# kpt_oks_sigmas: npt.NDArray[np.float64]
iouType: _TIOU
useSegm: int | None
def __init__(self, iouType: _TIOU = "segm") -> None: ...
Expand Down
16 changes: 7 additions & 9 deletions stubs/pycocotools/pycocotools/mask.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from _typeshed import Incomplete
from typing import Any, overload
from typing_extensions import TypeAlias

from . import _EncodedRLE
import numpy as np
import numpy.typing as npt

# TODO: Use numpy types when #5768 is resolved.
# import numpy as np
# import numpy.typing as npt
from . import _EncodedRLE

_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],
Expand Down
Loading