def stem(self, inp): ''' inception v4 stem input: 256 x 256 x 3 output: 32 x 32 x 576 ''' xi = Input(shape=inp.get_shape().as_list()[1:]) # 256 x 256 x 3 x = layers.conv_bn_act(xi, 32, (3, 3), strides=(2, 2)) x = layers.conv_bn_act(x, 32, (3, 3)) x = layers.conv_bn_act(x, 64, (3, 3)) a = layers.conv_bn_act(x, 96, (3, 3), strides=(2, 2)) b = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x) x = concatenate([a, b]) a = layers.conv_bn_act(x, 64, (1, 1)) a = layers.conv_bn(a, 96, (3, 3)) b = layers.conv_bn_act(x, 64, (1, 1)) b = layers.conv_bn_act(b, 64, (5, 1)) b = layers.conv_bn_act(b, 64, (1, 5)) b = layers.conv_bn(b, 96, (3, 3)) x = concatenate([a, b]) a = layers.act_conv_bn(x, 192, (3, 3), strides=(2, 2)) b = MaxPooling2D((2, 2), strides=(2, 2))(x) x = concatenate([a, b]) x = blocks.sepconv_residual(x, 3 * 192, name='sepconv1') model = Model(xi, x, name='Stem') x = model(inp) return x
def fremap_block(self, inp, num_filters, name=None): # input_shape = inp.get_shape().as_list()[1:] # xi = Input(shape=input_shape) x = layers.act_conv_bn(inp, num_filters, (1, 1)) # model = Model(inputs=inp, outputs=x, name=name) return x
def reception_block(self, inp, name): ''' each pose block starts with a reception block it is u-shaped and relies on separable convolutions inp ------------------------- a (SR 576) -------------------- + -- out | | | | MP --- C 288 -- SR 288 ---- b (SR 288) ---- + -- SR 576 -- US | | | | MP --- SR -- SR -- SR --- US <- all 288 channels SR: Sepconv Residual (all 5x5) C: Conv (1x1) MP: Max Pooling (2x2 with stride 2x2) US: UpSampling (2x2) input: 32 x 32 x 576 output: 32 x 32 x 576 ''' ksize = self.kernel_size input_shape = inp.get_shape().as_list()[1:] size = int(input_shape[-1]) # first branch # xi = Input(shape=input_shape) a = blocks.sepconv_residual(inp, size, name='sepconv_l1', kernel_size=ksize) # second branch low1 = MaxPooling2D((2, 2))(inp) low1 = layers.act_conv_bn(low1, int(size/2), (1, 1)) low1 = blocks.sepconv_residual(low1, int(size/2), name='sepconv_l2_1', kernel_size=ksize) b = blocks.sepconv_residual(low1, int(size/2), name='sepconv_l2_2', kernel_size=ksize) # third branch c = MaxPooling2D((2, 2))(low1) c = blocks.sepconv_residual(c, int(size/2), name='sepconv_l3_1', kernel_size=ksize) c = blocks.sepconv_residual(c, int(size/2), name='sepconv_l3_2', kernel_size=ksize) c = blocks.sepconv_residual(c, int(size/2), name='sepconv_l3_3', kernel_size=ksize) c = UpSampling2D((2, 2))(c) # merge second and third branches b = add([b, c]) b = blocks.sepconv_residual(b, size, name='sepconv_l2_3', kernel_size=ksize) b = UpSampling2D((2, 2))(b) # merge first and second branches x = add([a, b]) # model = Model(inputs=xi, outputs=x, name=name) return x
def sepconv_residual(x, out_size, name, kernel_size=(3, 3)): ''' Separable convolution with residual TODO: Schema ''' shortcut_name = name + '_shortcut' reduce_name = name + '_reduce' num_filters = K.int_shape(x)[-1] if num_filters == out_size: ident = x else: ident = layers.act_conv_bn(x, out_size, (1, 1), name=shortcut_name) if out_size < num_filters: x = layers.act_conv_bn(x, out_size, (1, 1), name=reduce_name) x = layers.separable_act_conv_bn(x, out_size, kernel_size, name=name) x = add([ident, x]) return x
def stem(self, inp): ''' inception v4 stem input: 256 x 256 x 3 output: 32 x 32 x 576 ''' print("BUILDING STEM") # xi = Input(shape=inp.get_shape().as_list()[1:]) # 256 x 256 x 3 x = layers.conv_bn_act(inp, 32, (3, 3), strides=(2, 2), name="stem1") x = layers.conv_bn_act(x, 32, (3, 3), name="stem2") x = layers.conv_bn_act(x, 64, (3, 3), name="stem3") a = layers.conv_bn_act(x, 96, (3, 3), strides=(2, 2), name="stem4") b = MaxPooling2D((3, 3), strides=(2, 2), padding='same', name="stem5")(x) x = concatenate([a, b], name="stem6") a = layers.conv_bn_act(x, 64, (1, 1), name="stem7") a = layers.conv_bn(a, 96, (3, 3), name="stem8") b = layers.conv_bn_act(x, 64, (1, 1), name="stem9") b = layers.conv_bn_act(b, 64, (5, 1), name="stem10") b = layers.conv_bn_act(b, 64, (1, 5), name="stem11") b = layers.conv_bn(b, 96, (3, 3), name="stem12") x = concatenate([a, b], name="stem13") a = layers.act_conv_bn(x, 192, (3, 3), strides=(2, 2), name="stem14") b = MaxPooling2D((2, 2), strides=(2, 2), name="stem15")(x) x = concatenate([a, b], name="stem16") x = blocks.sepconv_residual(x, 3 * 192, name='sepconv1') # model = Model(xi, x, name='Stem') # print("Stem model summary") # model.summary() # x = model(inp) return x