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

Function _validate_shapes

tensorflow/contrib/tpu/python/tpu/keras_support.py:2148–2178  ·  view source on GitHub ↗

Validate that all layers in `model` have constant shape.

(model)

Source from the content-addressed store, hash-verified

2146
2147# pylint: disable=bad-continuation
2148def _validate_shapes(model):
2149 """Validate that all layers in `model` have constant shape."""
2150 for layer in model.layers:
2151 if isinstance(layer.input_shape, tuple):
2152 input_shapes = [layer.input_shape]
2153 else:
2154 input_shapes = layer.input_shape
2155
2156 if isinstance(layer.output_shape, tuple):
2157 output_shapes = [layer.output_shape]
2158 else:
2159 output_shapes = layer.output_shape
2160
2161 for shape in input_shapes + output_shapes:
2162 for dim in shape[1:]:
2163 if dim is None:
2164 raise ValueError(
2165 """
2166Layer %(layer)s has a variable shape in a non-batch dimension. TPU models must
2167have constant shapes for all operations.
2168
2169You may have to specify `input_length` for RNN/TimeDistributed layers.
2170
2171Layer: %(layer)s
2172Input shape: %(input_shape)s
2173Output shape: %(output_shape)s
2174 """ % {
2175 'layer': layer,
2176 'input_shape': layer.input_shape,
2177 'output_shape': layer.output_shape
2178 })
2179
2180
2181# pylint: enable=bad-continuation

Callers 1

tpu_modelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected