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

Method _run_internal_graph

tensorflow/python/keras/engine/network.py:769–866  ·  view source on GitHub ↗

Computes output tensors for new inputs. # Note: - Can be run on non-Keras tensors. Arguments: inputs: Tensor or nested structure of Tensors. training: Boolean learning phase. mask: (Optional) Tensor or nested structure of Tensors. Returns: Two l

(self, inputs, training=None, mask=None)

Source from the content-addressed store, hash-verified

767 return output_shapes
768
769 def _run_internal_graph(self, inputs, training=None, mask=None):
770 """Computes output tensors for new inputs.
771
772 # Note:
773 - Can be run on non-Keras tensors.
774
775 Arguments:
776 inputs: Tensor or nested structure of Tensors.
777 training: Boolean learning phase.
778 mask: (Optional) Tensor or nested structure of Tensors.
779
780 Returns:
781 Two lists: output_tensors, output_masks
782 """
783 # Note: masking support is relevant mainly for Keras.
784 # It cannot be factored out without having the fully reimplement the network
785 # calling logic on the Keras side. We choose to incorporate it in
786 # Network because 1) it may be useful to fully support in tf.layers in
787 # the future and 2) Keras is a major user of Network. If you don't
788 # use masking, it does not interfere with regular behavior at all and you
789 # can ignore it.
790 inputs = nest.flatten(inputs)
791 if mask is None:
792 masks = [None for _ in range(len(inputs))]
793 else:
794 masks = nest.flatten(mask)
795
796 for input_t, mask in zip(inputs, masks):
797 input_t._keras_mask = mask
798
799 # Dictionary mapping reference tensors to computed tensors.
800 tensor_dict = {}
801
802 for x, y in zip(self.inputs, inputs):
803 tensor_dict[str(id(x))] = y
804
805 depth_keys = list(self._nodes_by_depth.keys())
806 depth_keys.sort(reverse=True)
807 # Ignore the InputLayers when computing the graph.
808 depth_keys = depth_keys[1:]
809
810 for depth in depth_keys:
811 nodes = self._nodes_by_depth[depth]
812 for node in nodes:
813 # This is always a single layer, never a list.
814 layer = node.outbound_layer
815
816 if all(
817 str(id(tensor)) in tensor_dict
818 for tensor in nest.flatten(node.input_tensors)):
819
820 # Call layer (reapplying ops to new inputs).
821 computed_tensors = nest.map_structure(
822 lambda t: tensor_dict[str(id(t))], node.input_tensors)
823
824 # Ensure `training` arg propagation if applicable.
825 kwargs = copy.copy(node.arguments) if node.arguments else {}
826 argspec = self._layer_call_argspecs[layer].args

Callers 2

compute_maskMethod · 0.95
callMethod · 0.95

Calls 11

allFunction · 0.85
typeFunction · 0.85
anyFunction · 0.85
setdefaultMethod · 0.80
rangeFunction · 0.50
flattenMethod · 0.45
keysMethod · 0.45
sortMethod · 0.45
copyMethod · 0.45
valuesMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected