ToActMap
- class hybrid_learning.datasets.transforms.image_transforms.ToActMap(act_map_gen, device=None, requires_grad=False)[source]
Bases:
ImageTransform
Evaluate a given image by a torch model on the correct device. The model should return tensors, e.g. be a
ModelStump
. Ifdevice
is given, the parameters of the modelact_map_gen
are moved to this device.Warning
Ensure moving of the model parameters to a different device does not interfere with e.g. optimization of these parameters in case
device
is given!Public Data Attributes:
Settings to reproduce the instance.
Inherited from : py: class:Transform
IDENTITY_CLASS
The identity class or classes for composition / addition.
Settings to reproduce the instance.
Public Methods:
apply_to
(img_t)Collect output of activation map generator for image
img_t
as input.Inherited from : py: class:ImageTransform
apply_to
(img_t)Collect output of activation map generator for image
img_t
as input.Inherited from : py: class:Transform
apply_to
(img_t)Collect output of activation map generator for image
img_t
as input.Special Methods:
__init__
(act_map_gen[, device, requires_grad])Init.
Inherited from : py: class:ImageTransform
__call__
(img)Application of transformation.
Inherited from : py: class:Transform
__repr__
()Return repr(self).
__eq__
(other)Return self==value.
__copy__
()Return a shallow copy of self using settings.
__add__
(other)Return a flat composition of
self
withother
.__radd__
(other)Return a flat composition of
other
andself
.__call__
(img)Application of transformation.
- __init__(act_map_gen, device=None, requires_grad=False)[source]
Init.
- Parameters
act_map_gen (Module) – model the output of which is interpreted as activation maps
device (Optional[Union[str, device]]) – the device to operate the transformation on
requires_grad (bool) – whether the model and the transformation output should require gradients (this trafo may be unpickleable in combination with cuda usage of set to
True
)
- apply_to(img_t)[source]
Collect output of activation map generator for image
img_t
as input. The evaluation ofact_map_gen
onimg_t
is conducted ondevice
if this is set.- Parameters
img_t (Tensor) – image for which to obtain activation map; make sure all necessary transformations are applied
- Returns
activation map as
torch.Tensor
- Return type
- act_map_gen: torch.nn.modules.module.Module
Callable torch model that accepts and returns a
torch.Tensor
.