tf.keras.backend.is_keras_tensor
Stay organized with collections
Save and categorize content based on your preferences.
Returns whether x
is a Keras tensor.
tf.keras.backend.is_keras_tensor(
x
)
A "Keras tensor" is a tensor that was returned by a Keras layer,
(Layer
class) or by Input
.
Arguments |
x
|
A candidate tensor.
|
Returns |
A boolean: Whether the argument is a Keras tensor.
|
Raises |
ValueError
|
In case x is not a symbolic tensor.
|
Examples:
import tensorflow as tf
import numpy
from keras import backend as K
from keras.layers import Input, Dense
np_var = numpy.array([1, 2])
K.is_keras_tensor(np_var) # A numpy array is not a symbolic tensor.
ValueError
k_var = tf.compat.v1.placeholder('float32', shape=(1,1))
K.is_keras_tensor(k_var) # A variable indirectly created outside of
keras is not a Keras tensor.
False
keras_var = K.variable(np_var)
K.is_keras_tensor(keras_var) # A variable created with the keras
backend is not a Keras tensor.
False
keras_placeholder = K.placeholder(shape=(2, 4, 5))
K.is_keras_tensor(keras_placeholder) # A placeholder is not a Keras
tensor.
False
keras_input = Input([10])
K.is_keras_tensor(keras_input) # An Input is a Keras tensor.
True
keras_layer_output = Dense(10)(keras_input)
K.is_keras_tensor(keras_layer_output) # Any Keras layer output is a
Keras tensor.
True
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.backend.is_keras_tensor\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/keras/backend.py#L937-L988) |\n\nReturns whether `x` is a Keras tensor.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.backend.is_keras_tensor`](/api_docs/python/tf/keras/backend/is_keras_tensor)\n\n\u003cbr /\u003e\n\n tf.keras.backend.is_keras_tensor(\n x\n )\n\nA \"Keras tensor\" is a tensor that was returned by a Keras layer,\n(`Layer` class) or by `Input`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|-----|---------------------|\n| `x` | A candidate tensor. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A boolean: Whether the argument is a Keras tensor. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|---------------------------------------|\n| `ValueError` | In case `x` is not a symbolic tensor. |\n\n\u003cbr /\u003e\n\n#### Examples:\n\n import tensorflow as tf\n import numpy\n from keras import backend as K\n from keras.layers import Input, Dense\n np_var = numpy.array([1, 2])\n K.is_keras_tensor(np_var) # A numpy array is not a symbolic tensor.\n ValueError\n k_var = tf.compat.v1.placeholder('float32', shape=(1,1))\n K.is_keras_tensor(k_var) # A variable indirectly created outside of\n keras is not a Keras tensor.\n False\n keras_var = K.variable(np_var)\n K.is_keras_tensor(keras_var) # A variable created with the keras\n backend is not a Keras tensor.\n False\n keras_placeholder = K.placeholder(shape=(2, 4, 5))\n K.is_keras_tensor(keras_placeholder) # A placeholder is not a Keras\n tensor.\n False\n keras_input = Input([10])\n K.is_keras_tensor(keras_input) # An Input is a Keras tensor.\n True\n keras_layer_output = Dense(10)(keras_input)\n K.is_keras_tensor(keras_layer_output) # Any Keras layer output is a\n Keras tensor.\n True"]]