code: def convert(input_: DATA_TYPE, type_: str, dtype_: DTYPE = None):
      """
      Convert tf.Tensor/np.ndarray to specified format.
  
      Usage:
      ```
      x = np.random.random((10, 10))
      convert(x, type_="tf", dtype_=tf.float32)
  
      x = tf.random.normal((10, 10))
      convert(x, type_="numpy", dtype_=np.float32)
      ```
  
      :param input_: The tf.Tensor/np.ndarray to convert.
      :param type_: The target type, "tf" means tf.Tensor, "numpy" means np.ndarray.
      :param dtype_: The target dtype.
      :return The results of conversion.
      """
      # todo: we should also convert `int`, `float`, `bool` to scalar Tensor/numpy
      if type_ == "tf":
          if isinstance(input_, np.ndarray):
              return tf.convert_to_tensor(input_, dtype=dtype_)
          elif isinstance(input_, tf.Tensor):
              if dtype_ is not None and input_.dtype != dtype_:
                  return tf.cast(input_, dtype=dtype_)
              else:
                  return input_
          else:
              invalidInputError(False, f"Unkonwn type: {type(input_)}")
      elif type_ == "numpy":
          if isinstance(input_, tf.Tensor):
              input_ = input_.numpy()
          if isinstance(input_, np.ndarray):
              if dtype_ is not None and input_.dtype != dtype_:
                  return input_.astype(dtype_)
              else:
                  return input_
          else:
              invalidInputError(False, f"Unkonwn type: {type(input_)}")
      else:
          invalidInputError(False, f"Invalid target type: {type_}")
  
file_path: BigDL/python/nano/src/bigdl/nano/utils/tf/data.py
imports: from typing import Union, Optional, Sequence, Dict
  import numpy
  import tensorflow
  from bigdl.nano.utils.common import invalidInputError
label_desc: Use image node_id 4 for calling a global function with example usage: convert(input_, type_, dtype_) and returns: tf, tf, input_, input_, input_