torchcvnn.transforms.ToTensor¶
- class torchcvnn.transforms.ToTensor(dtype: str)[source]¶
Converts numpy array or torch tensor to torch tensor of specified dtype. This transform converts input data to a PyTorch tensor with the specified data type. It handles both numpy arrays and existing PyTorch tensors as input.
- Parameters:
dtype (str) – Target data type for the output tensor. Should be one of PyTorch’s supported dtype strings (e.g. ‘float32’, ‘float64’, ‘int32’, etc.)
- Returns:
The converted tensor with the specified dtype.
- Return type:
Example
>>> transform = ToTensor(dtype='float32') >>> x_numpy = np.array([1, 2, 3]) >>> x_tensor = transform(x_numpy) # converts to torch.FloatTensor >>> x_existing = torch.tensor([1, 2, 3], dtype=torch.int32) >>> x_converted = transform(x_existing) # converts to torch.FloatTensor
Methods
__init__
(dtype)