transforms/transforms.py
def to_tensor(x, input_format='tensor', dtype=None, device=None):
    """Convert input data to tensor based on its format"""
    if input_format == 'tensor':
        return torch.as_tensor(x, dtype=dtype, device=device)
    elif input_format == 'pil':
        return torchvision.transforms.functional.to_tensor(x).to(
            dtype=dtype, device=device)
    elif input_format == 'list':
        return _to_list_of_tensor(x, dtype=dtype, device=device)
    elif input_format == 'tuple':
        return _to_tuple_of_tensor(x, dtype=dtype, device=device)
    elif input_format == 'dict':
        return _to_dict_of_tensor(x, dtype=dtype, device=device)
    elif input_format == 'comb':
        return _to_comb_of_tensor(x, dtype=dtype, device=device)
    else:
        raise ValueError("Unsupported format {}".format(input_format))
Convert input data to tensor based on its format
Convert input data to tensor based on its format
Convert input data to tensor based on its format
def to_tensor(x, input_format='tensor', dtype=None, device=None):
    if input_format == 'tensor':
        return torch.as_tensor(x, dtype=dtype, device=device)
    elif input_format == 'pil':
        return torchvision.transforms.functional.to_tensor(x).to(
            dtype=dtype, device=device)
    elif input_format == 'list':
        return _to_list_of_tensor(x, dtype=dtype, device=device)
    elif input_format == 'tuple':
        return _to_tuple_of_tensor(x, dtype=dtype, device=device)
    elif input_format == 'dict':
        return _to_dict_of_tensor(x, dtype=dtype, device=device)
    elif input_format == 'comb':
        return _to_comb_of_tensor(x, dtype=dtype, device=device)
    else:
        raise ValueError("Unsupported format {}".format(input_format))
def to_tensor ( x , input_format = 'tensor' , dtype = None , device = None ) : if input_format == 'tensor' : return torch . as_tensor ( x , dtype = dtype , device = device ) elif input_format == 'pil' : return torchvision . transforms . functional . to_tensor ( x ) . to ( dtype = dtype , device = device ) elif input_format == 'list' : return _to_list_of_tensor ( x , dtype = dtype , device = device ) elif input_format == 'tuple' : return _to_tuple_of_tensor ( x , dtype = dtype , device = device ) elif input_format == 'dict' : return _to_dict_of_tensor ( x , dtype = dtype , device = device ) elif input_format == 'comb' : return _to_comb_of_tensor ( x , dtype = dtype , device = device ) else : raise ValueError ( "Unsupported format {}" . format ( input_format ) )
Convert input data to tensor based on its format
Convert input data to tensor based on its format
"""Convert input data to tensor based on its format"""
x
input_format
dtype
device