code: def from_tensor(
      self, *, tensor, batched, name="TensorSpec.from_tensor"
  ):
      # Check whether underspecified
      if self.is_underspecified():
          raise TensorforceError.unexpected()
  
      # Check whether TensorFlow tensor
      if not isinstance(tensor, tf.Tensor):
          raise TensorforceError.type(
              name=name, argument="tensor", dtype=type(tensor)
          )
  
      # Check whether tensor type and shape match
      if tf_util.dtype(x=tensor) != self.type:
          raise TensorforceError.value(
              name=name, argument="tensor.dtype", value=tensor
          )
      if tf_util.shape(x=tensor)[int(batched) :] != self.shape:
          raise TensorforceError.value(
              name=name, argument="tensor.shape", value=tensor
          )
  
      # Convert tensor value to Numpy array
      value = tensor.numpy()
  
      # Check for nan or inf
      if np.isnan(value).any() or np.isinf(value).any():
          raise TensorforceError.value(
              name=name, argument="tensor", value=value
          )
  
      # Check num_values
      if self.type == "int" and self.num_values is not None:
          if (value < 0).any() or (value >= self.num_values).any():
              raise TensorforceError.value(
                  name=name, argument="tensor", value=value
              )
  
      # Check min/max_value
      elif self.type == "int" or self.type == "float":
          if self.min_value is not None:
              if (value < self.min_value).any():
                  raise TensorforceError.value(
                      name=name, argument="tensor", value=value
                  )
          if self.max_value is not None:
              if (value > self.max_value).any():
                  raise TensorforceError.value(
                      name=name, argument="tensor", value=value
                  )
  
      # If singleton shape, return Python object instead of Numpy array
      if self.shape == () and not batched:
          value = value.item()
  
      return value
  
imports: from functools import total_ordering
  import numpy
  import tensorflow
  from tensorforce import TensorforceError, util
  from tensorforce.core.utils import tf_util
label_desc: Use image node_id 12 for calling the TensorSpec obj's underlying member method code with example usage: obj.from_tensor() and returns: value