View source on GitHub |
Specifies the rank, dtype and shape of every input to a layer.
tf.keras.InputSpec(
dtype=None,
shape=None,
ndim=None,
max_ndim=None,
min_ndim=None,
axes=None,
allow_last_axis_squeeze=False,
name=None
)
Layers can expose (if appropriate) an input_spec
attribute:
an instance of InputSpec
, or a nested structure of InputSpec
instances
(one per input tensor). These objects enable the layer to run input
compatibility checks for input structure, input rank, input shape, and
input dtype for the first argument of Layer.call
.
A None
entry in a shape is compatible with any dimension.
Example:
class MyLayer(Layer):
def __init__(self):
super().__init__()
# The layer will accept inputs with
# shape (*, 28, 28) & (*, 28, 28, 1)
# and raise an appropriate error message otherwise.
self.input_spec = InputSpec(
shape=(None, 28, 28, 1),
allow_last_axis_squeeze=True)
Methods
from_config
@classmethod
from_config( config )
get_config
get_config()