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

Function get_tensors_from_tensor_names

tensorflow/lite/python/util.py:89–123  ·  view source on GitHub ↗

Gets the Tensors associated with the `tensor_names` in the provided graph. Args: graph: TensorFlow Graph. tensor_names: List of strings that represent names of tensors in the graph. Returns: A list of Tensor objects in the same order the names are provided. Raises: ValueErro

(graph, tensor_names)

Source from the content-addressed store, hash-verified

87
88
89def get_tensors_from_tensor_names(graph, tensor_names):
90 """Gets the Tensors associated with the `tensor_names` in the provided graph.
91
92 Args:
93 graph: TensorFlow Graph.
94 tensor_names: List of strings that represent names of tensors in the graph.
95
96 Returns:
97 A list of Tensor objects in the same order the names are provided.
98
99 Raises:
100 ValueError:
101 tensor_names contains an invalid tensor name.
102 """
103 # Get the list of all of the tensors.
104 tensor_name_to_tensor = {}
105 for op in graph.get_operations():
106 for tensor in op.values():
107 tensor_name_to_tensor[get_tensor_name(tensor)] = tensor
108
109 # Get the tensors associated with tensor_names.
110 tensors = []
111 invalid_tensors = []
112 for name in tensor_names:
113 tensor = tensor_name_to_tensor.get(name)
114 if tensor is None:
115 invalid_tensors.append(name)
116 else:
117 tensors.append(tensor)
118
119 # Throw ValueError if any user input names are not valid tensors.
120 if invalid_tensors:
121 raise ValueError("Invalid tensors '{}' were found.".format(
122 ",".join(invalid_tensors)))
123 return tensors
124
125
126def set_tensor_shapes(tensors, shapes):

Callers

nothing calls this directly

Calls 7

get_tensor_nameFunction · 0.85
get_operationsMethod · 0.80
valuesMethod · 0.45
getMethod · 0.45
appendMethod · 0.45
formatMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected