tensorflow/core/debug/debug_io_utils.cc
// Encapsulates the tensor value inside a vector of Event protos. Large tensors
// are broken up to multiple protos to fit the chunk_size_limit. In each Event
// proto the field summary.tensor carries the content of the tensor.
// If chunk_size_limit <= 0, the tensor will not be broken into chunks, i.e., a
// length-1 vector will be returned, regardless of the size of the tensor.
Encapsulates the tensor value inside a vector of Event protos. Large tensors
are broken up to multiple protos to fit the chunk_size_limit. In each Event
proto the field summary.tensor carries the content of the tensor.
If chunk_size_limit <= 0, the tensor will not be broken into chunks, i.e., a
length-1 vector will be returned, regardless of the size of the tensor.
Encapsulates the tensor value inside a vector of Event protos . Large tensors are broken up to multiple protos to fit the chunk_size_limit . In each Event proto the field summary . tensor carries the content of the tensor . If chunk_size_limit < = 0 the tensor will not be broken into chunks i . e . a length - 1 vector will be returned regardless of the size of the tensor .
Status WrapTensorAsEvents(const DebugNodeKey& debug_node_key,
                          const Tensor& tensor, const uint64 wall_time_us,
                          const size_t chunk_size_limit,
                          std::vector<Event>* events) {
  TensorProto tensor_proto;
  if (tensor.dtype() == DT_STRING) {
    tensor.AsProtoField(&tensor_proto);
    TF_RETURN_IF_ERROR(WrapStringTensorAsEvents(
        debug_node_key, wall_time_us, chunk_size_limit, &tensor_proto, events));
  } else {
    tensor.AsProtoTensorContent(&tensor_proto);
    const size_t total_length = tensor_proto.tensor_content().size();
    const size_t chunk_size_ub =
        chunk_size_limit > 0 ? chunk_size_limit : total_length;
    const size_t num_chunks =
        (total_length == 0)
            ? 1
            : (total_length + chunk_size_ub - 1) / chunk_size_ub;
    for (size_t i = 0; i < num_chunks; ++i) {
      const size_t pos = i * chunk_size_ub;
      const size_t len =
          (i == num_chunks - 1) ? (total_length - pos) : chunk_size_ub;
      Event event = PrepareChunkEventProto(debug_node_key, wall_time_us,
                                           num_chunks, i, tensor_proto.dtype(),
                                           tensor_proto.tensor_shape());
      event.mutable_summary()
          ->mutable_value(0)
          ->mutable_tensor()
          ->set_tensor_content(tensor_proto.tensor_content().substr(pos, len));
      events->push_back(std::move(event));
    }
  }
  return Status::OK();
}
Status WrapTensorAsEvents ( const DebugNodeKey & debug_node_key , const Tensor & tensor , const uint64 wall_time_us , const size_t chunk_size_limit , std :: vector < Event > * events ) { TensorProto tensor_proto ; if ( tensor . dtype ( ) == DT_STRING ) { tensor . AsProtoField ( & tensor_proto ) ; TF_RETURN_IF_ERROR ( WrapStringTensorAsEvents ( debug_node_key , wall_time_us , chunk_size_limit , & tensor_proto , events ) ) ; } else { tensor . AsProtoTensorContent ( & tensor_proto ) ; const size_t total_length = tensor_proto . tensor_content ( ) . size ( ) ; const size_t chunk_size_ub = chunk_size_limit > 0 ? chunk_size_limit : total_length ; const size_t num_chunks = ( total_length == 0 ) ? 1 : ( total_length + chunk_size_ub - 1 ) / chunk_size_ub ; for ( size_t i = 0 ; i < num_chunks ; ++ i ) { const size_t pos = i * chunk_size_ub ; const size_t len = ( i == num_chunks - 1 ) ? ( total_length - pos ) : chunk_size_ub ; Event event = PrepareChunkEventProto ( debug_node_key , wall_time_us , num_chunks , i , tensor_proto . dtype ( ) , tensor_proto . tensor_shape ( ) ) ; event . mutable_summary ( ) -> mutable_value ( 0 ) -> mutable_tensor ( ) -> set_tensor_content ( tensor_proto . tensor_content ( ) . substr ( pos , len ) ) ; events -> push_back ( std :: move ( event ) ) ; } } return Status :: OK ( ) ; }
Encapsulates the tensor value inside a vector of Event protos.
Encapsulates the tensor value inside a vector of Event protos .
// Treat DT_STRING specially, so that tensor_util.MakeNdarray in Python can // convert the TensorProto to string-type numpy array. MakeNdarray does not // work with strings encoded by AsProtoTensorContent() in tensor_content.