code: def test_to_tensor():
      # 3D Input
      data_in = np.random.uniform(0, 255, (300, 300, 3)).astype(
          dtype=np.uint8
      )
      out_nd = transforms.ToTensor()(np.array(data_in, dtype="uint8"))
      assert_almost_equal(
          out_nd.asnumpy(),
          np.transpose(
              data_in.astype(dtype=np.float32) / 255.0, (2, 0, 1)
          ),
      )
  
      # 4D Input
      data_in = np.random.uniform(0, 255, (5, 300, 300, 3)).astype(
          dtype=np.uint8
      )
      out_nd = transforms.ToTensor()(np.array(data_in, dtype="uint8"))
      assert_almost_equal(
          out_nd.asnumpy(),
          np.transpose(
              data_in.astype(dtype=np.float32) / 255.0, (0, 3, 1, 2)
          ),
      )
  
      # Invalid Input
      invalid_data_in = np.random.uniform(
          0, 255, (5, 5, 300, 300, 3)
      ).astype(dtype=np.uint8)
      transformer = transforms.ToTensor()
      assertRaises(MXNetError, transformer, invalid_data_in)
  
      # Bounds (0->0, 255->1)
      data_in = np.zeros((10, 20, 3)).astype(dtype=np.uint8)
      out_nd = transforms.ToTensor()(np.array(data_in, dtype="uint8"))
      assert same(
          out_nd.asnumpy(),
          np.transpose(
              np.zeros(data_in.shape, dtype=np.float32), (2, 0, 1)
          ),
      )
  
      data_in = np.full((10, 20, 3), 255).astype(dtype=np.uint8)
      out_nd = transforms.ToTensor()(np.array(data_in, dtype="uint8"))
      assert same(
          out_nd.asnumpy(),
          np.transpose(
              np.ones(data_in.shape, dtype=np.float32), (2, 0, 1)
          ),
      )
  
imports: import os
  from collections import namedtuple
  from uuid import uuid4
  import numpy
  import mxnet
  from mxnet import gluon, autograd, np, npx
  from mxnet.test_utils import use_np, assert_almost_equal, check_gluon_hybridize_consistency, same, check_symbolic_backward
  from common import assertRaises, xfail_when_nonstandard_decimal_separator
  import random
  from mxnet.base import MXNetError
  from mxnet.gluon.data.vision import transforms
  from mxnet import image
  import pytest
label_desc: Use image node_id 1 for calling a global function with example usage: test_to_tensor() without return types