def np2tensor(img, bgr2rgb=True, data_range=1.0, normalize=False, change_range=True, add_batch=True):
    '\n    Converts a numpy image array into a Tensor array.\n    Parameters:\n        img (numpy array): the input image numpy array\n        add_batch (bool): choose if new tensor needs batch dimension added\n    '
    if (not isinstance(img, np.ndarray)):
        raise TypeError('Got unexpected object type, expected np.ndarray')
    if change_range:
        if np.issubdtype(img.dtype, np.integer):
            info = np.iinfo
        elif np.issubdtype(img.dtype, np.floating):
            info = np.finfo
        img = ((img * data_range) / info(img.dtype).max)
    img = torch.from_numpy(np.ascontiguousarray(np.transpose(img, (2, 0, 1)))).float()
    if bgr2rgb:
        if (img.shape[0] == 3):
            img = bgr_to_rgb(img)
        elif (img.shape[0] == 4):
            img = bgra_to_rgba(img)
    if add_batch:
        img.unsqueeze_(0)
    if normalize:
        img = norm(img)
    return img
Converts a numpy image array into a Tensor array.
Parameters:
    img (numpy array): the input image numpy array
    add_batch (bool): choose if new tensor needs batch dimension added
def np2tensor(img, bgr2rgb=True, data_range=1.0, normalize=False, change_range=True, add_batch=True):
    '\n    Converts a numpy image array into a Tensor array.\n    Parameters:\n        img (numpy array): the input image numpy array\n        add_batch (bool): choose if new tensor needs batch dimension added\n    '
    if (not isinstance(img, np.ndarray)):
        raise TypeError('Got unexpected object type, expected np.ndarray')
    if change_range:
        if np.issubdtype(img.dtype, np.integer):
            info = np.iinfo
        elif np.issubdtype(img.dtype, np.floating):
            info = np.finfo
        img = ((img * data_range) / info(img.dtype).max)
    img = torch.from_numpy(np.ascontiguousarray(np.transpose(img, (2, 0, 1)))).float()
    if bgr2rgb:
        if (img.shape[0] == 3):
            img = bgr_to_rgb(img)
        elif (img.shape[0] == 4):
            img = bgra_to_rgba(img)
    if add_batch:
        img.unsqueeze_(0)
    if normalize:
        img = norm(img)
    return img