-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Add stubs for pycocotools #9086
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
Changes from 27 commits
ae9e2d2
2a1c251
81675f9
07febd5
9c204ee
4faa515
3fe497d
2699f58
87039a7
feb9114
f03e88c
8aca487
a8cd2d5
8b52fca
8596fab
294e104
749bdfa
cd6001f
9536495
5985956
980f360
5f09960
4a0bac0
de905d2
99a28bd
a686ab9
3f668c3
34b09cd
7472602
6e5bb73
8857817
d9a3b8e
f7a13bf
4d29cf0
3f28dcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| version = "2.0.*" | ||
|
|
||
| [tool.stubtest] | ||
| ignore_missing_stub = false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from typing_extensions import TypedDict | ||
|
|
||
| # Unused in this module, but imported in multiple submodules. | ||
| class _EncodedRLE(TypedDict): # noqa: Y049 | ||
| size: list[int] | ||
| counts: str | bytes |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| from _typeshed import Incomplete, Self | ||
| from pathlib import Path | ||
| from typing import Generic, TypeVar, overload | ||
| from typing_extensions import Literal, TypeAlias, TypedDict | ||
|
|
||
| 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 | ||
|
|
||
| class _Image(TypedDict): | ||
| id: int | ||
| width: int | ||
| height: int | ||
| file_name: str | ||
|
|
||
| _TPolygonSegmentation: TypeAlias = list[list[float]] | ||
|
|
||
| class _RLE(TypedDict): | ||
| size: list[int] | ||
| counts: list[int] | ||
|
|
||
| class _Annotation(TypedDict): | ||
| id: int | ||
| image_id: int | ||
| category_id: int | ||
| segmentation: _TPolygonSegmentation | _RLE | _EncodedRLE | ||
| area: float | ||
| bbox: list[float] | ||
| iscrowd: int | ||
|
|
||
| _TSeg = TypeVar("_TSeg", _TPolygonSegmentation, _RLE, _EncodedRLE) | ||
|
|
||
| class _AnnotationG(TypedDict, Generic[_TSeg]): | ||
| id: int | ||
| image_id: int | ||
| category_id: int | ||
| segmentation: _TSeg | ||
| area: float | ||
| bbox: list[float] | ||
| iscrowd: int | ||
|
|
||
| class _Category(TypedDict): | ||
| id: int | ||
| name: str | ||
| supercategory: str | ||
|
|
||
| class _Dataset(TypedDict): | ||
| images: list[_Image] | ||
| annotations: list[_Annotation] | ||
| categories: list[_Category] | ||
|
|
||
| class COCO: | ||
| anns: dict[int, _Annotation] | ||
| dataset: _Dataset | ||
| cats: dict[int, _Category] | ||
| imgs: dict[int, _Image] | ||
| imgToAnns: dict[int, list[_Annotation]] | ||
| catToImgs: dict[int, list[int]] | ||
| def __init__(self, annotation_file: str | Path | None = ...) -> None: ... | ||
| def createIndex(self) -> None: ... | ||
| def info(self) -> None: ... | ||
| def getAnnIds( | ||
| self, imgIds: list[int] | int = ..., catIds: list[int] | int = ..., areaRng: list[float] = ..., iscrowd: bool | None = ... | ||
| ) -> list[int]: ... | ||
| def getCatIds( | ||
| self, catNms: list[str] | str = ..., supNms: list[str] | str = ..., catIds: list[int] | int = ... | ||
hoel-bagard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) -> list[int]: ... | ||
| def getImgIds(self, imgIds: list[int] | int = ..., catIds: list[int] | int = ...) -> list[int]: ... | ||
| def loadAnns(self, ids: list[int] | int = ...) -> list[_Annotation]: ... | ||
| def loadCats(self, ids: list[int] | int = ...) -> list[_Category]: ... | ||
| def loadImgs(self, ids: list[int] | int = ...) -> list[_Image]: ... | ||
hoel-bagard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def showAnns(self, anns: list[_Annotation], draw_bbox: bool = ...) -> None: ... | ||
hoel-bagard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def loadRes(self: Self, resFile: str) -> Self: ... | ||
hoel-bagard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def download(self, tarDir: str | None = ..., imgIds: list[int] = ...) -> Literal[-1] | None: ... | ||
hoel-bagard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def loadNumpyAnnotations(self, data: _NDArray) -> 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]: ... | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| from _typeshed import Incomplete | ||
| from typing_extensions import Literal, TypeAlias, TypedDict | ||
|
|
||
| from .coco import COCO | ||
|
|
||
| # TODO: Use numpy types when #5768 is resolved. | ||
| # import numpy as np | ||
| # import numpy.typing as npt | ||
|
|
||
| _NDArray: TypeAlias = Incomplete | ||
| _TIOU: TypeAlias = Literal["segm", "bbox", "keypoints"] | ||
|
|
||
| class _EvaluationResult(TypedDict): | ||
| image_id: int | ||
| category_id: int | ||
| aRng: list[int] | ||
| maxDet: int | ||
| 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 COCOeval: | ||
| cocoGt: COCO | ||
| cocoDt: COCO | ||
| evalImgs: list[_EvaluationResult] | ||
| eval: _EvaluationResult | ||
| params: Params | ||
| stats: _NDArray | ||
| # stats: npt.NDArray[np.float64] | ||
| ious: dict[tuple[int, int], list[float]] | ||
| def __init__(self, cocoGt: COCO | None = ..., cocoDt: COCO | None = ..., iouType: _TIOU = ...) -> 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) -> _EvaluationResult: ... | ||
| def accumulate(self, p: Params | None = ...) -> None: ... | ||
| def summarize(self) -> None: ... | ||
|
|
||
| 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[int] | ||
| 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 = ...) -> None: ... | ||
| def setDetParams(self) -> None: ... | ||
| def setKpParams(self) -> None: ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from _typeshed import Incomplete | ||
| from typing import Any, overload | ||
| from typing_extensions import TypeAlias | ||
|
|
||
| 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] | ||
|
|
||
| def iou( | ||
| dt: _NDArrayUInt32 | list[float] | list[_EncodedRLE], | ||
| gt: _NDArrayUInt32 | list[float] | list[_EncodedRLE], | ||
| pyiscrowd: list[int] | _NDArrayUInt8, | ||
| ) -> list[Any] | _NDArrayFloat64: ... | ||
|
Comment on lines
+16
to
+20
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (No change requested, just pointing out to clarify:) This function should have the parameters annotated as |
||
| def merge(rleObjs: list[_EncodedRLE], intersect: int = ...) -> _EncodedRLE: ... | ||
|
|
||
| # ignore an "overlapping overloads" error due to _NDArrayInt32 being an alias for `Incomplete` for now | ||
| @overload | ||
| def frPyObjects(pyobj: _NDArrayUInt32 | list[list[int]] | list[_EncodedRLE], h: int, w: int) -> list[_EncodedRLE]: ... # type: ignore[misc] | ||
| @overload | ||
| def frPyObjects(pyobj: list[int] | _EncodedRLE, h: int, w: int) -> _EncodedRLE: ... | ||
| def encode(bimask: _NDArrayUInt8) -> _EncodedRLE: ... | ||
| def decode(rleObjs: _EncodedRLE) -> _NDArrayUInt8: ... | ||
| def area(rleObjs: _EncodedRLE) -> _NPUInt32: ... | ||
| def toBbox(rleObjs: _EncodedRLE) -> _NDArrayFloat64: ... | ||
Uh oh!
There was an error while loading. Please reload this page.