def _create_conv_net(X, image_width, image_height, image_channel, phase, drop_conv, n_class=1): inputX = tf.reshape(X, [-1, image_width, image_height, image_channel]) # shape=(?, 32, 32, 1) # VNet model # layer0->convolution layer0 = conv_relu(x=inputX, kernalshape=(3, 3, image_channel, 16), scope='layer0') # layer1->convolution layer1 = conv_bn_relu_drop(x=layer0, kernalshape=(3, 3, 16, 16), phase=phase, drop_conv=drop_conv, scope='layer1-1') layer1 = conv_bn_relu_drop(x=layer1, kernalshape=(3, 3, 16, 16), phase=phase, drop_conv=drop_conv, scope='layer1-2') layer1 = resnet_Add(x1=layer0, x2=layer1) # down sampling1 down1 = down_sampling(x=layer1, kernalshape=(3, 3, 16, 32), phase=phase, drop_conv=drop_conv, scope='down1') # layer2->convolution layer2 = conv_bn_relu_drop(x=down1, kernalshape=(3, 3, 32, 32), phase=phase, drop_conv=drop_conv, scope='layer2_1') layer2 = conv_bn_relu_drop(x=layer2, kernalshape=(3, 3, 32, 32), phase=phase, drop_conv=drop_conv, scope='layer2_2') layer2 = resnet_Add(x1=down1, x2=layer2) # down sampling2 down2 = down_sampling(x=layer2, kernalshape=(3, 3, 32, 64), phase=phase, drop_conv=drop_conv, scope='down2') # layer3->convolution layer3 = conv_bn_relu_drop(x=down2, kernalshape=(3, 3, 64, 64), phase=phase, drop_conv=drop_conv, scope='layer3_1') layer3 = conv_bn_relu_drop(x=layer3, kernalshape=(3, 3, 64, 64), phase=phase, drop_conv=drop_conv, scope='layer3_2') layer3 = conv_bn_relu_drop(x=layer3, kernalshape=(3, 3, 64, 64), phase=phase, drop_conv=drop_conv, scope='layer3_3') layer3 = resnet_Add(x1=down2, x2=layer3) # down sampling3 down3 = down_sampling(x=layer3, kernalshape=(3, 3, 64, 128), phase=phase, drop_conv=drop_conv, scope='down3') # layer4->convolution layer4 = conv_bn_relu_drop(x=down3, kernalshape=(3, 3, 128, 128), phase=phase, drop_conv=drop_conv, scope='layer4_1') layer4 = conv_bn_relu_drop(x=layer4, kernalshape=(3, 3, 128, 128), phase=phase, drop_conv=drop_conv, scope='layer4_2') layer4 = conv_bn_relu_drop(x=layer4, kernalshape=(3, 3, 128, 128), phase=phase, drop_conv=drop_conv, scope='layer4_3') layer4 = resnet_Add(x1=down3, x2=layer4) # down sampling4 down4 = down_sampling(x=layer4, kernalshape=(3, 3, 128, 256), phase=phase, drop_conv=drop_conv, scope='down4') # layer5->convolution layer5 = conv_bn_relu_drop(x=down4, kernalshape=(3, 3, 256, 256), phase=phase, drop_conv=drop_conv, scope='layer5_1') layer5 = conv_bn_relu_drop(x=layer5, kernalshape=(3, 3, 256, 256), phase=phase, drop_conv=drop_conv, scope='layer5_2') layer5 = conv_bn_relu_drop(x=layer5, kernalshape=(3, 3, 256, 256), phase=phase, drop_conv=drop_conv, scope='layer5_3') layer5 = resnet_Add(x1=down4, x2=layer5) # down sampling5 down5 = down_sampling(x=layer5, kernalshape=(3, 3, 256, 512), phase=phase, drop_conv=drop_conv, scope='down5') # layer6->convolution layer6 = conv_bn_relu_drop(x=down5, kernalshape=(3, 3, 512, 512), phase=phase, drop_conv=drop_conv, scope='layer6_1') layer6 = conv_bn_relu_drop(x=layer6, kernalshape=(3, 3, 512, 512), phase=phase, drop_conv=drop_conv, scope='layer6_2') layer6 = conv_bn_relu_drop(x=layer6, kernalshape=(3, 3, 512, 512), phase=phase, drop_conv=drop_conv, scope='layer6_3') layer6 = resnet_Add(x1=down5, x2=layer6) # layer7->deconvolution deconv1 = deconv_relu_drop(x=layer6, kernalshape=(3, 3, 256, 512), scope='deconv1') # layer8->convolution layer7 = crop_and_concat(layer5, deconv1) _, H, W, _ = layer5.get_shape().as_list() layer7 = conv_bn_relu_drop(x=layer7, kernalshape=(3, 3, 512, 256), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer7_1') layer7 = conv_bn_relu_drop(x=layer7, kernalshape=(3, 3, 256, 256), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer7_2') layer7 = conv_bn_relu_drop(x=layer7, kernalshape=(3, 3, 256, 256), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer7_3') layer7 = resnet_Add(x1=deconv1, x2=layer7) # deepspu1 output_map1 = upsample2d(x=layer7, scale_factor=16, scope="upsample3d_1") output_map1 = conv_sigmod(x=output_map1, kernalshape=(1, 1, 256, n_class), scope='output_map1') # layer9->deconvolution deconv2 = deconv_relu_drop(x=layer7, kernalshape=(3, 3, 128, 256), scope='deconv2') # layer8->convolution layer8 = crop_and_concat(layer4, deconv2) _, H, W, _ = layer4.get_shape().as_list() layer8 = conv_bn_relu_drop(x=layer8, kernalshape=(3, 3, 256, 128), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer8_1') layer8 = conv_bn_relu_drop(x=layer8, kernalshape=(3, 3, 128, 128), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer8_2') layer8 = conv_bn_relu_drop(x=layer8, kernalshape=(3, 3, 128, 128), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer8_3') layer8 = resnet_Add(x1=deconv2, x2=layer8) # deepspu2 output_map2 = upsample2d(x=layer8, scale_factor=8, scope="upsample3d_2") output_map2 = conv_sigmod(x=output_map2, kernalshape=(1, 1, 128, n_class), scope='output_map2') # layer9->deconvolution deconv3 = deconv_relu_drop(x=layer8, kernalshape=(3, 3, 64, 128), scope='deconv3') # layer8->convolution layer9 = crop_and_concat(layer3, deconv3) _, H, W, _ = layer3.get_shape().as_list() layer9 = conv_bn_relu_drop(x=layer9, kernalshape=(3, 3, 128, 64), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer9_1') layer9 = conv_bn_relu_drop(x=layer9, kernalshape=(3, 3, 64, 64), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer9_2') layer9 = conv_bn_relu_drop(x=layer9, kernalshape=(3, 3, 64, 64), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer9_3') layer9 = resnet_Add(x1=deconv3, x2=layer9) # deepspu3 output_map3 = upsample2d(x=layer9, scale_factor=4, scope="upsample3d_3") output_map3 = conv_sigmod(x=output_map3, kernalshape=(1, 1, 64, n_class), scope='output_map3') # layer9->deconvolution deconv4 = deconv_relu_drop(x=layer9, kernalshape=(3, 3, 32, 64), scope='deconv4') # layer8->convolution layer10 = crop_and_concat(layer2, deconv4) _, H, W, _ = layer2.get_shape().as_list() layer10 = conv_bn_relu_drop(x=layer10, kernalshape=(3, 3, 64, 32), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer10_1') layer10 = conv_bn_relu_drop(x=layer10, kernalshape=(3, 3, 32, 32), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer10_2') layer10 = resnet_Add(x1=deconv4, x2=layer10) # deepspu4 output_map4 = upsample2d(x=layer10, scale_factor=2, scope="upsample3d_4") output_map4 = conv_sigmod(x=output_map4, kernalshape=(1, 1, 32, n_class), scope='output_map4') # layer9->deconvolution deconv5 = deconv_relu_drop(x=layer10, kernalshape=(3, 3, 16, 32), scope='deconv5') # layer8->convolution layer11 = crop_and_concat(layer1, deconv5) _, H, W, _ = layer1.get_shape().as_list() layer11 = conv_bn_relu_drop(x=layer11, kernalshape=(3, 3, 32, 16), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer11_1') layer11 = conv_bn_relu_drop(x=layer11, kernalshape=(3, 3, 16, 16), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer11_2') layer11 = resnet_Add(x1=deconv5, x2=layer11) # layer14->output output_map = conv_sigmod(x=layer11, kernalshape=(1, 1, 16, n_class), scope='output') return output_map, output_map1, output_map2, output_map3, output_map4
def _create_conv_net(X, image_width, image_height, image_channel, phase, drop_conv, n_class=1, n_classify=2): inputX = tf.reshape( X, [-1, image_width, image_height, image_channel]) # shape=(?, 32, 32, 1) # VNet model # layer0->convolution layer0 = conv_relu(x=inputX, kernalshape=(3, 3, image_channel, 16), scope='layer0') # layer1->convolution layer1 = conv_bn_relu_drop(x=layer0, kernalshape=(3, 3, 16, 16), phase=phase, drop_conv=drop_conv, scope='layer1-1') layer1 = conv_bn_relu_drop(x=layer1, kernalshape=(3, 3, 16, 16), phase=phase, drop_conv=drop_conv, scope='layer1-2') layer1 = resnet_Add(x1=layer0, x2=layer1) # down sampling1 down1 = down_sampling(x=layer1, kernalshape=(3, 3, 16, 32), phase=phase, drop_conv=drop_conv, scope='down1') # layer2->convolution layer2 = conv_bn_relu_drop(x=down1, kernalshape=(3, 3, 32, 32), phase=phase, drop_conv=drop_conv, scope='layer2_1') layer2 = conv_bn_relu_drop(x=layer2, kernalshape=(3, 3, 32, 32), phase=phase, drop_conv=drop_conv, scope='layer2_2') layer2 = resnet_Add(x1=down1, x2=layer2) # down sampling2 down2 = down_sampling(x=layer2, kernalshape=(3, 3, 32, 64), phase=phase, drop_conv=drop_conv, scope='down2') # layer3->convolution layer3 = conv_bn_relu_drop(x=down2, kernalshape=(3, 3, 64, 64), phase=phase, drop_conv=drop_conv, scope='layer3_1') layer3 = conv_bn_relu_drop(x=layer3, kernalshape=(3, 3, 64, 64), phase=phase, drop_conv=drop_conv, scope='layer3_2') layer3 = conv_bn_relu_drop(x=layer3, kernalshape=(3, 3, 64, 64), phase=phase, drop_conv=drop_conv, scope='layer3_3') layer3 = resnet_Add(x1=down2, x2=layer3) # down sampling3 down3 = down_sampling(x=layer3, kernalshape=(3, 3, 64, 128), phase=phase, drop_conv=drop_conv, scope='down3') # layer4->convolution layer4 = conv_bn_relu_drop(x=down3, kernalshape=(3, 3, 128, 128), phase=phase, drop_conv=drop_conv, scope='layer4_1') layer4 = conv_bn_relu_drop(x=layer4, kernalshape=(3, 3, 128, 128), phase=phase, drop_conv=drop_conv, scope='layer4_2') layer4 = conv_bn_relu_drop(x=layer4, kernalshape=(3, 3, 128, 128), phase=phase, drop_conv=drop_conv, scope='layer4_3') layer4 = resnet_Add(x1=down3, x2=layer4) # down sampling4 down4 = down_sampling(x=layer4, kernalshape=(3, 3, 128, 256), phase=phase, drop_conv=drop_conv, scope='down4') # layer5->convolution layer5 = conv_bn_relu_drop(x=down4, kernalshape=(3, 3, 256, 256), phase=phase, drop_conv=drop_conv, scope='layer5_1') layer5 = conv_bn_relu_drop(x=layer5, kernalshape=(3, 3, 256, 256), phase=phase, drop_conv=drop_conv, scope='layer5_2') layer5 = conv_bn_relu_drop(x=layer5, kernalshape=(3, 3, 256, 256), phase=phase, drop_conv=drop_conv, scope='layer5_3') layer5 = resnet_Add(x1=down4, x2=layer5) # down sampling5 down5 = down_sampling(x=layer5, kernalshape=(3, 3, 256, 512), phase=phase, drop_conv=drop_conv, scope='down5') # layer6->convolution layer6 = conv_bn_relu_drop(x=down5, kernalshape=(3, 3, 512, 512), phase=phase, drop_conv=drop_conv, scope='layer6_1') layer6 = conv_bn_relu_drop(x=layer6, kernalshape=(3, 3, 512, 512), phase=phase, drop_conv=drop_conv, scope='layer6_2') layer6 = conv_bn_relu_drop(x=layer6, kernalshape=(3, 3, 512, 512), phase=phase, drop_conv=drop_conv, scope='layer6_3') layer6 = resnet_Add(x1=down5, x2=layer6) gap = tf.reduce_mean(layer6, axis=(1, 2)) # layer7->FC1 layerfc1 = tf.reshape(gap, [-1, 512]) # shape=(?, 512) layerfc2 = full_connected_relu_drop(x=layerfc1, kernal=(512, 512), drop=drop_conv, activefunction='relu', scope='fc1') # layer7->output classify_output = full_connected_relu_drop(x=layerfc2, kernal=(512, n_classify), drop=drop_conv, activefunction='regression', scope='classify_output') # layer7->deconvolution deconv1 = deconv_relu_drop(x=layer6, kernalshape=(3, 3, 256, 512), scope='deconv1') # layer8->convolution layer7 = crop_and_concat(layer5, deconv1) _, H, W, _ = layer5.get_shape().as_list() layer7 = conv_bn_relu_drop(x=layer7, kernalshape=(3, 3, 512, 256), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer7_1') layer7 = conv_bn_relu_drop(x=layer7, kernalshape=(3, 3, 256, 256), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer7_2') layer7 = conv_bn_relu_drop(x=layer7, kernalshape=(3, 3, 256, 256), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer7_3') layer7 = resnet_Add(x1=deconv1, x2=layer7) # layer9->deconvolution deconv2 = deconv_relu_drop(x=layer7, kernalshape=(3, 3, 128, 256), scope='deconv2') # layer8->convolution layer8 = crop_and_concat(layer4, deconv2) _, H, W, _ = layer4.get_shape().as_list() layer8 = conv_bn_relu_drop(x=layer8, kernalshape=(3, 3, 256, 128), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer8_1') layer8 = conv_bn_relu_drop(x=layer8, kernalshape=(3, 3, 128, 128), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer8_2') layer8 = conv_bn_relu_drop(x=layer8, kernalshape=(3, 3, 128, 128), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer8_3') layer8 = resnet_Add(x1=deconv2, x2=layer8) # layer9->deconvolution deconv3 = deconv_relu_drop(x=layer8, kernalshape=(3, 3, 64, 128), scope='deconv3') # layer8->convolution layer9 = crop_and_concat(layer3, deconv3) _, H, W, _ = layer3.get_shape().as_list() layer9 = conv_bn_relu_drop(x=layer9, kernalshape=(3, 3, 128, 64), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer9_1') layer9 = conv_bn_relu_drop(x=layer9, kernalshape=(3, 3, 64, 64), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer9_2') layer9 = conv_bn_relu_drop(x=layer9, kernalshape=(3, 3, 64, 64), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer9_3') layer9 = resnet_Add(x1=deconv3, x2=layer9) # layer9->deconvolution deconv4 = deconv_relu_drop(x=layer9, kernalshape=(3, 3, 32, 64), scope='deconv4') # layer8->convolution layer10 = crop_and_concat(layer2, deconv4) _, H, W, _ = layer2.get_shape().as_list() layer10 = conv_bn_relu_drop(x=layer10, kernalshape=(3, 3, 64, 32), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer10_1') layer10 = conv_bn_relu_drop(x=layer10, kernalshape=(3, 3, 32, 32), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer10_2') layer10 = resnet_Add(x1=deconv4, x2=layer10) # layer9->deconvolution deconv5 = deconv_relu_drop(x=layer10, kernalshape=(3, 3, 16, 32), scope='deconv5') # layer8->convolution layer11 = crop_and_concat(layer1, deconv5) _, H, W, _ = layer1.get_shape().as_list() layer11 = conv_bn_relu_drop(x=layer11, kernalshape=(3, 3, 32, 16), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer11_1') layer11 = conv_bn_relu_drop(x=layer11, kernalshape=(3, 3, 16, 16), height=H, width=W, phase=phase, drop_conv=drop_conv, scope='layer11_2') layer11 = resnet_Add(x1=deconv5, x2=layer11) # layer14->output output_map = conv_sigmod(x=layer11, kernalshape=(1, 1, 16, n_class), scope='output') return output_map, classify_output