(data)
Convert objects of various python types to :obj:`torch.Tensor`.

    Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`,
    :class:`Sequence`, :class:`int` and :class:`float`.
Convert objects of various python types to :obj:`torch.Tensor`.
Convert objects of various python types to : obj : torch . Tensor .
def to_tensor(data):
    """Convert objects of various python types to :obj:`torch.Tensor`.

    Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`,
    :class:`Sequence`, :class:`int` and :class:`float`.
    """
    if isinstance(data, torch.Tensor):
        return data
    elif isinstance(data, np.ndarray):
        return torch.from_numpy(data)
    elif isinstance(data, Sequence) and not mmcv.is_str(data):
        return torch.tensor(data)
    elif isinstance(data, int):
        return torch.LongTensor([data])
    elif isinstance(data, float):
        return torch.FloatTensor([data])
    else:
        raise TypeError('type {} cannot be converted to tensor.'.format(
            type(data)))
def to_tensor ( data ) : if isinstance ( data , torch . Tensor ) : return data elif isinstance ( data , np . ndarray ) : return torch . from_numpy ( data ) elif isinstance ( data , Sequence ) and not mmcv . is_str ( data ) : return torch . tensor ( data ) elif isinstance ( data , int ) : return torch . LongTensor ( [ data ] ) elif isinstance ( data , float ) : return torch . FloatTensor ( [ data ] ) else : raise TypeError ( 'type {} cannot be converted to tensor.' . format ( type ( data ) ) )