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 Tensorflow stubs #13433

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
17 changes: 17 additions & 0 deletions stubs/tensorflow/tensorflow/keras/layers/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,21 @@ class GaussianDropout(Layer[tf.Tensor, tf.Tensor]):
name: str | None = None,
) -> None: ...

class MaxPooling2D(Layer[tf.Tensor, tf.Tensor]):
Copy link
Contributor

Choose a reason for hiding this comment

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

In the implementation this doesn't extend Layer directly, it extends BasePooling

https://github.com/keras-team/keras/blob/v3.3.3/keras/src/layers/pooling/base_pooling.py

def __init__(
self,
pool_size: int | tuple[int, int] = (2, 2),
strides: int | tuple[int, int] | None = None,
padding: Literal["valid", "same"] = "valid",
Copy link
Contributor

Choose a reason for hiding this comment

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

We might not be able to type this as a literal, the docs mention it's case-insensitive

https://www.tensorflow.org/api_docs/python/tf/keras/layers/MaxPool2D#args

there's examples of code that pass the value in all caps

https://github.com/search?q=padding%3D%22valid%22+language%3APython+MaxPool2D&type=code

data_format: None | Literal["channels_last", "channels_first"] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Literal["channels_last", "channels_first"] | None to match the style of the other optionals.

name: str | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation seems to accept **kwargs though I'm not sure the purpose

https://github.com/keras-team/keras/blob/v3.3.3/keras/src/layers/pooling/max_pooling2d.py#L96

) -> None: ...

MaxPool2D = MaxPooling2D

class GlobalAveragePooling2D(Layer[tf.Tensor, tf.Tensor]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comments as above re: ordering of | None, and the base class here is BaseGlobalPooling

def __init__(self, data_format: None | Literal["channels_last", "channels_first"] = None, keepdims: bool = False) -> None: ...

GlobalAvgPool2D = GlobalAveragePooling2D

def __getattr__(name: str) -> Incomplete: ...
Loading