Augmented Tensor¶
- class aloscene.tensors.augmented_tensor.AugmentedTensor(x, names=None, device=None, *args, **kwargs)¶
Bases:
torch.Tensor
Tensor with attached labels
- COMMON_DIM_NAMES = ['B', 'T']¶
- add_label(var_name, variable, **kwargs)¶
- add_property(var_name, variable)¶
- static apply_on_label(label, func, on_list=True)¶
Apply a function on a label
- as_tensor()¶
Returns a new tensor based on the same memory location than the current Augmted Tensor
- Returns
- n_tensor: torch.Tensor
A new tensor based on the same content, same dtype, same device
- clone(*, memory_format=torch.preserve_format) Tensor ¶
See
torch.clone()
- cpu(*args, **kwargs)¶
Send the current augmentend tensor on the cpu with all its labels recursively.
- crop(H_crop, W_crop, **kwargs)¶
Crop AugmentedTensor, and its labels recursively
- Parameters
- H_crop: tuple
(start, end) between 0 and 1
- W_crop: tuple
(start, end) between 0 and 1
- Returns
- cropedaloscene AugmentedTensor
croped tensor
- cuda(*args, **kwargs)¶
Send the current augmentend tensor on cuda with all its labels recursively.
- drop_labels()¶
- get_labels()¶
- get_slices(dim_values, label=None)¶
Get a list of slices for each named dimension.
- Examplefor a tensor t with names (‘T’, ‘C’, ‘H’, ‘W’)
t[t.get_slices({“C”:1})] is equivalent to t[:,1,:,:]
- Parameters
- dim_valuesdict
keys : name of the dimension value : slice or value to index on this dimension the dimensions that are not keys of the dict have a default value of slice(None)
- Returns
- sliceslist of slice object
This can be used
- hflip(**kwargs)¶
Flip AugmentedTensor horizontally, and its labels recursively
- Returns
- flippedaloscene AugmentedTensor
horizontally flipped tensor
- pad(offset_y, offset_x, **kwargs)¶
Pad AugmentedTensor, and its labels recursively
- Parameters
- offset_y: tuple of float or tuple of int
(percentage top_offset, percentage bottom_offset) Percentage based on the previous size If tuple of int the absolute value will be converted to float (percentahe) before to be applied.
- offset_x: tuple of float or tuple of int
(percentage left_offset, percentage right_offset) Percentage based on the previous size. If tuple of int the absolute value will be converted to float (percentage) before to be applied.
- Returns
- cropedaloscene AugmentedTensor
croped tensor
- recursive_apply_on_labels_(func)¶
Recursively apply function on labels to modify tensor inplace
- rename(*args, auto_restore_names=False, **kwargs)¶
Rename the dimensions of your augmented Tensor.
- Parameters
- auto_restore_names: bool
Somehow hacky but this is maybe the only way to pass Augmented tensor through the datapipeline when doing multi-gpu training. Looking forward for the next pytorch release. Therefore, when passing your Augmented Tensor through a Datapipeline (the output of __getitem__) you must rename your augmented tensor using augmented_tensor.rename(auto_restore=True).
Note: This this not needed for the datasets that inhert from alodataset.BaseDataset
- rename_(*args, auto_restore_names=False, **kwargs)¶
Rename the dimensions of your augmented Tensor.
- Parameters
- auto_restore_names: bool
Somehow hacky but this is maybe the only way to pass Augmented tensor through the datapipeline when doing multi-gpu training. Looking forward for the next pytorch release. Therefore, when passing your Augmented Tensor through a Datapipeline (the output of __getitem__) you must rename your augmented tensor using augmented_tensor.rename(auto_restore=True).
Note: This this not needed for the datasets that inhert from alodataset.BaseDataset
- reset_names()¶
- resize(size, **kwargs)¶
Resize AugmentedTensor, and its labels recursively
- Parameters
- sizetuple of int
target size (H, W)
- Returns
- resizedaloscene AugmentedTensor
resized tensor
- set_labels(labels)¶
- spatial_shift(shift_y, shift_x, **kwargs)¶
Spatially shift the AugmentedTensor and its labels recursively
- Parameters
- shift_y: float
Shift percentage on the y axis. Could be negative or positive
- shift_x: float
Shift percentage on the x axis. Could ne negative or positive.
- Returns
- shifted_tensor: aloscene.AugmentedTensor
shifted tensor
- to(*args, **kwargs)¶
- vflip(**kwargs)¶
Flip AugmentedTensor vertically, and its labels recursively
- Returns
- flippedaloscene AugmentedTensor
vertically flipped tensor