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. If device is given, the parameters of the model act_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

Settings to reproduce the instance.

Inherited from : py: class:Transform

IDENTITY_CLASS

The identity class or classes for composition / addition.

settings

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 with other.

__radd__(other)

Return a flat composition of other and self.

__call__(img)

Application of transformation.


Parameters
__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 of act_map_gen on img_t is conducted on device 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

Tensor

act_map_gen: torch.nn.modules.module.Module

Callable torch model that accepts and returns a torch.Tensor.

device: Optional[Union[str, torch.device]]

If given, the device to move model and image to before evaluation.

requires_grad: bool

Whether to turn gradient tracking on for the transformation calculation.

property settings: Dict[str, Any]

Settings to reproduce the instance.