ravens/models/resnet.py
def ResNet43_8s(input_shape, output_dim, include_batchnorm=False, batchnorm_axis=3, prefix='', cutoff_early=False):
    """Daniel: produces an hourglass FCN network, adapted to CoRL submission size.

    Regarding shapes, look at: https://www.tensorflow.org/api_docs/python/tf/keras/Input [excludes batch size]
    Here are the shape patterns, where I print shapes for the input, and after each conv_block or Conv2D call.

    Attention:
    (None, 320, 320, 6) (input shape)
    (None, 320, 320, 64)
    (None, 320, 320, 64)
    (None, 160, 160, 128)
    (None, 80, 80, 256)
    (None, 40, 40, 512)
    (None, 40, 40, 256)
    (None, 80, 80, 128)
    (None, 160, 160, 64)
    (None, 320, 320, 1)

    Transport, key module
    (None, 384, 224, 6) (input shape)
    (None, 384, 224, 64)
    (None, 384, 224, 64)
    (None, 192, 112, 128)
    (None, 96, 56, 256)
    (None, 48, 28, 512)
    (None, 48, 28, 256)
    (None, 96, 56, 128)
    (None, 192, 112, 64)
    (None, 384, 224, 3)

    Transport, query module, assumes cropping beforehand.
    (None, 64, 64, 6) (input shape)
    (None, 64, 64, 64)
    (None, 64, 64, 64)
    (None, 32, 32, 128)
    (None, 16, 16, 256)
    (None, 8, 8, 512)
    (None, 8, 8, 256)
    (None, 16, 16, 128)
    (None, 32, 32, 64)
    (None, 64, 64, 3)

    Here I ignore output after identity blocks, which produce tensors of the same size.

    Parameters
    ----------
    :input_shape: a tuple that specifies the shape for tf.keras.layers.Input. By default,
        it's (None,320,320,6) for Attention, (None,384,224,6) for Transport. The input is
        a tuple, not a tensor.
    :output_dim: a single scalar, which produces the number of channels of the output.
        For example, if it's set to 3, then if we pass kernels of size (None,64,64,6),
        the default, we get an output tensor of size (None,64,64,3).
    """
    input_data = tf.keras.layers.Input(shape=input_shape)

    x = tf.keras.layers.Conv2D(64, (3, 3), strides=(1, 1), padding='same', kernel_initializer='glorot_uniform', name=prefix + 'conv1')(input_data)
    if include_batchnorm:
        x = tf.keras.layers.BatchNormalization(axis=batchnorm_axis, name=prefix + 'bn_conv1')(x)
    x = tf.keras.layers.ReLU()(x)

    if cutoff_early:
        x = conv_block(x, 5, [64, 64, output_dim], stage=2, block=prefix + 'a', strides=(1, 1), include_batchnorm=include_batchnorm)
        x = identity_block(x, 5, [64, 64, output_dim], stage=2, block=prefix + 'b', include_batchnorm=include_batchnorm)
        return input_data, x

    x = conv_block(x, 3, [64, 64, 64], stage=2, block=prefix + 'a', strides=(1, 1))
    x = identity_block(x, 3, [64, 64, 64], stage=2, block=prefix + 'b')

    x = conv_block(x, 3, [128, 128, 128], stage=3, block=prefix + 'a', strides=(2, 2))
    x = identity_block(x, 3, [128, 128, 128], stage=3, block=prefix + 'b')

    x = conv_block(x, 3, [256, 256, 256], stage=4, block=prefix + 'a', strides=(2, 2))
    x = identity_block(x, 3, [256, 256, 256], stage=4, block=prefix + 'b')

    x = conv_block(x, 3, [512, 512, 512], stage=5, block=prefix + 'a', strides=(2, 2))
    x = identity_block(x, 3, [512, 512, 512], stage=5, block=prefix + 'b')

    x = conv_block(x, 3, [256, 256, 256], stage=6, block=prefix + 'a', strides=(1, 1))
    x = identity_block(x, 3, [256, 256, 256], stage=6, block=prefix + 'b')

    x = tf.keras.layers.UpSampling2D(size=(2, 2), interpolation='bilinear', name=prefix + 'upsample_1')(x)

    x = conv_block(x, 3, [128, 128, 128], stage=7, block=prefix + 'a', strides=(1, 1))
    x = identity_block(x, 3, [128, 128, 128], stage=7, block=prefix + 'b')

    x = tf.keras.layers.UpSampling2D(size=(2, 2), interpolation='bilinear', name=prefix + 'upsample_2')(x)

    x = conv_block(x, 3, [64, 64, 64], stage=8, block=prefix + 'a', strides=(1, 1))
    x = identity_block(x, 3, [64, 64, 64], stage=8, block=prefix + 'b')

    x = tf.keras.layers.UpSampling2D(size=(2, 2), interpolation='bilinear', name=prefix + 'upsample_3')(x)

    x = conv_block(x, 3, [16, 16, output_dim], stage=9, block=prefix + 'a', strides=(1, 1), activation=False)
    output = identity_block(x, 3, [16, 16, output_dim], stage=9, block=prefix + 'b', activation=False)

    return input_data, output
Daniel: produces an hourglass FCN network, adapted to CoRL submission size.

    Regarding shapes, look at: https://www.tensorflow.org/api_docs/python/tf/keras/Input [excludes batch size]
    Here are the shape patterns, where I print shapes for the input, and after each conv_block or Conv2D call.

    Attention:
    (None, 320, 320, 6) (input shape)
    (None, 320, 320, 64)
    (None, 320, 320, 64)
    (None, 160, 160, 128)
    (None, 80, 80, 256)
    (None, 40, 40, 512)
    (None, 40, 40, 256)
    (None, 80, 80, 128)
    (None, 160, 160, 64)
    (None, 320, 320, 1)

    Transport, key module
    (None, 384, 224, 6) (input shape)
    (None, 384, 224, 64)
    (None, 384, 224, 64)
    (None, 192, 112, 128)
    (None, 96, 56, 256)
    (None, 48, 28, 512)
    (None, 48, 28, 256)
    (None, 96, 56, 128)
    (None, 192, 112, 64)
    (None, 384, 224, 3)

    Transport, query module, assumes cropping beforehand.
    (None, 64, 64, 6) (input shape)
    (None, 64, 64, 64)
    (None, 64, 64, 64)
    (None, 32, 32, 128)
    (None, 16, 16, 256)
    (None, 8, 8, 512)
    (None, 8, 8, 256)
    (None, 16, 16, 128)
    (None, 32, 32, 64)
    (None, 64, 64, 3)

    Here I ignore output after identity blocks, which produce tensors of the same size.

    Parameters
    ----------
    :input_shape: a tuple that specifies the shape for tf.keras.layers.Input. By default,
        it's (None,320,320,6) for Attention, (None,384,224,6) for Transport. The input is
        a tuple, not a tensor.
    :output_dim: a single scalar, which produces the number of channels of the output.
        For example, if it's set to 3, then if we pass kernels of size (None,64,64,6),
        the default, we get an output tensor of size (None,64,64,3).
    
produces an hourglass FCN network, adapted to CoRL submission size.





Transport, query module, assumes cropping beforehand.

Here I ignore output after identity blocks, which produce tensors of the same size.

Parameters
produces an hourglass FCN network adapted to CoRL submission size . Transport query module assumes cropping beforehand . Here I ignore output after identity blocks which produce tensors of the same size . Parameters
def ResNet43_8s(input_shape, output_dim, include_batchnorm=False, batchnorm_axis=3, prefix='', cutoff_early=False):
    input_data = tf.keras.layers.Input(shape=input_shape)
    x = tf.keras.layers.Conv2D(64, (3, 3), strides=(1, 1), padding='same', kernel_initializer='glorot_uniform', name=prefix + 'conv1')(input_data)
    if include_batchnorm:
        x = tf.keras.layers.BatchNormalization(axis=batchnorm_axis, name=prefix + 'bn_conv1')(x)
    x = tf.keras.layers.ReLU()(x)
    if cutoff_early:
        x = conv_block(x, 5, [64, 64, output_dim], stage=2, block=prefix + 'a', strides=(1, 1), include_batchnorm=include_batchnorm)
        x = identity_block(x, 5, [64, 64, output_dim], stage=2, block=prefix + 'b', include_batchnorm=include_batchnorm)
        return input_data, x
    x = conv_block(x, 3, [64, 64, 64], stage=2, block=prefix + 'a', strides=(1, 1))
    x = identity_block(x, 3, [64, 64, 64], stage=2, block=prefix + 'b')
    x = conv_block(x, 3, [128, 128, 128], stage=3, block=prefix + 'a', strides=(2, 2))
    x = identity_block(x, 3, [128, 128, 128], stage=3, block=prefix + 'b')
    x = conv_block(x, 3, [256, 256, 256], stage=4, block=prefix + 'a', strides=(2, 2))
    x = identity_block(x, 3, [256, 256, 256], stage=4, block=prefix + 'b')
    x = conv_block(x, 3, [512, 512, 512], stage=5, block=prefix + 'a', strides=(2, 2))
    x = identity_block(x, 3, [512, 512, 512], stage=5, block=prefix + 'b')
    x = conv_block(x, 3, [256, 256, 256], stage=6, block=prefix + 'a', strides=(1, 1))
    x = identity_block(x, 3, [256, 256, 256], stage=6, block=prefix + 'b')
    x = tf.keras.layers.UpSampling2D(size=(2, 2), interpolation='bilinear', name=prefix + 'upsample_1')(x)
    x = conv_block(x, 3, [128, 128, 128], stage=7, block=prefix + 'a', strides=(1, 1))
    x = identity_block(x, 3, [128, 128, 128], stage=7, block=prefix + 'b')
    x = tf.keras.layers.UpSampling2D(size=(2, 2), interpolation='bilinear', name=prefix + 'upsample_2')(x)
    x = conv_block(x, 3, [64, 64, 64], stage=8, block=prefix + 'a', strides=(1, 1))
    x = identity_block(x, 3, [64, 64, 64], stage=8, block=prefix + 'b')
    x = tf.keras.layers.UpSampling2D(size=(2, 2), interpolation='bilinear', name=prefix + 'upsample_3')(x)
    x = conv_block(x, 3, [16, 16, output_dim], stage=9, block=prefix + 'a', strides=(1, 1), activation=False)
    output = identity_block(x, 3, [16, 16, output_dim], stage=9, block=prefix + 'b', activation=False)
    return input_data, output
def ResNet43_8s ( input_shape , output_dim , include_batchnorm = False , batchnorm_axis = 3 , prefix = '' , cutoff_early = False ) : input_data = tf . keras . layers . Input ( shape = input_shape ) x = tf . keras . layers . Conv2D ( 64 , ( 3 , 3 ) , strides = ( 1 , 1 ) , padding = 'same' , kernel_initializer = 'glorot_uniform' , name = prefix + 'conv1' ) ( input_data ) if include_batchnorm : x = tf . keras . layers . BatchNormalization ( axis = batchnorm_axis , name = prefix + 'bn_conv1' ) ( x ) x = tf . keras . layers . ReLU ( ) ( x ) if cutoff_early : x = conv_block ( x , 5 , [ 64 , 64 , output_dim ] , stage = 2 , block = prefix + 'a' , strides = ( 1 , 1 ) , include_batchnorm = include_batchnorm ) x = identity_block ( x , 5 , [ 64 , 64 , output_dim ] , stage = 2 , block = prefix + 'b' , include_batchnorm = include_batchnorm ) return input_data , x x = conv_block ( x , 3 , [ 64 , 64 , 64 ] , stage = 2 , block = prefix + 'a' , strides = ( 1 , 1 ) ) x = identity_block ( x , 3 , [ 64 , 64 , 64 ] , stage = 2 , block = prefix + 'b' ) x = conv_block ( x , 3 , [ 128 , 128 , 128 ] , stage = 3 , block = prefix + 'a' , strides = ( 2 , 2 ) ) x = identity_block ( x , 3 , [ 128 , 128 , 128 ] , stage = 3 , block = prefix + 'b' ) x = conv_block ( x , 3 , [ 256 , 256 , 256 ] , stage = 4 , block = prefix + 'a' , strides = ( 2 , 2 ) ) x = identity_block ( x , 3 , [ 256 , 256 , 256 ] , stage = 4 , block = prefix + 'b' ) x = conv_block ( x , 3 , [ 512 , 512 , 512 ] , stage = 5 , block = prefix + 'a' , strides = ( 2 , 2 ) ) x = identity_block ( x , 3 , [ 512 , 512 , 512 ] , stage = 5 , block = prefix + 'b' ) x = conv_block ( x , 3 , [ 256 , 256 , 256 ] , stage = 6 , block = prefix + 'a' , strides = ( 1 , 1 ) ) x = identity_block ( x , 3 , [ 256 , 256 , 256 ] , stage = 6 , block = prefix + 'b' ) x = tf . keras . layers . UpSampling2D ( size = ( 2 , 2 ) , interpolation = 'bilinear' , name = prefix + 'upsample_1' ) ( x ) x = conv_block ( x , 3 , [ 128 , 128 , 128 ] , stage = 7 , block = prefix + 'a' , strides = ( 1 , 1 ) ) x = identity_block ( x , 3 , [ 128 , 128 , 128 ] , stage = 7 , block = prefix + 'b' ) x = tf . keras . layers . UpSampling2D ( size = ( 2 , 2 ) , interpolation = 'bilinear' , name = prefix + 'upsample_2' ) ( x ) x = conv_block ( x , 3 , [ 64 , 64 , 64 ] , stage = 8 , block = prefix + 'a' , strides = ( 1 , 1 ) ) x = identity_block ( x , 3 , [ 64 , 64 , 64 ] , stage = 8 , block = prefix + 'b' ) x = tf . keras . layers . UpSampling2D ( size = ( 2 , 2 ) , interpolation = 'bilinear' , name = prefix + 'upsample_3' ) ( x ) x = conv_block ( x , 3 , [ 16 , 16 , output_dim ] , stage = 9 , block = prefix + 'a' , strides = ( 1 , 1 ) , activation = False ) output = identity_block ( x , 3 , [ 16 , 16 , output_dim ] , stage = 9 , block = prefix + 'b' , activation = False ) return input_data , output
Daniel: produces an hourglass FCN network, adapted to CoRL submission size.
Daniel : produces an hourglass FCN network adapted to CoRL submission size .
"""Daniel: produces an hourglass FCN network, adapted to CoRL submission size.

    Regarding shapes, look at: https://www.tensorflow.org/api_docs/python/tf/keras/Input [excludes batch size]
    Here are the shape patterns, where I print shapes for the input, and after each conv_block or Conv2D call.

    Attention:
    (None, 320, 320, 6) (input shape)
    (None, 320, 320, 64)
    (None, 320, 320, 64)
    (None, 160, 160, 128)
    (None, 80, 80, 256)
    (None, 40, 40, 512)
    (None, 40, 40, 256)
    (None, 80, 80, 128)
    (None, 160, 160, 64)
    (None, 320, 320, 1)

    Transport, key module
    (None, 384, 224, 6) (input shape)
    (None, 384, 224, 64)
    (None, 384, 224, 64)
    (None, 192, 112, 128)
    (None, 96, 56, 256)
    (None, 48, 28, 512)
    (None, 48, 28, 256)
    (None, 96, 56, 128)
    (None, 192, 112, 64)
    (None, 384, 224, 3)

    Transport, query module, assumes cropping beforehand.
    (None, 64, 64, 6) (input shape)
    (None, 64, 64, 64)
    (None, 64, 64, 64)
    (None, 32, 32, 128)
    (None, 16, 16, 256)
    (None, 8, 8, 512)
    (None, 8, 8, 256)
    (None, 16, 16, 128)
    (None, 32, 32, 64)
    (None, 64, 64, 3)

    Here I ignore output after identity blocks, which produce tensors of the same size.

    Parameters
    ----------
    :input_shape: a tuple that specifies the shape for tf.keras.layers.Input. By default,
        it's (None,320,320,6) for Attention, (None,384,224,6) for Transport. The input is
        a tuple, not a tensor.
    :output_dim: a single scalar, which produces the number of channels of the output.
        For example, if it's set to 3, then if we pass kernels of size (None,64,64,6),
        the default, we get an output tensor of size (None,64,64,3).
    """
input_shape
output_dim
include_batchnorm
batchnorm_axis
prefix
cutoff_early
input_shape
a tuple that specifies the shape for tf.keras.layers.Input.
a tuple that specifies the shape for tf . keras . layers . Input .
output_dim
a single scalar, which produces the number of channels of the output.
For example, if it's set to 3, then if we pass kernels of size (None,64,64,6),
the default, we get an output tensor of size (None,64,64,3).
a single scalar which produces the number of channels of the output . For example if it ' s set to 3 then if we pass kernels of size ( None 64 64 6 ) the default we get an output tensor of size ( None 64 64 3 ) .