interfaces

Primitive Convolutional interfaces.

Classes

Conv2DInterface Primitive Interface to be used by all ashpy.models.
class ashpy.models.convolutional.interfaces.Conv2DInterface[source]

Bases: tensorflow.python.keras.engine.training.Model

Primitive Interface to be used by all ashpy.models.

__init__()[source]

Primitive Interface to be used by all ashpy.models.

Declares the self.model_layers list.

static _get_layer_spec(initial_filers, filters_cap, input_res, target_res)[source]

Compose the layer_spec, the building block of a convolutional model.

The layer_spec is an iterator. Every element returned is the number of filters to learn for the current layer. The generated sequence of filters starts from initial_filters and halve/double the number of filters depending on the input_res and target_res. If input_res > target_res the number of filters increases, else it decreases. The progression is always a power of 2.

Parameters:
  • initial_filers (int) – Depth of the first convolutional layer.
  • filters_cap (int) – Maximum number of filters per layer.
  • input_res (tuple of (int, int)) – Input resolution.
  • target_res (tuple of (int, int)) – Output resolution.
Yields:

int – Number of filters to use for the conv layer.

Examples

# Encoder
class T(Conv2DInterface):
    pass
spec = T._get_layer_spec(
    initial_filers=16,
    filters_cap=128,
    input_res=(512, 256),
    target_res=(32, 16)
)
print([s for s in spec])

spec = T._get_layer_spec(
    initial_filers=16,
    filters_cap=128,
    input_res=(28, 28),
    target_res=(7, 7)
)
print([s for s in spec])

# Decoder
spec = T._get_layer_spec(
    initial_filers=128,
    filters_cap=16,
    input_res=(32, 16),
    target_res=(512, 256)
)
print([s for s in spec])

spec = T._get_layer_spec(
    initial_filers=128,
    filters_cap=16,
    input_res=(7, 7),
    target_res=(28, 28)
)
print([s for s in spec])
[32, 64, 128, 128]
[32, 64]
[64, 32, 16, 16]
[64, 32]

Notes

This is useful since it enables us to dynamically redefine models sharing an underlying architecture but with different resolutions.

call(inputs, training=True, return_features=False)[source]

Execute the model on input data.

Parameters:
  • inputs (tf.Tensor) – Input tensor(s).
  • training (bool) – Training flag.
  • return_features (bool) – If True returns the features.
Returns:

tf.Tensor – The model output.