Skip to content

wideresnet

WideResidualNetwork

Creates a Wide Residual Network with specified parameters.

Parameters:

Name Type Description Default
input_shape Tuple[int, int, int]

The size of the input tensor (height, width, channels).

required
depth int

Depth of the network. Compute N = (n - 4) / 6. For a depth of 16, n = 16, N = (16 - 4) / 6 = 2 For a depth of 28, n = 28, N = (28 - 4) / 6 = 4 For a depth of 40, n = 40, N = (40 - 4) / 6 = 6

28
widen_factor int

Width of the network.

10
dropout float

Adds dropout if value is greater than 0.0.

0.0
classes int

The number of outputs the model should generate.

10
activation Optional[str]

activation function for last dense layer.

'softmax'

Returns:

Type Description
Model

A Keras Model.

Raises:

Type Description
ValueError

If (depth - 4) is not divisible by 6.

Source code in fastestimator/fastestimator/architecture/tensorflow/wideresnet.py
def WideResidualNetwork(input_shape: Tuple[int, int, int],
                        depth: int = 28,
                        widen_factor: int = 10,
                        dropout: float = 0.0,
                        classes: int = 10,
                        activation: Optional[str] = 'softmax') -> tf.keras.Model:
    """Creates a Wide Residual Network with specified parameters.

    Args:
        input_shape: The size of the input tensor (height, width, channels).
        depth: Depth of the network. Compute N = (n - 4) / 6.
               For a depth of 16, n = 16, N = (16 - 4) / 6 = 2
               For a depth of 28, n = 28, N = (28 - 4) / 6 = 4
               For a depth of 40, n = 40, N = (40 - 4) / 6 = 6
        widen_factor: Width of the network.
        dropout: Adds dropout if value is greater than 0.0.
        classes: The number of outputs the model should generate.
        activation: activation function for last dense layer.

    Returns:
        A Keras Model.

    Raises:
        ValueError: If (depth - 4) is not divisible by 6.
    """
    if (depth - 4) % 6 != 0:
        raise ValueError('Depth of the network must be such that (depth - 4)' 'should be divisible by 6.')

    img_input = layers.Input(shape=input_shape)
    inputs = img_input

    x = __create_wide_residual_network(classes, img_input, depth, widen_factor, dropout, activation)
    # Create model.
    model = Model(inputs, x)
    return model