tensorflow: add tensorflow.keras.activations members#11444
tensorflow: add tensorflow.keras.activations members#11444JelleZijlstra merged 6 commits intopython:mainfrom
tensorflow: add tensorflow.keras.activations members#11444Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| threshold: FloatTensorCompatible | FloatDataSequence = 0.0, | ||
| ) -> Tensor: ... | ||
| def selu(x: _ActivationInput) -> Tensor: ... | ||
| def serialize(activation: Callable[..., Any], use_legacy_format: bool = False) -> str: ... |
There was a problem hiding this comment.
It can also return a dict:
In [15]: tensorflow.keras.activations.serialize(len)
Out[15]:
{'module': 'builtins',
'class_name': 'builtin_function_or_method',
'config': 'len',
'registered_name': 'builtin_function_or_method'}
In [16]: tensorflow.keras.activations.serialize(lambda: 42)
/Users/jelle/py/venvs/py311/lib/python3.11/site-packages/keras/src/activations.py:549: UserWarning: The object being serialized includes a `lambda`. This is unsafe. In order to reload the object, you will have to pass `safe_mode=False` to the loading function. Please avoid using `lambda` in the future, and use named Python functions instead. This is the `lambda` being serialized: tensorflow.keras.activations.serialize(lambda: 42)
fn_config = serialization_lib.serialize_keras_object(activation)
Out[16]:
{'value': ('4wAAAAAAAAAAAAAAAAEAAAADAAAA8wYAAACXAGQBUwApAk7pKgAAAKkAcgMAAADzAAAAAPofPGlw\neXRob24taW5wdXQtMTYtYjFiYzU1YjgzOGViPvoIPGxhbWJkYT5yBgAAAAEAAABzBgAAAIAAqHKA\nAHIEAAAA\n',
None,
None)}
In [17]: tensorflow.keras.activations.serialize(os.path.exists)
Out[17]:
{'module': 'builtins',
'class_name': 'function',
'config': 'exists',
'registered_name': 'function'}
There was a problem hiding this comment.
@JelleZijlstra Thanks for pointing it out, I've fixed it in d25b89f. Do you have a method / tool to find this kind of errors ?
For this particular function, looking at the source code would have made it clear that the return type could be a dict. Is it how you found out about it ?
When doing the TensorFlow stubs, I usually try a few inputs, but I can't test everything, so I often rely on what the docs say 😞
There was a problem hiding this comment.
Just by trying it out. I didn't do that for all functions, I think at first I was mostly curious what this function would do with a builtin.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
No description provided.