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

Method _set_mask_metadata

tensorflow/python/keras/engine/base_layer.py:1964–2002  ·  view source on GitHub ↗
(self, inputs, outputs, previous_mask)

Source from the content-addressed store, hash-verified

1962 self.add_loss(mean_activity_loss, inputs=inputs)
1963
1964 def _set_mask_metadata(self, inputs, outputs, previous_mask):
1965 flat_outputs = nest.flatten(outputs)
1966
1967 mask_already_computed = (
1968 getattr(self, '_compute_output_and_mask_jointly', False) or
1969 all(getattr(x, '_keras_mask', None) is not None for x in flat_outputs))
1970
1971 # Only compute the mask if the Layer explicitly supports masking or has
1972 # overridden `compute_mask`.
1973 should_compute_mask = (
1974 hasattr(self, 'compute_mask') and
1975 (self.supports_masking or
1976 not getattr(self.compute_mask, '_is_default', False)))
1977
1978 if mask_already_computed:
1979 flat_masks = [getattr(x, '_keras_mask', None) for x in flat_outputs]
1980 elif not should_compute_mask:
1981 flat_masks = [None for _ in flat_outputs]
1982 else:
1983 output_masks = self.compute_mask(inputs, previous_mask)
1984 # `compute_mask` can return a single `None` even when a Layer
1985 # has multiple outputs.
1986 if output_masks is None:
1987 flat_masks = [None for _ in flat_outputs]
1988 else:
1989 flat_masks = nest.flatten(output_masks)
1990
1991 for output, mask in zip(flat_outputs, flat_masks):
1992 try:
1993 output._keras_mask = mask
1994 except AttributeError:
1995 # C Type such as np.ndarray.
1996 pass
1997
1998 if tf_utils.are_all_symbolic_tensors(flat_outputs):
1999 for output in flat_outputs:
2000 if getattr(output, '_keras_mask', None) is not None:
2001 # Do not track masks for `TensorFlowOpLayer` construction.
2002 output._keras_mask._keras_history_checked = True
2003
2004 def _collect_input_masks(self, inputs, args, kwargs):
2005 """Checks if `mask` argument was passed, else gathers mask from inputs."""

Callers 1

__call__Method · 0.95

Calls 3

compute_maskMethod · 0.95
allFunction · 0.85
flattenMethod · 0.45

Tested by

no test coverage detected