---
dataset:
    task:
        background_class: {use: false}
        preprocess:
            shape:
                height: 224
                width: 224
                channels: 3
            validate:
                - {type: resize, height: 256, width: 256, fill: true}
                - {type: crop_or_pad, height: 224, width: 224}
            final_cpu:
                - {type: linear_map, scale: 2.0, shift: -1.0}
model:
    name: resnet_v2_50
    description: |
        ResNet-v2-50 implementation from::
        https://github.com/keras-team/keras-applications/blob/master/keras_applications/resnet_common.py
    layers:
        _common: &common
            weights_initializer:
                type: tensorflow.initializers.he_normal
            normalizer_fn: tensorflow.contrib.slim.batch_norm
            normalizer_params: &norm_params
                center: true
                scale: true
                decay: 0.99
                epsilon: 1.001e-5
        _conv: &conv
            <<: *common
            type: convolution
            padding: valid
        conv1:
            <<: *conv
            kernel_size: 7
            stride: 2
            num_outputs: 64
            padding: 3
            normalizer_fn: null
            activation_fn: null
        pool1: &pool
            type: max_pool
            kernel_size: 3
            stride: 2
            padding: 1
        _bottleneck: &bb
            type: module
            kwargs: {stride: null, depth: null, shortcut: null}
            layers:
                preact: &norm
                    <<: *norm_params
                    type: batch_normalization
                    activation_fn: tensorflow.nn.relu
                conv1:
                    <<: *conv
                    kernel_size: 1
                    stride: 1
                    num_outputs: ^(depth)
                conv2:
                    <<: *conv
                    kernel_size: 3
                    stride: ^(stride)
                    padding: same
                    num_outputs: ^(depth)
                conv3:
                    <<: *conv
                    kernel_size: 1
                    stride: 1
                    num_outputs: &final_depth !arith 4 * ^(depth)
                    normalizer_fn: null
                    activation_fn: null
                conv_shortcut:
                    <<: *conv
                    kernel_size: 1
                    stride: ^(stride)
                    num_outputs: *final_depth
                    normalizer_fn: null
                    activation_fn: null
                pool_shortcut:
                    <<: *pool
                    kernel_size: 1
                    stride: ^(stride)
                    padding: valid
                identity_shortcut: {type: identity}
                add: {type: add}
            graph:
                - {from: input, with: preact, to: preact}
                - {from: preact, with: [conv1, conv2, conv3], to: residual}
                - from: !arith "'preact' if ^(shortcut) == 'conv' else 'input'"
                  with: ^(shortcut)_shortcut
                  to: shortcut
                - {from: [residual, shortcut], with: add, to: output}
        b21: {<<: *bb, stride: 1, depth: 64, shortcut: conv}
        b22: {<<: *bb, stride: 1, depth: 64, shortcut: identity}
        b23: {<<: *bb, stride: 1, depth: 64, shortcut: identity}
        b31: {<<: *bb, stride: 1, depth: 128, shortcut: conv}
        b32: {<<: *bb, stride: 1, depth: 128, shortcut: identity}
        b33: {<<: *bb, stride: 1, depth: 128, shortcut: identity}
        b34: {<<: *bb, stride: 2, depth: 128, shortcut: pool}
        b41: {<<: *bb, stride: 1, depth: 256, shortcut: conv}
        b42: {<<: *bb, stride: 1, depth: 256, shortcut: identity}
        b43: {<<: *bb, stride: 1, depth: 256, shortcut: identity}
        b44: {<<: *bb, stride: 1, depth: 256, shortcut: identity}
        b45: {<<: *bb, stride: 1, depth: 256, shortcut: identity}
        b46: {<<: *bb, stride: 2, depth: 256, shortcut: pool}
        b51: {<<: *bb, stride: 1, depth: 512, shortcut: conv}
        b52: {<<: *bb, stride: 1, depth: 512, shortcut: identity}
        b53: {<<: *bb, stride: 2, depth: 512, shortcut: pool}
        postnorm: {<<: *norm}
        avg_pool: {type: average_pool, kernel_size: global}
        flatten: {type: flatten}
        fc:
            <<: *common
            type: fully_connected
            num_outputs: $(dataset.task.num_classes)
            activation_fn: null
            normalizer_fn: null
    graph:
        from: input
        with: [
            conv1, pool1,
            b21, b22, b23,
            b31, b32, b33, b34,
            b41, b42, b43, b44, b45, b46,
            b51, b52, b53,
            postnorm, avg_pool, flatten, fc]
        to: output
