Пример #1
0
def unet2D_bn_modified(images, training, nlabels):

    images_padded = tf.pad(images, [[0,0], [92, 92], [92, 92], [0,0]], 'CONSTANT')

    conv1_1 = layers.conv2D_layer_bn(images_padded, 'conv1_1', num_filters=64, training=training, padding='VALID')
    conv1_2 = layers.conv2D_layer_bn(conv1_1, 'conv1_2', num_filters=64, training=training, padding='VALID')

    pool1 = layers.max_pool_layer2d(conv1_2)

    conv2_1 = layers.conv2D_layer_bn(pool1, 'conv2_1', num_filters=128, training=training, padding='VALID')
    conv2_2 = layers.conv2D_layer_bn(conv2_1, 'conv2_2', num_filters=128, training=training, padding='VALID')

    pool2 = layers.max_pool_layer2d(conv2_2)

    conv3_1 = layers.conv2D_layer_bn(pool2, 'conv3_1', num_filters=256, training=training, padding='VALID')
    conv3_2 = layers.conv2D_layer_bn(conv3_1, 'conv3_2', num_filters=256, training=training, padding='VALID')

    pool3 = layers.max_pool_layer2d(conv3_2)

    conv4_1 = layers.conv2D_layer_bn(pool3, 'conv4_1', num_filters=512, training=training, padding='VALID')
    conv4_2 = layers.conv2D_layer_bn(conv4_1, 'conv4_2', num_filters=512, training=training, padding='VALID')

    pool4 = layers.max_pool_layer2d(conv4_2)

    conv5_1 = layers.conv2D_layer_bn(pool4, 'conv5_1', num_filters=1024, training=training, padding='VALID')
    conv5_2 = layers.conv2D_layer_bn(conv5_1, 'conv5_2', num_filters=1024, training=training, padding='VALID')

    upconv4 = layers.deconv2D_layer_bn(conv5_2, name='upconv4', kernel_size=(4, 4), strides=(2, 2), num_filters=nlabels, training=training)
    concat4 = layers.crop_and_concat_layer([upconv4, conv4_2], axis=3)

    conv6_1 = layers.conv2D_layer_bn(concat4, 'conv6_1', num_filters=512, training=training, padding='VALID')
    conv6_2 = layers.conv2D_layer_bn(conv6_1, 'conv6_2', num_filters=512, training=training, padding='VALID')

    upconv3 = layers.deconv2D_layer_bn(conv6_2, name='upconv3', kernel_size=(4, 4), strides=(2, 2), num_filters=nlabels, training=training)

    concat3 = layers.crop_and_concat_layer([upconv3, conv3_2], axis=3)

    conv7_1 = layers.conv2D_layer_bn(concat3, 'conv7_1', num_filters=256, training=training, padding='VALID')
    conv7_2 = layers.conv2D_layer_bn(conv7_1, 'conv7_2', num_filters=256, training=training, padding='VALID')

    upconv2 = layers.deconv2D_layer_bn(conv7_2, name='upconv2', kernel_size=(4, 4), strides=(2, 2), num_filters=nlabels, training=training)
    concat2 = layers.crop_and_concat_layer([upconv2, conv2_2], axis=3)

    conv8_1 = layers.conv2D_layer_bn(concat2, 'conv8_1', num_filters=128, training=training, padding='VALID')
    conv8_2 = layers.conv2D_layer_bn(conv8_1, 'conv8_2', num_filters=128, training=training, padding='VALID')

    upconv1 = layers.deconv2D_layer_bn(conv8_2, name='upconv1', kernel_size=(4, 4), strides=(2, 2), num_filters=nlabels, training=training)
    concat1 = layers.crop_and_concat_layer([upconv1, conv1_2], axis=3)

    conv9_1 = layers.conv2D_layer_bn(concat1, 'conv9_1', num_filters=64, training=training, padding='VALID')
    conv9_2 = layers.conv2D_layer_bn(conv9_1, 'conv9_2', num_filters=64, training=training, padding='VALID')

    pred = layers.conv2D_layer_bn(conv9_2, 'pred', num_filters=nlabels, kernel_size=(1,1), activation=tf.identity, training=training, padding='VALID')

    return pred
Пример #2
0
def unet3D_bn(images, training, nlabels):

    images_padded = tf.pad(images, [[0, 0], [44, 44], [44, 44],[44, 44], [0, 0]], 'CONSTANT')

    conv1_1 = layers.conv3D_layer_bn(images_padded, 'conv1_1', num_filters=32, kernel_size=(3,3,3), training=training, padding='VALID')
    conv1_2 = layers.conv3D_layer_bn(conv1_1, 'conv1_2', num_filters=64, kernel_size=(3,3,3), training=training, padding='VALID')

    pool1 = layers.max_pool_layer3d(conv1_2, kernel_size=(2,2,2), strides=(2,2,2))

    conv2_1 = layers.conv3D_layer_bn(pool1, 'conv2_1', num_filters=64, kernel_size=(3,3,3), training=training, padding='VALID')
    conv2_2 = layers.conv3D_layer_bn(conv2_1, 'conv2_2', num_filters=128, kernel_size=(3,3,3), training=training, padding='VALID')

    pool2 = layers.max_pool_layer3d(conv2_2, kernel_size=(2,2,2), strides=(2,2,2))

    conv3_1 = layers.conv3D_layer_bn(pool2, 'conv3_1', num_filters=128, kernel_size=(3,3,3), training=training, padding='VALID')
    conv3_2 = layers.conv3D_layer_bn(conv3_1, 'conv3_2', num_filters=256, kernel_size=(3,3,3), training=training, padding='VALID')

    pool3 = layers.max_pool_layer3d(conv3_2, kernel_size=(2,2,2), strides=(2,2,2))

    conv4_1 = layers.conv3D_layer_bn(pool3, 'conv4_1', num_filters=256, kernel_size=(3,3,3), training=training, padding='VALID')
    conv4_2 = layers.conv3D_layer_bn(conv4_1, 'conv4_2', num_filters=512, kernel_size=(3,3,3), training=training, padding='VALID')

    upconv3 = layers.deconv3D_layer_bn(conv4_2, name='upconv3', kernel_size=(4, 4, 4), strides=(2, 2, 2), num_filters=512, training=training)
    concat3 = layers.crop_and_concat_layer([upconv3, conv3_2], axis=4)

    conv5_1 = layers.conv3D_layer_bn(concat3, 'conv5_1', num_filters=256, kernel_size=(3,3,3), training=training, padding='VALID')
    conv5_2 = layers.conv3D_layer_bn(conv5_1, 'conv5_2', num_filters=256, kernel_size=(3,3,3), training=training, padding='VALID')

    upconv2 = layers.deconv3D_layer_bn(conv5_2, name='upconv2', kernel_size=(4, 4, 4), strides=(2, 2, 2), num_filters=256, training=training)
    concat2 = layers.crop_and_concat_layer([upconv2, conv2_2], axis=4)

    conv6_1 = layers.conv3D_layer_bn(concat2, 'conv6_1', num_filters=128, kernel_size=(3,3,3), training=training, padding='VALID')
    conv6_2 = layers.conv3D_layer_bn(conv6_1, 'conv6_2', num_filters=128, kernel_size=(3,3,3), training=training, padding='VALID')

    upconv1 = layers.deconv3D_layer_bn(conv6_2, name='upconv1', kernel_size=(4, 4, 2), strides=(2, 2, 2), num_filters=128, training=training)
    concat1 = layers.crop_and_concat_layer([upconv1, conv1_2], axis=4)

    conv8_1 = layers.conv3D_layer_bn(concat1, 'conv8_1', num_filters=64, kernel_size=(3,3,3), training=training, padding='VALID')
    conv8_2 = layers.conv3D_layer_bn(conv8_1, 'conv8_2', num_filters=64, kernel_size=(3,3,3), training=training, padding='VALID')

    pred = layers.conv3D_layer_bn(conv8_2, 'pred', num_filters=nlabels, kernel_size=(1,1,1), activation=tf.identity, training=training, padding='VALID')

    return pred
Пример #3
0
def forward(images, training, nlabels):

    conv1_1 = layers.conv2D_layer_bn(images,
                                     'conv1_1',
                                     num_filters=64,
                                     training=training,
                                     padding='SAME')
    conv1_2 = layers.conv2D_layer_bn(conv1_1,
                                     'conv1_2',
                                     num_filters=64,
                                     training=training,
                                     padding='SAME')

    pool1 = layers.max_pool_layer2d(conv1_2, 'pool_1')

    conv2_1 = layers.conv2D_layer_bn(pool1,
                                     'conv2_1',
                                     num_filters=128,
                                     training=training,
                                     padding='SAME')
    conv2_2 = layers.conv2D_layer_bn(conv2_1,
                                     'conv2_2',
                                     num_filters=128,
                                     training=training,
                                     padding='SAME')

    pool2 = layers.max_pool_layer2d(conv2_2, 'pool_2')
    dout2 = layers.dropout_layer(pool2, 'dropout_2', training)

    conv3_1 = layers.conv2D_layer_bn(dout2,
                                     'conv3_1',
                                     num_filters=256,
                                     training=training,
                                     padding='SAME')
    conv3_2 = layers.conv2D_layer_bn(conv3_1,
                                     'conv3_2',
                                     num_filters=256,
                                     training=training,
                                     padding='SAME')

    pool3 = layers.max_pool_layer2d(conv3_2, 'pool_3')
    dout3 = layers.dropout_layer(pool3, 'dropout_3', training)

    conv4_1 = layers.conv2D_layer_bn(dout3,
                                     'conv4_1',
                                     num_filters=512,
                                     training=training,
                                     padding='SAME')
    conv4_2 = layers.conv2D_layer_bn(conv4_1,
                                     'conv4_2',
                                     num_filters=512,
                                     training=training,
                                     padding='SAME')

    pool4 = layers.max_pool_layer2d(conv4_2, 'pool_4')
    dout4 = layers.dropout_layer(pool4, 'dropout_4', training)

    conv5_1 = layers.conv2D_layer_bn(dout4,
                                     'conv5_1',
                                     num_filters=1024,
                                     training=training,
                                     padding='SAME')
    conv5_2 = layers.conv2D_layer_bn(conv5_1,
                                     'conv5_2',
                                     num_filters=1024,
                                     training=training,
                                     padding='SAME')

    upconv4 = layers.deconv2D_layer_bn(conv5_2,
                                       name='upconv4',
                                       kernel_size=(4, 4),
                                       strides=(2, 2),
                                       num_filters=nlabels,
                                       training=training)
    concat4 = layers.crop_and_concat_layer([upconv4, conv4_2],
                                           'crop_concat_4',
                                           axis=3)
    dout5 = layers.dropout_layer(concat4, 'dropout_5', training)

    conv6_1 = layers.conv2D_layer_bn(dout5,
                                     'conv6_1',
                                     num_filters=512,
                                     training=training,
                                     padding='SAME')
    conv6_2 = layers.conv2D_layer_bn(conv6_1,
                                     'conv6_2',
                                     num_filters=512,
                                     training=training,
                                     padding='SAME')

    upconv3 = layers.deconv2D_layer_bn(conv6_2,
                                       name='upconv3',
                                       kernel_size=(4, 4),
                                       strides=(2, 2),
                                       num_filters=nlabels,
                                       training=training)
    concat3 = layers.crop_and_concat_layer([upconv3, conv3_2],
                                           'crop_concat_3',
                                           axis=3)
    dout6 = layers.dropout_layer(concat3, 'dropout_6', training)

    conv7_1 = layers.conv2D_layer_bn(dout6,
                                     'conv7_1',
                                     num_filters=256,
                                     training=training,
                                     padding='SAME')
    conv7_2 = layers.conv2D_layer_bn(conv7_1,
                                     'conv7_2',
                                     num_filters=256,
                                     training=training,
                                     padding='SAME')

    upconv2 = layers.deconv2D_layer_bn(conv7_2,
                                       name='upconv2',
                                       kernel_size=(4, 4),
                                       strides=(2, 2),
                                       num_filters=nlabels,
                                       training=training)
    concat2 = layers.crop_and_concat_layer([upconv2, conv2_2],
                                           'crop_concat_2',
                                           axis=3)
    dout7 = layers.dropout_layer(concat2, 'dropout_7', training)

    conv8_1 = layers.conv2D_layer_bn(dout7,
                                     'conv8_1',
                                     num_filters=128,
                                     training=training,
                                     padding='SAME')
    conv8_2 = layers.conv2D_layer_bn(conv8_1,
                                     'conv8_2',
                                     num_filters=128,
                                     training=training,
                                     padding='SAME')

    upconv1 = layers.deconv2D_layer_bn(conv8_2,
                                       name='upconv1',
                                       kernel_size=(4, 4),
                                       strides=(2, 2),
                                       num_filters=nlabels,
                                       training=training)
    concat1 = layers.crop_and_concat_layer([upconv1, conv1_2],
                                           'crop_concat_1',
                                           axis=3)

    conv9_1 = layers.conv2D_layer_bn(concat1,
                                     'conv9_1',
                                     num_filters=64,
                                     training=training,
                                     padding='SAME')
    conv9_2 = layers.conv2D_layer_bn(conv9_1,
                                     'conv9_2',
                                     num_filters=64,
                                     training=training,
                                     padding='SAME')

    pred_1 = layers.conv2D_layer_bn(conv9_2,
                                    'pred',
                                    num_filters=nlabels,
                                    kernel_size=(1, 1),
                                    activation=tf.identity,
                                    training=training,
                                    padding='SAME')

    # Deep supervision
    ds1_1 = layers.conv2D_layer(conv7_2,
                                'ds_1',
                                num_filters=nlabels,
                                kernel_size=(1, 1),
                                activation=tf.identity,
                                padding='SAME')
    ds1_2 = layers.deconv2D_layer(ds1_1,
                                  'ds_2',
                                  kernel_size=(4, 4),
                                  strides=(2, 2),
                                  num_filters=nlabels,
                                  padding='SAME')
    ds2_1 = layers.conv2D_layer(conv8_2,
                                'ds_3',
                                num_filters=nlabels,
                                kernel_size=(1, 1),
                                activation=tf.identity,
                                padding='SAME')
    ds1_ds2 = tf.add(ds1_2, ds2_1)
    ds = layers.deconv2D_layer(ds1_ds2,
                               'ds_4',
                               kernel_size=(4, 4),
                               strides=(2, 2),
                               num_filters=nlabels,
                               padding='SAME')

    pred_2 = tf.add(pred_1, ds)

    return pred_2
Пример #4
0
def unet_16_2D_bn(x, training, scope_name='generator'):

    n_ch_0 = 16

    with tf.variable_scope(scope_name):

        conv1_1 = layers.conv2D_layer_bn(x,
                                         'conv1_1',
                                         num_filters=n_ch_0,
                                         training=training)
        conv1_2 = layers.conv2D_layer_bn(conv1_1,
                                         'conv1_2',
                                         num_filters=n_ch_0,
                                         training=training)
        pool1 = layers.maxpool2D_layer(conv1_2)

        conv2_1 = layers.conv2D_layer_bn(pool1,
                                         'conv2_1',
                                         num_filters=n_ch_0 * 2,
                                         training=training)
        conv2_2 = layers.conv2D_layer_bn(conv2_1,
                                         'conv2_2',
                                         num_filters=n_ch_0 * 2,
                                         training=training)
        pool2 = layers.maxpool2D_layer(conv2_2)

        conv3_1 = layers.conv2D_layer_bn(pool2,
                                         'conv3_1',
                                         num_filters=n_ch_0 * 4,
                                         training=training)
        conv3_2 = layers.conv2D_layer_bn(conv3_1,
                                         'conv3_2',
                                         num_filters=n_ch_0 * 4,
                                         training=training)
        pool3 = layers.maxpool2D_layer(conv3_2)

        conv4_1 = layers.conv2D_layer_bn(pool3,
                                         'conv4_1',
                                         num_filters=n_ch_0 * 8,
                                         training=training)
        conv4_2 = layers.conv2D_layer_bn(conv4_1,
                                         'conv4_2',
                                         num_filters=n_ch_0 * 8,
                                         training=training)

        upconv3 = layers.deconv2D_layer_bn(conv4_2,
                                           name='upconv3',
                                           num_filters=n_ch_0,
                                           training=training)
        concat3 = layers.crop_and_concat_layer([upconv3, conv3_2], axis=-1)

        conv5_1 = layers.conv2D_layer_bn(concat3,
                                         'conv5_1',
                                         num_filters=n_ch_0 * 4,
                                         training=training)

        conv5_2 = layers.conv2D_layer_bn(conv5_1,
                                         'conv5_2',
                                         num_filters=n_ch_0 * 4,
                                         training=training)

        upconv2 = layers.deconv2D_layer_bn(conv5_2,
                                           name='upconv2',
                                           num_filters=n_ch_0,
                                           training=training)
        concat2 = layers.crop_and_concat_layer([upconv2, conv2_2], axis=-1)

        conv6_1 = layers.conv2D_layer_bn(concat2,
                                         'conv6_1',
                                         num_filters=n_ch_0 * 2,
                                         training=training)
        conv6_2 = layers.conv2D_layer_bn(conv6_1,
                                         'conv6_2',
                                         num_filters=n_ch_0 * 2,
                                         training=training)

        upconv1 = layers.deconv2D_layer_bn(conv6_2,
                                           name='upconv1',
                                           num_filters=n_ch_0,
                                           training=training)
        concat1 = layers.crop_and_concat_layer([upconv1, conv1_2], axis=-1)

        conv8_1 = layers.conv2D_layer_bn(concat1,
                                         'conv8_1',
                                         num_filters=n_ch_0,
                                         training=training)
        conv8_2 = layers.conv2D_layer(conv8_1,
                                      'conv8_2',
                                      num_filters=1,
                                      activation=tf.identity)

    return conv8_2