MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / placeholder

Function placeholder

tensorflow/python/keras/backend.py:986–1052  ·  view source on GitHub ↗

Instantiates a placeholder tensor and returns it. Arguments: shape: Shape of the placeholder (integer tuple, may include `None` entries). ndim: Number of axes of the tensor. At least one of {`shape`, `ndim`} must be specified. If both are specified, `shap

(shape=None,
                ndim=None,
                dtype=None,
                sparse=False,
                name=None,
                ragged=False)

Source from the content-addressed store, hash-verified

984
985@keras_export('keras.backend.placeholder')
986def placeholder(shape=None,
987 ndim=None,
988 dtype=None,
989 sparse=False,
990 name=None,
991 ragged=False):
992 """Instantiates a placeholder tensor and returns it.
993
994 Arguments:
995 shape: Shape of the placeholder
996 (integer tuple, may include `None` entries).
997 ndim: Number of axes of the tensor.
998 At least one of {`shape`, `ndim`} must be specified.
999 If both are specified, `shape` is used.
1000 dtype: Placeholder type.
1001 sparse: Boolean, whether the placeholder should have a sparse type.
1002 name: Optional name string for the placeholder.
1003 ragged: Boolean, whether the placeholder should have a ragged type.
1004 In this case, values of 'None' in the 'shape' argument represent
1005 ragged dimensions. For more information about RaggedTensors, see this
1006 [guide](https://www.tensorflow.org/guide/ragged_tensors).
1007
1008 Raises:
1009 ValueError: If called with eager execution
1010 ValueError: If called with sparse = True and ragged = True.
1011
1012 Returns:
1013 Tensor instance (with Keras metadata included).
1014
1015 Examples:
1016 ```python
1017 >>> from keras import backend as K
1018 >>> input_ph = K.placeholder(shape=(2, 4, 5))
1019 >>> input_ph
1020 <tf.Tensor 'Placeholder_4:0' shape=(2, 4, 5) dtype=float32>
1021 ```
1022 """
1023 if sparse and ragged:
1024 raise ValueError(
1025 'Cannot set both sparse and ragged to True when creating a placeholder.'
1026 )
1027
1028 if dtype is None:
1029 dtype = floatx()
1030 if not shape:
1031 if ndim:
1032 shape = tuple([None for _ in range(ndim)])
1033 with get_graph().as_default():
1034 if sparse:
1035 x = array_ops.sparse_placeholder(dtype, shape=shape, name=name)
1036 elif ragged:
1037 ragged_rank = 0
1038 for i in range(1, len(shape)):
1039 if shape[i] is None:
1040 ragged_rank += 1
1041 else:
1042 break
1043 value_shape = shape[(ragged_rank + 1):]

Callers 1

Calls 6

floatxFunction · 0.85
tupleFunction · 0.85
get_graphFunction · 0.85
rangeFunction · 0.50
as_defaultMethod · 0.45
placeholderMethod · 0.45

Tested by 1