tf.keras.backend.cast
| View source on GitHub |
Преобразует тензор в другой тип данных и возвращает его.
tf.keras.backend.cast(
x, dtype
)
Вы можете преобразовать Keras переменную, но она по-прежнему вернёт Keras тензор.
| Аргументы | |
|---|---|
x | Keras тензор (или переменная). |
dtype | Строка, либо ('float16', 'float32', или 'float64'). |
| Возвращает | |
|---|---|
Keras тензор с типом данных dtype. |
Примеры:
Преобразуйте переменную float32 в тензор float64
input = tf.keras.backend.ones(shape=(1,3)) print(input) <tf.Variable 'Variable:0' shape=(1, 3) dtype=float32, numpy=array([[1., 1., 1.]], dtype=float32)> cast_input = tf.keras.backend.cast(input, dtype='float64') print(cast_input) tf.Tensor([[1. 1. 1.]], shape=(1, 3), dtype=float64)
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.3/api_docs/python/tf/keras/backend/cast