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

Add stubs for pycocotools #9086

Merged
merged 35 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ae9e2d2
Added the coco.pyi file.
hoel-bagard Nov 4, 2022
2a1c251
Added the mask.pyi file.
hoel-bagard Nov 4, 2022
81675f9
Added the cocoeval.pyi file.
hoel-bagard Nov 4, 2022
07febd5
Added imports to the __init__.
hoel-bagard Nov 4, 2022
9c204ee
Merge branch 'python:main' into main
hoel-bagard Nov 4, 2022
4faa515
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2022
3fe497d
Fixed some ids being allowed to also be simple int/str instead of list.
hoel-bagard Nov 4, 2022
2699f58
Merged with main.
hoel-bagard Nov 4, 2022
87039a7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2022
feb9114
Fixed name missing an '_'
hoel-bagard Nov 4, 2022
f03e88c
Moved some imports from typing to typing_extensions.
hoel-bagard Nov 4, 2022
8aca487
Removed numpy dependency.
hoel-bagard Nov 4, 2022
a8cd2d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2022
8b52fca
Removed extra underscores.
hoel-bagard Nov 4, 2022
8596fab
Merge branch 'main' of github.com:hoel-bagard/typeshed
hoel-bagard Nov 4, 2022
294e104
Fixed TypeAlias import.
hoel-bagard Nov 4, 2022
749bdfa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2022
cd6001f
Now using the Self type from _typeshed.
hoel-bagard Nov 4, 2022
9536495
Added references to #5768 next to the commented out numpy imports.
hoel-bagard Nov 4, 2022
5985956
Removed the pycocotools entry from pyrightconfig.stricter.json.
hoel-bagard Nov 4, 2022
980f360
Added missing return type.
hoel-bagard Nov 4, 2022
5f09960
Fix mypy error
AlexWaygood Nov 4, 2022
4a0bac0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2022
de905d2
Added 'None' type to the COCO init arg as it is the default value.
hoel-bagard Nov 5, 2022
99a28bd
Moved the private types to __init__ and the files they are used.
hoel-bagard Nov 7, 2022
a686ab9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2022
3f668c3
Removed comment.
hoel-bagard Nov 16, 2022
34b09cd
Updated imports.
hoel-bagard Nov 28, 2022
7472602
Replace list by Collection/Sequence.
hoel-bagard Nov 28, 2022
6e5bb73
Replace list by Collection/Sequence.
hoel-bagard Nov 28, 2022
8857817
Replace list by Collection/Sequence.
hoel-bagard Nov 28, 2022
d9a3b8e
Replace list by Collection/Sequence.
hoel-bagard Nov 28, 2022
f7a13bf
Replace list by Sequence.
hoel-bagard Nov 28, 2022
4d29cf0
Replace Self type by COCO,
hoel-bagard Nov 28, 2022
3f28dcb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 28, 2022
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
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"stubs/peewee",
"stubs/psutil",
"stubs/psycopg2",
"stubs/pycocotools",
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
"stubs/pyflakes",
"stubs/Pygments",
"stubs/PyMySQL",
Expand Down
4 changes: 4 additions & 0 deletions stubs/pycocotools/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version = "2.0.*"

[tool.stubtest]
ignore_missing_stub = false
3 changes: 3 additions & 0 deletions stubs/pycocotools/pycocotools/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .coco import *
from .cocoeval import *
from .mask import *
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
46 changes: 46 additions & 0 deletions stubs/pycocotools/pycocotools/coco.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from _typeshed import Incomplete, Self
from pathlib import Path
from typing import overload
from typing_extensions import Literal, TypeAlias

from .coco_types import _RLE, _Annotation, _AnnotationG, _Category, _Dataset, _EncodedRLE, _Image, _TPolygonSegmentation

# import numpy as np
# import numpy.typing as npt

PYTHON_VERSION: Incomplete
_NDArray: TypeAlias = Incomplete

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: ...
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 = ...
hoel-bagard marked this conversation as resolved.
Show resolved Hide resolved
) -> list[int]: ...
def getCatIds(
self, catNms: list[str] | str = ..., supNms: list[str] | str = ..., catIds: list[int] | int = ...
hoel-bagard marked this conversation as resolved.
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.
Show resolved Hide resolved
def showAnns(self, anns: list[_Annotation], draw_bbox: bool = ...) -> None: ...
hoel-bagard marked this conversation as resolved.
Show resolved Hide resolved
def loadRes(self: Self, resFile: str) -> Self: ...
hoel-bagard marked this conversation as resolved.
Show resolved Hide resolved
def download(self, tarDir: str | None = ..., imgIds: list[int] = ...) -> Literal[-1] | None: ...
hoel-bagard marked this conversation as resolved.
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]: ...
71 changes: 71 additions & 0 deletions stubs/pycocotools/pycocotools/coco_types.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from _typeshed import Incomplete
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
from typing import Generic, TypeVar
from typing_extensions import TypeAlias, TypedDict

# import numpy as np
# import numpy.typing as npt

_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 _EncodedRLE(TypedDict):
size: list[int]
counts: str | bytes

class _Annotation(TypedDict):
id: int
image_id: int
category_id: int
segmentation: _TPolygonSegmentation | _RLE | _EncodedRLE
area: float
bbox: list[float]
iscrowd: int # Either 1 or 0

_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 # Either 1 or 0

class _Category(TypedDict):
id: int
name: str
supercategory: str

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 _Dataset(TypedDict):
images: list[_Image]
annotations: list[_Annotation]
categories: list[_Category]
48 changes: 48 additions & 0 deletions stubs/pycocotools/pycocotools/cocoeval.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from _typeshed import Incomplete
from typing_extensions import Literal, TypeAlias

from .coco import COCO
from .coco_types import _EvaluationResult

# import numpy as np
# import numpy.typing as npt

_NDArray: TypeAlias = Incomplete
_TIOU: TypeAlias = Literal["segm", "bbox", "keypoints"]

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: ...
28 changes: 28 additions & 0 deletions stubs/pycocotools/pycocotools/mask.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from _typeshed import Incomplete
from typing import overload
from typing_extensions import TypeAlias

from .coco_types import _EncodedRLE

# 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 | _NDArrayFloat64: ...
def merge(rleObjs: list[_EncodedRLE], intersect: int = ...): ...
@overload
def frPyObjects(pyobj: _NDArrayUInt32 | list[list[int]] | list[_EncodedRLE], h: int, w: int) -> list[_EncodedRLE]: ...
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
@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: ...