def __init__(self, filters, dropout_rate, kernel_initializer, kernel_regularizer, name='bottleneck_composite_function'): layers = [ L.BatchNormalization(), L.Activation(tf.nn.relu), L.Conv2D( filters * 4, 1, use_bias=False, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer), L.Dropout(dropout_rate), L.BatchNormalization(), L.Activation(tf.nn.relu), L.Conv2D( filters, 3, padding='same', use_bias=False, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer), L.Dropout(dropout_rate), ] super().__init__(layers, name=name)
def __init__(self, filters, strides, expansion_factor, dropout_rate, kernel_initializer, kernel_regularizer, name='bottleneck'): super().__init__(name=name) self.expand_conv = Sequential([ L.Conv2D( filters * expansion_factor, # FIXME: should be `input_shape[3].value * expansion_factor` 1, use_bias=False, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer), L.BatchNormalization(), L.Activation(tf.nn.relu6), L.Dropout(dropout_rate) ]) self.depthwise_conv = Sequential([ L.DepthwiseConv2D(3, strides=strides, padding='same', use_bias=False, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer), L.BatchNormalization(), L.Activation(tf.nn.relu6), L.Dropout(dropout_rate) ]) self.linear_conv = Sequential([ L.Conv2D(filters, 1, use_bias=False, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer), L.BatchNormalization(), L.Dropout(dropout_rate) ])
def __init__(self, input_filters, compression_factor, dropout_rate, kernel_initializer, kernel_regularizer, name='transition_layer'): self.input_filters = input_filters filters = int(input_filters * compression_factor) layers = [ L.BatchNormalization(), L.Conv2D( filters, 1, use_bias=False, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer), L.Dropout(dropout_rate), L.AveragePooling2D(2, 2, padding='same') ] super().__init__(layers, name=name)
def __init__(self, dropout_rate, kernel_initializer=None, kernel_regularizer=None, name='mobilenet_v2'): if kernel_initializer is None: kernel_initializer = tf.contrib.layers.variance_scaling_initializer( factor=2.0, mode='FAN_IN', uniform=False) if kernel_regularizer is None: kernel_regularizer = tf.contrib.layers.l2_regularizer(scale=4e-5) super().__init__(name=name) self.input_conv = Sequential([ L.Conv2D(32, 3, strides=2, padding='same', use_bias=False, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer), L.BatchNormalization(), L.Activation(tf.nn.relu6), L.Dropout(dropout_rate) ]) self.bottleneck_1_1 = Bottleneck(16, expansion_factor=1, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_2_1 = Bottleneck(24, expansion_factor=6, strides=2, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_2_2 = Bottleneck(24, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_3_1 = Bottleneck(32, expansion_factor=6, strides=2, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_3_2 = Bottleneck(32, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_3_3 = Bottleneck(32, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_4_1 = Bottleneck(64, expansion_factor=6, strides=2, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_4_2 = Bottleneck(64, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_4_3 = Bottleneck(64, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_4_4 = Bottleneck(64, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_5_1 = Bottleneck(96, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_5_2 = Bottleneck(96, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_5_3 = Bottleneck(96, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_6_1 = Bottleneck(160, expansion_factor=6, strides=2, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_6_2 = Bottleneck(160, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_6_3 = Bottleneck(160, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.bottleneck_7_1 = Bottleneck(320, expansion_factor=6, strides=1, dropout_rate=dropout_rate, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer) self.output_conv = Sequential([ L.Conv2D(32, 1, use_bias=False, kernel_initializer=kernel_initializer, kernel_regularizer=kernel_regularizer), L.BatchNormalization(), L.Activation(tf.nn.relu6), L.Dropout(dropout_rate) ])