resnet_general_block

tfsnippet.layers.resnet_general_block(*args, **kwargs)

A general implementation of ResNet block.

The architecture of this ResNet implementation follows the work “Wide residual networks” (Zagoruyko & Komodakis, 2016). It basically does the following things:

shortcut = input
if strides != 1 or in_channels != out_channels:
    shortcut = conv_fn(
        input=shortcut,
        out_channels=out_channels,
        kernel_size=shortcut_kernel_size,
        strides=strides,
        name='shortcut'
    )

residual = input
residual = conv_fn(
    input=activation_fn(normalizer_fn(residual)),
    out_channels=in_channels if resize_at_exit else out_channels,
    kernel_size=kernel_size,
    strides=strides,
    name='conv'
)
residual = dropout_fn(residual)
residual = conv_fn(
    input=activation_fn(normalizer_fn(residual)),
    out_channels=out_channels,
    kernel_size=kernel_size,
    strides=strides,
    name='conv_1'
)

output = shortcut + residual
Parameters:
  • conv_fn – The convolution function for “shortcut”, “conv” and “conv_1” convolutional layers. It must accept, and only expect, 5 named arguments (input, out_channels, kernel_size, strides, name).
  • input (Tensor) – The input tensor.
  • in_channels (int) – The channel numbers of the tensor.
  • out_channels (int) – The channel numbers of the output.
  • kernel_size (int or tuple[int]) – Kernel size over spatial dimensions, for “conv” and “conv_1” convolutional layers.
  • strides (int or tuple[int]) – Strides over spatial dimensions, for all three convolutional layers.
  • shortcut_kernel_size (int or tuple[int]) – Kernel size over spatial dimensions, for the “shortcut” convolutional layer.
  • resize_at_exit (bool) – If True, resize the spatial dimensions at the “conv_1” convolutional layer. If False, resize at the “conv” convolutional layer. (see above)
  • activation_fn – The activation function.
  • normalizer_fn – The normalizer function.
  • dropout_fn – The dropout function.
  • name (str) – Default name of the variable scope. Will be uniquified. If not specified, generate one according to the class name.
  • scope (str) – The name of the variable scope.
Returns:

The output tensor.

Return type:

tf.Tensor