View source on GitHub |
Specifies the rank, dtype and shape of every input to a layer.
tf.keras.layers.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.
A None entry in a shape is compatible with any dimension, a None shape is compatible with any shape.
Example:
class MyLayer(Layer):
def __init__(self):
super(MyLayer, self).__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()