class_docstr: Codec for Tensor.
docstr: Returns an encoded `TensorProto` for the given `tf.Tensor`.
docstr_tok: ["Returns","an","encoded","`","TensorProto","`","for","the","given","`","tf.Tensor","`","."]
code: def do_encode(self, tensor_value, encode_fn):
      """Returns an encoded `TensorProto` for the given `tf.Tensor`."""
      del encode_fn
      encoded_tensor = struct_pb2.StructuredValue()
      if isinstance(tensor_value, ops.EagerTensor):
          encoded_tensor.tensor_value.CopyFrom(
              tensor_util.make_tensor_proto(tensor_value.numpy())
          )
      else:
          if tensor_value.op.type == "Const":
              encoded_tensor.tensor_value.CopyFrom(
                  tensor_value.op.get_attr("value")
              )
          else:
              raise nested_structure_coder.NotEncodableError(
                  f"No encoder for object {str(tensor_value)} of type"
                  f" {type(tensor_value)}."
              )
      return encoded_tensor
  
imports: from typing import Union
  import numpy
  from tensorflow.core.framework import types_pb2
  from tensorflow.core.protobuf import struct_pb2
  from tensorflow.python.eager import context
  from tensorflow.python.eager import execute
  from tensorflow.python.framework import constant_tensor_conversion
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.framework import tensor_conversion_registry
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.profiler import trace
  from tensorflow.python.saved_model import nested_structure_coder
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 2 for calling the _ConstantTensorCodec obj's underlying member method code with example usage: obj.do_encode(tensor_value, encode_fn) and returns: encoded_tensor