Computes the output shape of the layer. If the layer has not been built, this method will call `build` on the layer. This assumes that the layer will later be used with inputs that match the input shape provided here. Arguments: input_shape: Shape tuple (tuple of integers)
(self, input_shape)
| 618 | return cls(**config) |
| 619 | |
| 620 | def compute_output_shape(self, input_shape): |
| 621 | """Computes the output shape of the layer. |
| 622 | |
| 623 | If the layer has not been built, this method will call `build` on the |
| 624 | layer. This assumes that the layer will later be used with inputs that |
| 625 | match the input shape provided here. |
| 626 | |
| 627 | Arguments: |
| 628 | input_shape: Shape tuple (tuple of integers) |
| 629 | or list of shape tuples (one per output tensor of the layer). |
| 630 | Shape tuples can include None for free dimensions, |
| 631 | instead of an integer. |
| 632 | |
| 633 | Returns: |
| 634 | An input shape tuple. |
| 635 | """ |
| 636 | if context.executing_eagerly(): |
| 637 | # In this case we build the model first in order to do shape inference. |
| 638 | # This is acceptable because the framework only calls |
| 639 | # `compute_output_shape` on shape values that the layer would later be |
| 640 | # built for. It would however cause issues in case a user attempts to |
| 641 | # use `compute_output_shape` manually with shapes that are incompatible |
| 642 | # with the shape the Layer will be called on (these users will have to |
| 643 | # implement `compute_output_shape` themselves). |
| 644 | self._maybe_build(input_shape) |
| 645 | with context.graph_mode(): |
| 646 | graph = func_graph.FuncGraph('graph') |
| 647 | with graph.as_default(): |
| 648 | input_shape = tf_utils.convert_shapes(input_shape, to_tuples=False) |
| 649 | inputs = nest.map_structure( |
| 650 | base_layer_utils.generate_placeholders_from_shape, input_shape) |
| 651 | try: |
| 652 | if self._expects_training_arg: |
| 653 | outputs = self(inputs, training=False) |
| 654 | else: |
| 655 | outputs = self(inputs) |
| 656 | except TypeError: |
| 657 | raise NotImplementedError('We could not automatically infer ' |
| 658 | 'the static shape of the layer\'s output.' |
| 659 | ' Please implement the ' |
| 660 | '`compute_output_shape` method on your ' |
| 661 | 'layer (%s).' % self.__class__.__name__) |
| 662 | return nest.map_structure(lambda t: t.shape, outputs) |
| 663 | raise NotImplementedError |
| 664 | |
| 665 | @doc_controls.for_subclass_implementers |
| 666 | def compute_output_signature(self, input_signature): |
no test coverage detected