A placeholder op that passes through input when its output is not fed.
tf.compat.v1.placeholder_with_default(
    input, shape, name=None
)
 Migrate to TF2
This API is strongly discouraged for use with eager execution and tf.function. The primary use of this API is for testing computation wrapped within a tf.function where the input tensors might not have statically known fully-defined shapes. The same can be achieved by creating a concrete function from the tf.function with a tf.TensorSpec input which has partially defined shapes. For example, the code
@tf.function
def f():
  x = tf.compat.v1.placeholder_with_default(
      tf.constant([[1., 2., 3.], [4., 5., 6.]]), [None, 3])
  y = tf.constant([[1.],[2.], [3.]])
  z = tf.matmul(x, y)
  assert z.shape[0] == None
  assert z.shape[1] == 1
 f()
can easily be replaced by
@tf.function def f(x): y = tf.constant([[1.],[2.], [3.]]) z = tf.matmul(x, y) assert z.shape[0] == None assert z.shape[1] == 1
g = f.get_concrete_function(tf.TensorSpec([None, 3]))
You can learn more about tf.function at Better performance with tf.function.
| Args | |
|---|---|
| input | A Tensor. The default value to produce when output is not fed. | 
| shape | A tf.TensorShapeor list ofints. The (possibly partial) shape of the tensor. | 
| name | A name for the operation (optional). | 
| Returns | |
|---|---|
| A Tensor. Has the same type asinput. | 
    © 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
    https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/compat/v1/placeholder_with_default