Asserts that the output shape from the layer matches the actual shape.
(expected, actual)
| 149 | kwargs)) |
| 150 | |
| 151 | def assert_shapes_equal(expected, actual): |
| 152 | """Asserts that the output shape from the layer matches the actual shape.""" |
| 153 | if len(expected) != len(actual): |
| 154 | raise AssertionError( |
| 155 | 'When testing layer %s, for input %s, found output_shape=' |
| 156 | '%s but expected to find %s.\nFull kwargs: %s' % |
| 157 | (layer_cls.__name__, x, actual, expected, kwargs)) |
| 158 | |
| 159 | for expected_dim, actual_dim in zip(expected, actual): |
| 160 | if isinstance(expected_dim, tensor_shape.Dimension): |
| 161 | expected_dim = expected_dim.value |
| 162 | if isinstance(actual_dim, tensor_shape.Dimension): |
| 163 | actual_dim = actual_dim.value |
| 164 | if expected_dim is not None and expected_dim != actual_dim: |
| 165 | raise AssertionError( |
| 166 | 'When testing layer %s, for input %s, found output_shape=' |
| 167 | '%s but expected to find %s.\nFull kwargs: %s' % |
| 168 | (layer_cls.__name__, x, actual, expected, kwargs)) |
| 169 | |
| 170 | if expected_output_shape is not None: |
| 171 | assert_shapes_equal(tensor_shape.TensorShape(expected_output_shape), |