Set model's input and output specs based on the input data received. This is to be used for Model subclasses, which do not know at instantiation time what their inputs look like. Args: inputs: Single array, or list of arrays. The arrays could be placeholders, Numpy arrays
(self, inputs, outputs=None, training=None)
| 2668 | |
| 2669 | # TODO(omalleyt): Consider changing to a more descriptive function name. |
| 2670 | def _set_inputs(self, inputs, outputs=None, training=None): |
| 2671 | """Set model's input and output specs based on the input data received. |
| 2672 | |
| 2673 | This is to be used for Model subclasses, which do not know at instantiation |
| 2674 | time what their inputs look like. |
| 2675 | |
| 2676 | Args: |
| 2677 | inputs: Single array, or list of arrays. The arrays could be placeholders, |
| 2678 | Numpy arrays, data tensors, or TensorSpecs. |
| 2679 | - if placeholders: the model is built on top of these placeholders, |
| 2680 | and we expect Numpy data to be fed for them when calling `fit`/etc. |
| 2681 | - if Numpy data or TensorShapes: we create placeholders matching the |
| 2682 | TensorShapes or shapes of the Numpy arrays. We expect Numpy data to be |
| 2683 | fed for these placeholders when calling `fit`/etc. |
| 2684 | - if data tensors: the model is built on top of these tensors. |
| 2685 | We do not expect any Numpy data to be provided when calling `fit`/etc. |
| 2686 | outputs: None, a data tensor, or a list of tensors. If None, the |
| 2687 | outputs will be determined by invoking `self.call()`, otherwise the |
| 2688 | provided value will be used. |
| 2689 | training: Boolean or None. Only relevant in symbolic mode. Specifies |
| 2690 | whether to build the model's graph in inference mode (False), training |
| 2691 | mode (True), or using the Keras learning phase (None). |
| 2692 | Raises: |
| 2693 | ValueError: If dict inputs are passed to a Sequential Model where the |
| 2694 | first layer isn't FeatureLayer. |
| 2695 | """ |
| 2696 | inputs = self._set_input_attrs(inputs) |
| 2697 | |
| 2698 | if outputs is None: |
| 2699 | kwargs = {} |
| 2700 | if self._expects_training_arg: |
| 2701 | # In V2 mode, feeding `training=None` is not allowed because any value |
| 2702 | # explicitly passed by the user is respected, even `None`.` |
| 2703 | if training is None and not ops.executing_eagerly_outside_functions(): |
| 2704 | training = K.learning_phase() |
| 2705 | if training is not None: |
| 2706 | kwargs['training'] = training |
| 2707 | try: |
| 2708 | outputs = self(inputs, **kwargs) |
| 2709 | except NotImplementedError: |
| 2710 | # This Model or a submodel is dynamic and hasn't overridden |
| 2711 | # `compute_output_shape`. |
| 2712 | outputs = None |
| 2713 | |
| 2714 | self._set_output_attrs(outputs) |
| 2715 | |
| 2716 | @trackable.no_automatic_dependency_tracking |
| 2717 | def _set_input_attrs(self, inputs): |