keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.58k stars 19.42k forks source link

request: type information for layers #19836

Open ghsanti opened 3 months ago

ghsanti commented 3 months ago

Executing any of the layers, for example:

    z_in = Input(shape=(123,), name="name")

The return type is Unknown, which means we don't have hints for the methods of z_in.

Certainly we could do cast(KerasTensor,z_in) but that would need to be done with every layer, every time.

Any ideas @mehtamansi29 ?

fchollet commented 3 months ago

In the example above, z_in has a dtype attribute which in this case has value "float32".

ghsanti commented 3 months ago

But I mean type information for type hints, currently z_in is marked as Unknown. This is from the blueprint of Input, for example:

(function) def Input(
    shape: Unknown | None = None,
    batch_size: Unknown | None = None,
    dtype: Unknown | None = None,
    sparse: Unknown | None = None,
    batch_shape: Unknown | None = None,
    name: Unknown | None = None,
    tensor: Unknown | None = None,
    optional: bool = False
) -> (Unknown | Any | list[Unknown])

This makes it difficult: -> (Unknown | Any | list[Unknown])

@fchollet

ghsanti commented 2 months ago

Linked issue was solved using Jedi (or a workaround for Pylance.)

But this issue isn't resolved yet i.e how to get typing information on class instances.

ghsanti commented 2 months ago

Is this planned? Do you need help with it? @mehtamansi29

I'd find having this types quite useful since I'm new to Keras.