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)
| 87 | |
| 88 | |
| 89 | def 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 | |
| 126 | def set_tensor_shapes(tensors, shapes): |
nothing calls this directly
no test coverage detected