Skip to content

Commit

Permalink
Merge pull request #27571 from vjravi:doc-sprint
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 246607042
  • Loading branch information
tensorflower-gardener committed May 4, 2019
2 parents b541aeb + 4e44905 commit 242674c
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions tensorflow/python/keras/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1371,21 +1371,20 @@ def cast(x, dtype):
Returns:
Keras tensor with dtype `dtype`.
Example:
Examples:
Cast a float32 variable to a float64 tensor
```python
>>> from keras import backend as K
>>> input = K.placeholder((2, 3), dtype='float32')
>>> input
<tf.Tensor 'Placeholder_2:0' shape=(2, 3) dtype=float32>
# It doesn't work in-place as below.
>>> K.cast(input, dtype='float16')
<tf.Tensor 'Cast_1:0' shape=(2, 3) dtype=float16>
>>> input
<tf.Tensor 'Placeholder_2:0' shape=(2, 3) dtype=float32>
# you need to assign it.
>>> input = K.cast(input, dtype='float16')
>>> input
<tf.Tensor 'Cast_2:0' shape=(2, 3) dtype=float16>
>>> import tensorflow as tf
>>> from tensorflow.keras import backend as K
>>> input = K.ones(shape=(1,3))
>>> print(input)
>>> cast_input = K.cast(input, dtype='float64')
>>> print(cast_input)
<tf.Variable 'Variable:0' shape=(1, 3) dtype=float32,
numpy=array([[1., 1., 1.]], dtype=float32)>
tf.Tensor([[1. 1. 1.]], shape=(1, 3), dtype=float64)
```
"""
return math_ops.cast(x, dtype)
Expand Down Expand Up @@ -2662,6 +2661,17 @@ def batch_flatten(x):
Returns:
A tensor.
Examples:
Flattening a 3D tensor to 2D by collapsing the last dimension.
```python
>>> from tensorflow.keras import backend as K
>>> x_batch = K.ones(shape=(2, 3, 4, 5))
>>> x_batch_flatten = K.batch_flatten(x_batch)
>>> K.int_shape(x_batch_flatten)
(2, 60)
```
"""
x = array_ops.reshape(x, array_ops.stack([-1, prod(shape(x)[1:])]))
return x
Expand Down

0 comments on commit 242674c

Please sign in to comment.