Source: vis/input_modifiers.py#L0


InputModifier

Abstract class for defining an input modifier. An input modifier can be used with the Optimizer.minimize to make pre and post changes to the optimized input during the optimization process.

modifier.pre(seed_input)
# gradient descent update to img
modifier.post(seed_input)

InputModifier.post

post(self, inp)

Implement post gradient descent update modification to the input. If post-processing is not desired, simply ignore the implementation. It returns the unmodified inp by default.

Args:

  • inp: An N-dim numpy array of shape: (samples, channels, image_dims...) if image_data_format= channels_first or (samples, image_dims..., channels) if image_data_format=channels_last.

Returns:

The modified post input.


InputModifier.pre

pre(self, inp)

Implement pre gradient descent update modification to the input. If pre-processing is not desired, simply ignore the implementation. It returns the unmodified inp by default.

Args:

  • inp: An N-dim numpy array of shape: (samples, channels, image_dims...) if image_data_format= channels_first or (samples, image_dims..., channels) if image_data_format=channels_last.

Returns:

The modified pre input.


Jitter


Jitter.__init__

__init__(self, jitter=0.05)

Implements an input modifier that introduces random jitter in pre. Jitter has been shown to produce crisper activation maximization images.

Args:

  • jitter: The amount of jitter to apply, scalar or sequence. If a scalar, same jitter is applied to all image dims. If sequence, jitter should contain a value per image dim.

A value between [0., 1.] is interpreted as a percentage of the image dimension. (Default value: 0.05)


Jitter.post

post(self, inp)

Implement post gradient descent update modification to the input. If post-processing is not desired, simply ignore the implementation. It returns the unmodified inp by default.

Args:

  • inp: An N-dim numpy array of shape: (samples, channels, image_dims...) if image_data_format= channels_first or (samples, image_dims..., channels) if image_data_format=channels_last.

Returns:

The modified post input.


Jitter.pre

pre(self, img)