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

Function load_tensor_from_event

tensorflow/python/debug/lib/debug_data.py:105–140  ·  view source on GitHub ↗

Load a tensor from an Event proto. Args: event: The Event proto, assumed to hold a tensor value in its summary.value[0] field. Returns: The tensor value loaded from the event file, as a `numpy.ndarray`, if representation of the tensor value by a `numpy.ndarray` is possible.

(event)

Source from the content-addressed store, hash-verified

103
104
105def load_tensor_from_event(event):
106 """Load a tensor from an Event proto.
107
108 Args:
109 event: The Event proto, assumed to hold a tensor value in its
110 summary.value[0] field.
111
112 Returns:
113 The tensor value loaded from the event file, as a `numpy.ndarray`, if
114 representation of the tensor value by a `numpy.ndarray` is possible.
115 For uninitialized Tensors, returns `None`. For Tensors of data types that
116 cannot be represented as `numpy.ndarray` (e.g., `tf.resource`), return
117 the `TensorProto` protobuf object without converting it to a
118 `numpy.ndarray`.
119 """
120
121 tensor_proto = event.summary.value[0].tensor
122 shape = tensor_util.TensorShapeProtoToList(tensor_proto.tensor_shape)
123 num_elements = 1
124 for shape_dim in shape:
125 num_elements *= shape_dim
126
127 if tensor_proto.tensor_content or tensor_proto.string_val or not num_elements:
128 # Initialized tensor or empty tensor.
129 if tensor_proto.dtype == types_pb2.DT_RESOURCE:
130 tensor_value = InconvertibleTensorProto(tensor_proto)
131 else:
132 try:
133 tensor_value = tensor_util.MakeNdarray(tensor_proto)
134 except KeyError:
135 tensor_value = InconvertibleTensorProto(tensor_proto)
136 else:
137 # Uninitialized tensor or tensor of unconvertible data type.
138 tensor_value = InconvertibleTensorProto(tensor_proto, False)
139
140 return tensor_value
141
142
143def _load_graph_def_from_event_file(event_file_path):

Callers 1

Calls 1

Tested by

no test coverage detected