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

Method __call__

tensorflow/python/keras/engine/base_layer.py:727–919  ·  view source on GitHub ↗

Wraps `call`, applying pre- and post-processing steps. Arguments: inputs: input tensor(s). *args: additional positional arguments to be passed to `self.call`. **kwargs: additional keyword arguments to be passed to `self.call`. Returns: Output tensor(s). Note:

(self, inputs, *args, **kwargs)

Source from the content-addressed store, hash-verified

725 return mask
726
727 def __call__(self, inputs, *args, **kwargs):
728 """Wraps `call`, applying pre- and post-processing steps.
729
730 Arguments:
731 inputs: input tensor(s).
732 *args: additional positional arguments to be passed to `self.call`.
733 **kwargs: additional keyword arguments to be passed to `self.call`.
734
735 Returns:
736 Output tensor(s).
737
738 Note:
739 - The following optional keyword arguments are reserved for specific uses:
740 * `training`: Boolean scalar tensor of Python boolean indicating
741 whether the `call` is meant for training or inference.
742 * `mask`: Boolean input mask.
743 - If the layer's `call` method takes a `mask` argument (as some Keras
744 layers do), its default value will be set to the mask generated
745 for `inputs` by the previous layer (if `input` did come from
746 a layer that generated a corresponding mask, i.e. if it came from
747 a Keras layer with masking support.
748
749 Raises:
750 ValueError: if the layer's `call` method returns None (an invalid value).
751 """
752 call_context = base_layer_utils.call_context()
753 input_list = nest.flatten(inputs)
754
755 # We will attempt to build a TF graph if & only if all inputs are symbolic.
756 # This is always the case in graph mode. It can also be the case in eager
757 # mode when all inputs can be traced back to `keras.Input()` (when building
758 # models using the functional API).
759 build_graph = tf_utils.are_all_symbolic_tensors(input_list)
760
761 # Accept NumPy and scalar inputs by converting to Tensors.
762 if any(isinstance(x, (np.ndarray, float, int)) for x in input_list):
763 def _convert_non_tensor(x):
764 # Don't call `ops.convert_to_tensor` on all `inputs` because
765 # `SparseTensors` can't be converted to `Tensor`.
766 if isinstance(x, (np.ndarray, float, int)):
767 return ops.convert_to_tensor(x)
768 return x
769 inputs = nest.map_structure(_convert_non_tensor, inputs)
770 input_list = nest.flatten(inputs)
771
772 # Handle `mask` propagation from previous layer to current layer. Masks can
773 # be propagated explicitly via the `mask` argument, or implicitly via
774 # setting the `_keras_mask` attribute on the inputs to a Layer. Masks passed
775 # explicitly take priority.
776 mask_arg_passed_by_framework = False
777 input_masks = self._collect_input_masks(inputs, args, kwargs)
778 if (self._expects_mask_arg and input_masks is not None and
779 not self._call_arg_was_passed('mask', args, kwargs)):
780 mask_arg_passed_by_framework = True
781 kwargs['mask'] = input_masks
782
783 # If `training` argument was not explicitly passed, propagate `training`
784 # value from this layer's calling layer.

Callers 1

applyMethod · 0.95

Calls 15

_collect_input_masksMethod · 0.95
_call_arg_was_passedMethod · 0.95
_get_call_arg_valueMethod · 0.95
_clear_lossesMethod · 0.95
_name_scopeMethod · 0.95
_maybe_buildMethod · 0.95
_maybe_cast_inputsMethod · 0.95
_symbolic_callMethod · 0.95
_set_mask_metadataMethod · 0.95
callMethod · 0.95

Tested by

no test coverage detected