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)
| 103 | |
| 104 | |
| 105 | def 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 | |
| 143 | def _load_graph_def_from_event_file(event_file_path): |
no test coverage detected