rising.transforms.functional¶
Provides a functional interface for transforms (usually working on single tensors rather then collections thereof). All transformations are implemented to work on batched tensors. Implementations include:
Affine Transforms
Channel Transforms
Cropping Transforms
Device Transforms
Intensity Transforms
Spatial Transforms
Tensor Transforms
Utility Transforms
Affine Transforms¶
-
rising.transforms.functional.affine.
affine_image_transform
(image_batch, matrix_batch, output_size=None, adjust_size=False, interpolation_mode='bilinear', padding_mode='zeros', align_corners=False, reverse_order=False)[source][source]¶ Performs an affine transformation on a batch of images
- Parameters
image_batch (
Tensor
) – the batch to transform. Should have shape of [N, C, NDIM]matrix_batch (
Tensor
) – a batch of affine matrices with shape [N, NDIM, NDIM+1]output_size (
Optional
[tuple
]) – if given, this will be the resulting image size. Defaults toNone
adjust_size (
bool
) – if True, the resulting image size will be calculated dynamically to ensure that the whole image fits.interpolation_mode (
str
) – interpolation mode to calculate output values ‘bilinear’ | ‘nearest’. Default: ‘bilinear’padding_mode (
str
) – padding mode for outside grid values ‘zeros’ | ‘border’ | ‘reflection’. Default: ‘zeros’align_corners (
bool
) – Geometrically, we consider the pixels of the input as squares rather than points. If set to True, the extrema (-1 and 1) are considered as referring to the center points of the input’s corner pixels. If set to False, they are instead considered as referring to the corner points of the input’s corner pixels, making the sampling more resolution agnostic.
- Returns
transformed image
- Return type
Warning
When align_corners = True, the grid positions depend on the pixel size relative to the input image size, and so the locations sampled by grid_sample() will differ for the same input given at different resolutions (that is, after being upsampled or downsampled).
Notes
output_size
andadjust_size
are mutually exclusive. If None of them is set, the resulting image will have the same size as the input image.
-
rising.transforms.functional.affine.
affine_point_transform
(point_batch, matrix_batch)[source][source]¶ Function to perform an affine transformation onto point batches
- Parameters
point_batch (
Tensor
) – a point batch of shape [N, NP, NDIM]NP
is the number of points,N
is the batch size,NDIM
is the number of spatial dimensionsmatrix_batch (
Tensor
) – torch.Tensor a batch of affine matrices with shape [N, NDIM, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions
- Returns
- the batch of transformed points in cartesian coordinates)
[N, NP, NDIM]
NP
is the number of points,N
is the batch size,NDIM
is the number of spatial dimensions
- Return type
-
rising.transforms.functional.affine.
create_rotation
(rotation, batchsize, ndim, degree=False, device=None, dtype=None, image_transform=True)[source][source]¶ Formats the given scale parameters to a homogeneous transformation matrix
- Parameters
rotation (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the rotation factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a rotation angle of 0batchsize (
int
) – the number of samples per batchndim (
int
) – the dimensionality of the transformdegree (
bool
) – whether the given rotation(s) are in degrees. Only valid for rotation parameters, which aren’t passed as full transformation matrix.device (
Union
[device
,str
,None
]) – the device to put the resulting tensor to. Defaults to the torch default devicedtype (
Union
[dtype
,str
,None
]) – the dtype of the resulting trensor. Defaults to the torch default dtypeimage_transform (
bool
) – bool inverts the rotation matrix to match expected behavior when applied to an image, e.g. rotation > 0 should rotate the image counter clockwise but the grid clockwise
- Returns
- the homogeneous transformation matrix
[N, NDIM + 1, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions
- Return type
-
rising.transforms.functional.affine.
create_scale
(scale, batchsize, ndim, device=None, dtype=None, image_transform=True)[source][source]¶ Formats the given scale parameters to a homogeneous transformation matrix
- Parameters
scale (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the scale factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a scaling factor of 1batchsize (
int
) – the number of samples per batchndim (
int
) – the dimensionality of the transformdevice (
Union
[device
,str
,None
]) – the device to put the resulting tensor to. Defaults to the torch default devicedtype (
Union
[dtype
,str
,None
]) – the dtype of the resulting trensor. Defaults to the torch default dtypeimage_transform (
bool
) – inverts the scale matrix to match expected behavior when applied to an image, e.g. scale>1 increases the size of an image but decrease the size of an grid
- Returns
- the homogeneous transformation matrix
[N, NDIM + 1, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions
- Return type
-
rising.transforms.functional.affine.
create_translation
(offset, batchsize, ndim, device=None, dtype=None, image_transform=True)[source][source]¶ Formats the given translation parameters to a homogeneous transformation matrix
- Parameters
offset (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the translation offset(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a translation offset of 0batchsize (
int
) – the number of samples per batchndim (
int
) – the dimensionality of the transformdevice (
Union
[device
,str
,None
]) – the device to put the resulting tensor to. Defaults to the torch default devicedtype (
Union
[dtype
,str
,None
]) – the dtype of the resulting trensor. Defaults to the torch default dtypeimage_transform (
bool
) – bool inverts the translation matrix to match expected behavior when applied to an image, e.g. translation > 0 should move the image in the positive direction of an axis but the grid in the negative direction
- Returns
- the homogeneous transformation matrix [N, NDIM + 1, NDIM + 1],
N is the batch size and NDIM is the number of spatial dimensions
- Return type
-
rising.transforms.functional.affine.
parametrize_matrix
(scale, rotation, translation, batchsize, ndim, degree=False, device=None, dtype=None, image_transform=True)[source][source]¶ Formats the given scale parameters to a homogeneous transformation matrix
- Parameters
scale (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the scale factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a scaling factor of 1rotation (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the rotation factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a rotation factor of 1translation (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the translation offset(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a translation offset of 0batchsize (
int
) – the number of samples per batchndim (
int
) – the dimensionality of the transformdegree (
bool
) – whether the given rotation(s) are in degrees. Only valid for rotation parameters, which aren’t passed as full transformation matrix.device (
Union
[device
,str
,None
]) – the device to put the resulting tensor to. Defaults to the torch default devicedtype (
Union
[dtype
,str
,None
]) – the dtype of the resulting trensor. Defaults to the torch default dtypeimage_transform (
bool
) – bool adjusts transformation matrices such that they match the expected behavior on images (seecreate_scale()
andcreate_translation()
for more info)
- Returns
- the transformation matrix [N, NDIM, NDIM+1],
N
is the batch size and
NDIM
is the number of spatial dimensions
- the transformation matrix [N, NDIM, NDIM+1],
- Return type
affine_image_transform¶
-
rising.transforms.functional.affine.
affine_image_transform
(image_batch, matrix_batch, output_size=None, adjust_size=False, interpolation_mode='bilinear', padding_mode='zeros', align_corners=False, reverse_order=False)[source][source] Performs an affine transformation on a batch of images
- Parameters
image_batch (
Tensor
) – the batch to transform. Should have shape of [N, C, NDIM]matrix_batch (
Tensor
) – a batch of affine matrices with shape [N, NDIM, NDIM+1]output_size (
Optional
[tuple
]) – if given, this will be the resulting image size. Defaults toNone
adjust_size (
bool
) – if True, the resulting image size will be calculated dynamically to ensure that the whole image fits.interpolation_mode (
str
) – interpolation mode to calculate output values ‘bilinear’ | ‘nearest’. Default: ‘bilinear’padding_mode (
str
) – padding mode for outside grid values ‘zeros’ | ‘border’ | ‘reflection’. Default: ‘zeros’align_corners (
bool
) – Geometrically, we consider the pixels of the input as squares rather than points. If set to True, the extrema (-1 and 1) are considered as referring to the center points of the input’s corner pixels. If set to False, they are instead considered as referring to the corner points of the input’s corner pixels, making the sampling more resolution agnostic.
- Returns
transformed image
- Return type
Warning
When align_corners = True, the grid positions depend on the pixel size relative to the input image size, and so the locations sampled by grid_sample() will differ for the same input given at different resolutions (that is, after being upsampled or downsampled).
Notes
output_size
andadjust_size
are mutually exclusive. If None of them is set, the resulting image will have the same size as the input image.
affine_point_transform¶
-
rising.transforms.functional.affine.
affine_point_transform
(point_batch, matrix_batch)[source][source] Function to perform an affine transformation onto point batches
- Parameters
point_batch (
Tensor
) – a point batch of shape [N, NP, NDIM]NP
is the number of points,N
is the batch size,NDIM
is the number of spatial dimensionsmatrix_batch (
Tensor
) – torch.Tensor a batch of affine matrices with shape [N, NDIM, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions
- Returns
- the batch of transformed points in cartesian coordinates)
[N, NP, NDIM]
NP
is the number of points,N
is the batch size,NDIM
is the number of spatial dimensions
- Return type
parametrize_matrix¶
-
rising.transforms.functional.affine.
parametrize_matrix
(scale, rotation, translation, batchsize, ndim, degree=False, device=None, dtype=None, image_transform=True)[source][source] Formats the given scale parameters to a homogeneous transformation matrix
- Parameters
scale (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the scale factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a scaling factor of 1rotation (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the rotation factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a rotation factor of 1translation (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the translation offset(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a translation offset of 0batchsize (
int
) – the number of samples per batchndim (
int
) – the dimensionality of the transformdegree (
bool
) – whether the given rotation(s) are in degrees. Only valid for rotation parameters, which aren’t passed as full transformation matrix.device (
Union
[device
,str
,None
]) – the device to put the resulting tensor to. Defaults to the torch default devicedtype (
Union
[dtype
,str
,None
]) – the dtype of the resulting trensor. Defaults to the torch default dtypeimage_transform (
bool
) – bool adjusts transformation matrices such that they match the expected behavior on images (seecreate_scale()
andcreate_translation()
for more info)
- Returns
- the transformation matrix [N, NDIM, NDIM+1],
N
is the batch size and
NDIM
is the number of spatial dimensions
- the transformation matrix [N, NDIM, NDIM+1],
- Return type
create_rotation¶
-
rising.transforms.functional.affine.
create_rotation
(rotation, batchsize, ndim, degree=False, device=None, dtype=None, image_transform=True)[source][source] Formats the given scale parameters to a homogeneous transformation matrix
- Parameters
rotation (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the rotation factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a rotation angle of 0batchsize (
int
) – the number of samples per batchndim (
int
) – the dimensionality of the transformdegree (
bool
) – whether the given rotation(s) are in degrees. Only valid for rotation parameters, which aren’t passed as full transformation matrix.device (
Union
[device
,str
,None
]) – the device to put the resulting tensor to. Defaults to the torch default devicedtype (
Union
[dtype
,str
,None
]) – the dtype of the resulting trensor. Defaults to the torch default dtypeimage_transform (
bool
) – bool inverts the rotation matrix to match expected behavior when applied to an image, e.g. rotation > 0 should rotate the image counter clockwise but the grid clockwise
- Returns
- the homogeneous transformation matrix
[N, NDIM + 1, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions
- Return type
create_rotation_2d¶
create_rotation_3d¶
create_rotation_3d_0¶
create_rotation_3d_1¶
create_rotation_3d_2¶
create_scale¶
-
rising.transforms.functional.affine.
create_scale
(scale, batchsize, ndim, device=None, dtype=None, image_transform=True)[source][source] Formats the given scale parameters to a homogeneous transformation matrix
- Parameters
scale (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the scale factor(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a scaling factor of 1batchsize (
int
) – the number of samples per batchndim (
int
) – the dimensionality of the transformdevice (
Union
[device
,str
,None
]) – the device to put the resulting tensor to. Defaults to the torch default devicedtype (
Union
[dtype
,str
,None
]) – the dtype of the resulting trensor. Defaults to the torch default dtypeimage_transform (
bool
) – inverts the scale matrix to match expected behavior when applied to an image, e.g. scale>1 increases the size of an image but decrease the size of an grid
- Returns
- the homogeneous transformation matrix
[N, NDIM + 1, NDIM + 1], N is the batch size and NDIM is the number of spatial dimensions
- Return type
create_translation¶
-
rising.transforms.functional.affine.
create_translation
(offset, batchsize, ndim, device=None, dtype=None, image_transform=True)[source][source] Formats the given translation parameters to a homogeneous transformation matrix
- Parameters
offset (
Union
[int
,Sequence
[int
],float
,Sequence
[float
],Tensor
,AbstractParameter
,Sequence
[AbstractParameter
]]) – the translation offset(s). Supported are: * a single parameter (as float or int), which will be replicated for all dimensions and batch samples * a parameter per sample, which will be replicated for all dimensions * a parameter per dimension, which will be replicated for all batch samples * a parameter per sampler per dimension * None will be treated as a translation offset of 0batchsize (
int
) – the number of samples per batchndim (
int
) – the dimensionality of the transformdevice (
Union
[device
,str
,None
]) – the device to put the resulting tensor to. Defaults to the torch default devicedtype (
Union
[dtype
,str
,None
]) – the dtype of the resulting trensor. Defaults to the torch default dtypeimage_transform (
bool
) – bool inverts the translation matrix to match expected behavior when applied to an image, e.g. translation > 0 should move the image in the positive direction of an axis but the grid in the negative direction
- Returns
- the homogeneous transformation matrix [N, NDIM + 1, NDIM + 1],
N is the batch size and NDIM is the number of spatial dimensions
- Return type
expand_scalar_param¶
Channel Transforms¶
-
rising.transforms.functional.channel.
one_hot_batch
(target, num_classes=None, dtype=None)[source][source]¶ Compute one hot for input tensor (assumed to a be batch and thus saved into first dimension -> input should only have one channel)
- Parameters
- Returns
one hot encoded tensor
- Return type
one_hot_batch¶
Cropping Transforms¶
-
rising.transforms.functional.crop.
crop
(data, corner, size)[source][source]¶ Extract crop from last dimensions of data
Args: data: input tensor corner: top left corner point size: size of patch
- Returns
cropped data
- Return type
-
rising.transforms.functional.crop.
center_crop
(data, size)[source][source]¶ Crop patch from center
Args: data: input tensor size: size of patch
- Returns
output tensor cropped from input tensor
- Return type
-
rising.transforms.functional.crop.
random_crop
(data, size, dist=0)[source][source]¶ Crop random patch/volume from input tensor
crop¶
center_crop¶
random_crop¶
Intensity Transforms¶
-
rising.transforms.functional.intensity.
norm_range
(data, min, max, per_channel=True, out=None)[source][source]¶ Scale range of tensor
- Parameters
- Returns
normalized data
- Return type
-
rising.transforms.functional.intensity.
norm_min_max
(data, per_channel=True, out=None, eps=1e-08)[source][source]¶ Scale range to [0,1]
- Parameters
- Returns
scaled data
- Return type
-
rising.transforms.functional.intensity.
norm_zero_mean_unit_std
(data, per_channel=True, out=None, eps=1e-08)[source][source]¶ Normalize mean to zero and std to one
- Parameters
- Returns
normalized data
- Return type
-
rising.transforms.functional.intensity.
norm_mean_std
(data, mean, std, per_channel=True, out=None)[source][source]¶ Normalize mean and std with provided values
-
rising.transforms.functional.intensity.
add_noise
(data, noise_type, out=None, **kwargs)[source][source]¶ Add noise to input
- Parameters
- Returns
data with added noise
- Return type
See also
torch.Tensor.normal_()
,torch.Tensor.exponential_()
-
rising.transforms.functional.intensity.
add_value
(data, value, out=None)[source][source]¶ Increase brightness additively by value (currently this functions is intended as an interface in case additional functionality should be added to transform)
- Parameters
- Returns
augmented data
- Return type
-
rising.transforms.functional.intensity.
gamma_correction
(data, gamma)[source][source]¶ Apply gamma correction to data (currently this functions is intended as an interface in case additional functionality should be added to transform)
- Parameters
- Returns
gamma corrected data
- Return type
-
rising.transforms.functional.intensity.
scale_by_value
(data, value, out=None)[source][source]¶ Increase brightness scaled by value (currently this functions is intended as an interface in case additional functionality should be added to transform)
- Parameters
- Returns
augmented data
- Return type
-
rising.transforms.functional.intensity.
clamp
(data, min, max, out=None)[source][source]¶ Clamp tensor to minimal and maximal value
norm_range¶
norm_min_max¶
norm_zero_mean_unit_std¶
norm_mean_std¶
-
rising.transforms.functional.intensity.
norm_mean_std
(data, mean, std, per_channel=True, out=None)[source][source] Normalize mean and std with provided values
add_noise¶
add_value¶
gamma_correction¶
scale_by_value¶
Spatial Transforms¶
-
rising.transforms.functional.spatial.
rot90
(data, k, dims)[source][source]¶ Rotate 90 degrees around dims
-
rising.transforms.functional.spatial.
resize_native
(data, size=None, scale_factor=None, mode='nearest', align_corners=None, preserve_range=False)[source][source]¶ Down/up-sample sample to either the given
size
or the givenscale_factor
The modes available for resizing are: nearest, linear (3D-only), bilinear, bicubic (4D-only), trilinear (5D-only), area- Parameters
data (
Tensor
) – input tensor of shape batch x channels x height x width x [depth]size (
Union
[int
,Sequence
[int
],None
]) – spatial output size (excluding batch size and number of channels)scale_factor (
Union
[float
,Sequence
[float
],None
]) – multiplier for spatial sizemode (
str
) – one ofnearest
,linear
,bilinear
,bicubic
,trilinear
,area
(for more inforamtion seetorch.nn.functional.interpolate()
)align_corners (
Optional
[bool
]) – input and output tensors are aligned by the center points of their corners pixels, preserving the values at the corner pixels.preserve_range (
bool
) – output tensor has same range as input tensor
- Returns
interpolated tensor
- Return type
See also
mirror¶
rot90¶
resize_native¶
-
rising.transforms.functional.spatial.
resize_native
(data, size=None, scale_factor=None, mode='nearest', align_corners=None, preserve_range=False)[source][source] Down/up-sample sample to either the given
size
or the givenscale_factor
The modes available for resizing are: nearest, linear (3D-only), bilinear, bicubic (4D-only), trilinear (5D-only), area- Parameters
data (
Tensor
) – input tensor of shape batch x channels x height x width x [depth]size (
Union
[int
,Sequence
[int
],None
]) – spatial output size (excluding batch size and number of channels)scale_factor (
Union
[float
,Sequence
[float
],None
]) – multiplier for spatial sizemode (
str
) – one ofnearest
,linear
,bilinear
,bicubic
,trilinear
,area
(for more inforamtion seetorch.nn.functional.interpolate()
)align_corners (
Optional
[bool
]) – input and output tensors are aligned by the center points of their corners pixels, preserving the values at the corner pixels.preserve_range (
bool
) – output tensor has same range as input tensor
- Returns
interpolated tensor
- Return type
See also
Tensor Transforms¶
-
rising.transforms.functional.tensor.
tensor_op
(data, fn, *args, **kwargs)[source][source]¶ Invokes a function form a tensor
- Parameters
data (
Union
[Tensor
,List
[Tensor
],Tuple
[Tensor
],Mapping
[Hashable
,Tensor
]]) – data which should be pushed to device. Sequence and mapping items are mapping individually to gpufn (
str
) – tensor function*args – positional arguments passed to tensor function
**kwargs – keyword arguments passed to tensor function
- Returns
data which was pushed to device
- Return type
Union[torch.Tensor, Sequence, Mapping]
-
rising.transforms.functional.tensor.
to_device_dtype
(data, dtype=None, device=None, **kwargs)[source][source]¶ Pushes data to device
- Parameters
- Returns
data which was pushed to device
- Return type
Union[torch.Tensor, Sequence, Mapping]
tensor_op¶
-
rising.transforms.functional.tensor.
tensor_op
(data, fn, *args, **kwargs)[source][source] Invokes a function form a tensor
- Parameters
data (
Union
[Tensor
,List
[Tensor
],Tuple
[Tensor
],Mapping
[Hashable
,Tensor
]]) – data which should be pushed to device. Sequence and mapping items are mapping individually to gpufn (
str
) – tensor function*args – positional arguments passed to tensor function
**kwargs – keyword arguments passed to tensor function
- Returns
data which was pushed to device
- Return type
Union[torch.Tensor, Sequence, Mapping]
to_device_dtype¶
-
rising.transforms.functional.tensor.
to_device_dtype
(data, dtype=None, device=None, **kwargs)[source][source] Pushes data to device
- Parameters
- Returns
data which was pushed to device
- Return type
Union[torch.Tensor, Sequence, Mapping]
Utility Transforms¶
-
rising.transforms.functional.utility.
box_to_seg
(boxes, shape=None, dtype=None, device=None, out=None)[source][source]¶ Convert a sequence of bounding boxes to a segmentation
- Parameters
boxes (
Sequence
[Sequence
[int
]]) – sequence of bounding boxes encoded as (dim0_min, dim1_min, dim0_max, dim1_max, [dim2_min, dim2_max]). Supported bounding boxes for 2D (4 entries per box) and 3d (6 entries per box)shape (
Optional
[Sequence
[int
]]) – ifout
is not provided, shape of output tensor must be specifieddtype (
Union
[dtype
,str
,None
]) – ifout
is not provided, dtype of output tensor must be specifieddevice (
Union
[device
,str
,None
]) – ifout
is not provided, device of output tensor must be specifiedout (
Optional
[Tensor
]) – if not None, the segmentation will be saved inside this tensor
- Returns
bounding boxes encoded as a segmentation
- Return type
-
rising.transforms.functional.utility.
seg_to_box
(seg, dim)[source][source]¶ Convert instance segmentation to bounding boxes
-
rising.transforms.functional.utility.
instance_to_semantic
(instance, cls)[source][source]¶ Convert an instance segmentation to a semantic segmentation
- Parameters
- Returns
semantic segmentation
- Return type
Warning
instance
needs to encode objects starting from 1 and the indices need to be continuous (0 is interpreted as background)
-
rising.transforms.functional.utility.
pop_keys
(data, keys, return_popped=False)[source][source]¶ Pops keys from a given data dict
- Parameters
data (
dict
) – the dictionary to pop the keys fromkeys (
Union
[Callable
,Sequence
]) – if callable it must return a boolean for each key indicating whether it should be popped from the dict. if sequence of strings, the strings shall be the keys to be poppedreturn_popped – whether to also return the popped values
(default – False)
- Returns
the data without the popped values dict: the popped values; only if :attr`return_popped` is True
- Return type
-
rising.transforms.functional.utility.
filter_keys
(data, keys, return_popped=False)[source][source]¶ Filters keys from a given data dict
- Parameters
data (
dict
) – the dictionary to pop the keys fromkeys (
Union
[Callable
,Sequence
]) – if callable it must return a boolean for each key indicating whether it should be retained in the dict. if sequence of strings, the strings shall be the keys to be retainedreturn_popped – whether to also return the popped values (default: False)
- Returns
the data without the popped values dict: the popped values; only if
return_popped
is True- Return type
box_to_seg¶
-
rising.transforms.functional.utility.
box_to_seg
(boxes, shape=None, dtype=None, device=None, out=None)[source][source] Convert a sequence of bounding boxes to a segmentation
- Parameters
boxes (
Sequence
[Sequence
[int
]]) – sequence of bounding boxes encoded as (dim0_min, dim1_min, dim0_max, dim1_max, [dim2_min, dim2_max]). Supported bounding boxes for 2D (4 entries per box) and 3d (6 entries per box)shape (
Optional
[Sequence
[int
]]) – ifout
is not provided, shape of output tensor must be specifieddtype (
Union
[dtype
,str
,None
]) – ifout
is not provided, dtype of output tensor must be specifieddevice (
Union
[device
,str
,None
]) – ifout
is not provided, device of output tensor must be specifiedout (
Optional
[Tensor
]) – if not None, the segmentation will be saved inside this tensor
- Returns
bounding boxes encoded as a segmentation
- Return type
seg_to_box¶
instance_to_semantic¶
-
rising.transforms.functional.utility.
instance_to_semantic
(instance, cls)[source][source] Convert an instance segmentation to a semantic segmentation
- Parameters
- Returns
semantic segmentation
- Return type
Warning
instance
needs to encode objects starting from 1 and the indices need to be continuous (0 is interpreted as background)
pop_keys¶
-
rising.transforms.functional.utility.
pop_keys
(data, keys, return_popped=False)[source][source] Pops keys from a given data dict
- Parameters
data (
dict
) – the dictionary to pop the keys fromkeys (
Union
[Callable
,Sequence
]) – if callable it must return a boolean for each key indicating whether it should be popped from the dict. if sequence of strings, the strings shall be the keys to be poppedreturn_popped – whether to also return the popped values
(default – False)
- Returns
the data without the popped values dict: the popped values; only if :attr`return_popped` is True
- Return type
filter_keys¶
-
rising.transforms.functional.utility.
filter_keys
(data, keys, return_popped=False)[source][source] Filters keys from a given data dict
- Parameters
data (
dict
) – the dictionary to pop the keys fromkeys (
Union
[Callable
,Sequence
]) – if callable it must return a boolean for each key indicating whether it should be retained in the dict. if sequence of strings, the strings shall be the keys to be retainedreturn_popped – whether to also return the popped values (default: False)
- Returns
the data without the popped values dict: the popped values; only if
return_popped
is True- Return type