dilated convolution

先是U-net,它的结构是这样子的,然后是
论文里面是这么说的:

The network architecture is illustrated in Figure 1. It consists of a contracting path (left side) and an expansive path (right side). The contracting path follows the typical architecture of a convolutional network. It consists of the repeated application of two 3x3 convolutions (unpadded convolutions), each followed by a rectified linear unit (ReLU) and a 2x2 max pooling operation with stride 2 for downsampling. At each downsampling step we double the number of feature channels. Every step in the expansive path consists of an upsampling of the feature map followed by a 2x2 convolution (“up-convolution”) that halves the number of feature channels, a concatenation with the correspondingly cropped feature map from the contracting path, and two 3x3 convolutions, each fol- lowed by a ReLU. The cropping is necessary due to the loss of border pixels in every convolution. At the final layer a 1x1 convolution is used to map each 64- component feature vector to the desired number of classes. In total the network has 23 convolutional layers.

然后代码大概是这样子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from keras.models import Input, Model
from keras.layers import Conv2D, Concatenate, MaxPooling2D, Reshape, ZeroPadding2D
from keras.layers import UpSampling2D, Activation, Permute

def level_block(m, dim, depth, factor, acti):
if depth > 0:
n = Conv2D(dim, 3, activation=acti, padding='same')(m)
n = Conv2D(dim, 3, activation=acti, padding='same')(n)
# n = ZeroPadding2D()(n)
# m = AtrousConvolution2D(dim, 3, 3, atrous_rate=(2, 2), activation=acti)(n)
m = MaxPooling2D()(n)
m = level_block(m, int(factor*dim), depth-1, factor, acti)
m = UpSampling2D()(m)
m = Conv2D(dim, 2, activation=acti, padding='same')(m)
# m = Concatenate(axis=3)([n, m])
m = Conv2D(dim, 3, activation=acti, padding='same')(m)
return Conv2D(dim, 3, activation=acti, padding='same')(m)

def UNet(img_shape, n_out=1, dim=64, depth=4, factor=2, acti='elu', flatten=False):
i = Input(shape=img_shape)
o = level_block(i, dim, depth, factor, acti)
o = Conv2D(n_out, (1, 1))(o)
if flatten:
o = Reshape(n_out, img_shape[0] * img_shape[1])(o)
o = Permute((2, 1))(o)
o = Activation('sigmoid')(o)
return Model(inputs=i, outputs=o)

cited (https://github.com/pietz/brats-segmentation)

先熟悉一下keras里面相关的接口吧,

1
2
3
4
5
Conv2D(dim, 3, activation=acti, padding='same')
Conv2D(filters, kernel_size, strides=(1, 1), padding='valid', data_format=None, dilation_rate=(1, 1), activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)

UpSampling2D(size=(2, 2), data_format=None)
upsampling这里doc里面是说repeat。。。

  • padding 有三种
    • same padding
      顾名思义padding完size和原来一样
    • valid padding

先是讲下dilated convolution, 他的结构是这样子的,
avatar
就是kernel的计算的时间复杂度是一样的,但是感受域变大了

CRF

  • conditional random field