def unet_resnet(input_pred, input_img, output_channel, stage):
    input_shape = input_img.shape
    input_channel = input_shape.dims[(- 1)].value
    input_pred_softmax = tf.nn.softmax(input_pred, name=('softmax_ss' + stage))
    forground_input_pred = tf.expand_dims(input_pred_softmax[:, :, :, :, 1], axis=(- 1))
    input_concat = tf.concat([forground_input_pred, input_img], axis=(- 1))
    input_attention = (forground_input_pred * input_img)
    conv_bn_1_1 = conv_bn_relu(input=input_attention, output_chn=16, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block1_conv1'))
    input_cat = tf.concat([input_attention, input_attention, input_attention, input_attention, input_attention, input_attention, input_attention, input_attention], axis=(- 1))
    if (((input_channel % 2) == 0) or (input_channel == 1)):
        input_tile = tf.tile(input=input_attention, multiples=[1, 1, 1, 1, int((16 / input_channel))], name=('tile' + stage))
    else:
        input_tile = tf.tile(input=input_attention, multiples=[1, 1, 1, 1, int((16 / (input_channel - 1)))], name=('tile' + stage))
        input_tile = input_tile[:, :, :, :, 0:16]
    conv_bn_skip_1_1 = (input_tile + conv_bn_1_1)
    pool1_1 = tf.layers.max_pooling3d(inputs=conv_bn_skip_1_1, pool_size=2, strides=2, name=(stage + 'pool_1_1'))
    conv_bn_2_1 = conv_bn_relu(input=pool1_1, output_chn=32, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block2_conv1'))
    conv_bn_2_2 = conv_bn_relu(input=conv_bn_2_1, output_chn=32, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block2_conv2'))
    pool1_1_cat = tf.concat([pool1_1, pool1_1], axis=(- 1))
    conv_bn_skip_2_1 = (pool1_1_cat + conv_bn_2_2)
    pool_2_1 = tf.layers.max_pooling3d(inputs=conv_bn_skip_2_1, pool_size=2, strides=2, name=(stage + 'pool2_2'))
    conv_bn_3_1 = conv_bn_relu(input=pool_2_1, output_chn=64, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block3_conv1'))
    conv_bn_3_2 = conv_bn_relu(input=conv_bn_3_1, output_chn=64, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block3_conv2'))
    conv_bn_3_3 = conv_bn_relu(input=conv_bn_3_2, output_chn=64, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block3_conv3'))
    pool_2_1_cat = tf.concat([pool_2_1, pool_2_1], axis=(- 1))
    conv_bn_skip_3_1 = (conv_bn_3_3 + pool_2_1_cat)
    pool3_1 = tf.layers.max_pooling3d(inputs=conv_bn_skip_3_1, pool_size=2, strides=2, name=(stage + 'pool3_1'))
    conv_bn_4_1 = conv_bn_relu(input=pool3_1, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block4_conv1'))
    conv_bn_4_2 = conv_bn_relu(input=conv_bn_4_1, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block4_conv2'))
    conv_bn_4_3 = conv_bn_relu(input=conv_bn_4_2, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block4_conv3'))
    pool3_1_cat = tf.concat([pool3_1, pool3_1], axis=(- 1))
    conv_bn_skip_4_1 = (conv_bn_4_3 + pool3_1_cat)
    pool4_1 = tf.layers.max_pooling3d(inputs=conv_bn_skip_4_1, pool_size=2, strides=2, name=(stage + 'pool4_1'))
    conv_bn_5_1 = conv_bn_relu(input=pool4_1, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block5_conv1'))
    conv_bn_5_2 = conv_bn_relu(input=conv_bn_5_1, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block5_conv2'))
    conv_bn_5_3 = conv_bn_relu(input=conv_bn_5_2, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block5_conv3'))
    pool4_1_cat = tf.concat([pool4_1, pool4_1], axis=(- 1))
    conv_bn_skip_5_1 = (conv_bn_5_3 + pool4_1_cat)
    deconv_bn_1_1 = deconv_bn_relu(input=conv_bn_skip_5_1, output_chn=128, is_training=True, name=(stage + 'deconv_1_1'))
    concat1 = tf.concat([deconv_bn_1_1, conv_bn_skip_4_1], axis=(- 1), name=(stage + 'concat1'))
    conv_bn_6_1 = conv_bn_relu(input=concat1, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block6_conv1'))
    conv_bn_6_2 = conv_bn_relu(input=conv_bn_6_1, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block6_conv2'))
    conv_bn_6_3 = conv_bn_relu(input=conv_bn_6_2, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'blovk6_conv3'))
    deconv_bn_1_1_cat = tf.concat([deconv_bn_1_1, deconv_bn_1_1], axis=(- 1))
    conv_bn_skip_6_1 = (conv_bn_6_3 + deconv_bn_1_1_cat)
    deconv_bn_2_1 = deconv_bn_relu(input=conv_bn_skip_6_1, output_chn=64, is_training=True, name=(stage + 'deconv_2_1'))
    concat2 = tf.concat([deconv_bn_2_1, conv_bn_skip_3_1], axis=(- 1), name=(stage + 'concat2'))
    conv_bn_7_1 = conv_bn_relu(input=concat2, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block7_conv1'))
    conv_bn_7_2 = conv_bn_relu(input=conv_bn_7_1, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block7_conv2'))
    conv_bn_7_3 = conv_bn_relu(input=conv_bn_7_2, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block7_conv3'))
    deconv_bn_2_1_cat = tf.concat([deconv_bn_2_1, deconv_bn_2_1], axis=(- 1))
    conv_bn_skip_7_1 = (conv_bn_7_3 + deconv_bn_2_1_cat)
    deconv_bn_3_1 = deconv_bn_relu(input=conv_bn_skip_7_1, output_chn=32, is_training=True, name=(stage + 'deconv_3_1'))
    concat3 = tf.concat([deconv_bn_3_1, conv_bn_skip_2_1], axis=(- 1), name=(stage + 'concat3'))
    conv_bn_8_1 = conv_bn_relu(input=concat3, output_chn=64, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block8_conv1'))
    conv_bn_8_2 = conv_bn_relu(input=conv_bn_8_1, output_chn=64, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block8_conv2'))
    deconv_bn_3_1_cat = tf.concat([deconv_bn_3_1, deconv_bn_3_1], axis=(- 1))
    conv_bn_skip_8_1 = (conv_bn_8_2 + deconv_bn_3_1_cat)
    deconv_bn_4_1 = deconv_bn_relu(input=conv_bn_skip_8_1, output_chn=16, is_training=True, name=(stage + 'deconv_4_1'))
    concat4 = tf.concat([deconv_bn_4_1, conv_bn_skip_1_1], axis=(- 1), name=(stage + 'conca4_1'))
    conv_bn_9_1 = conv_bn_relu(input=concat4, output_chn=32, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block9_conv1'))
    deconv_bn_4_1_cat = tf.concat([deconv_bn_4_1, deconv_bn_4_1], axis=(- 1))
    conv_bn_skip_9_1 = (conv_bn_9_1 + deconv_bn_4_1_cat)
    pred = conv3d(input=conv_bn_skip_9_1, output_chn=output_channel, kernel_size=1, stride=1, use_bias=True, name=(stage + 'pred'))
    soft_prob_v = tf.nn.softmax(pred, name='pred_soft_v')
    pred_label_v = tf.argmax(soft_prob_v, axis=4, name='argmax_v')
    return (pred, pred_label_v)
def unet_resnet(input_pred, input_img, output_channel, stage):
    input_shape = input_img.shape
    input_channel = input_shape.dims[(- 1)].value
    input_pred_softmax = tf.nn.softmax(input_pred, name=('softmax_ss' + stage))
    forground_input_pred = tf.expand_dims(input_pred_softmax[:, :, :, :, 1], axis=(- 1))
    input_concat = tf.concat([forground_input_pred, input_img], axis=(- 1))
    input_attention = (forground_input_pred * input_img)
    conv_bn_1_1 = conv_bn_relu(input=input_attention, output_chn=16, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block1_conv1'))
    input_cat = tf.concat([input_attention, input_attention, input_attention, input_attention, input_attention, input_attention, input_attention, input_attention], axis=(- 1))
    if (((input_channel % 2) == 0) or (input_channel == 1)):
        input_tile = tf.tile(input=input_attention, multiples=[1, 1, 1, 1, int((16 / input_channel))], name=('tile' + stage))
    else:
        input_tile = tf.tile(input=input_attention, multiples=[1, 1, 1, 1, int((16 / (input_channel - 1)))], name=('tile' + stage))
        input_tile = input_tile[:, :, :, :, 0:16]
    conv_bn_skip_1_1 = (input_tile + conv_bn_1_1)
    pool1_1 = tf.layers.max_pooling3d(inputs=conv_bn_skip_1_1, pool_size=2, strides=2, name=(stage + 'pool_1_1'))
    conv_bn_2_1 = conv_bn_relu(input=pool1_1, output_chn=32, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block2_conv1'))
    conv_bn_2_2 = conv_bn_relu(input=conv_bn_2_1, output_chn=32, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block2_conv2'))
    pool1_1_cat = tf.concat([pool1_1, pool1_1], axis=(- 1))
    conv_bn_skip_2_1 = (pool1_1_cat + conv_bn_2_2)
    pool_2_1 = tf.layers.max_pooling3d(inputs=conv_bn_skip_2_1, pool_size=2, strides=2, name=(stage + 'pool2_2'))
    conv_bn_3_1 = conv_bn_relu(input=pool_2_1, output_chn=64, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block3_conv1'))
    conv_bn_3_2 = conv_bn_relu(input=conv_bn_3_1, output_chn=64, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block3_conv2'))
    conv_bn_3_3 = conv_bn_relu(input=conv_bn_3_2, output_chn=64, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block3_conv3'))
    pool_2_1_cat = tf.concat([pool_2_1, pool_2_1], axis=(- 1))
    conv_bn_skip_3_1 = (conv_bn_3_3 + pool_2_1_cat)
    pool3_1 = tf.layers.max_pooling3d(inputs=conv_bn_skip_3_1, pool_size=2, strides=2, name=(stage + 'pool3_1'))
    conv_bn_4_1 = conv_bn_relu(input=pool3_1, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block4_conv1'))
    conv_bn_4_2 = conv_bn_relu(input=conv_bn_4_1, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block4_conv2'))
    conv_bn_4_3 = conv_bn_relu(input=conv_bn_4_2, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block4_conv3'))
    pool3_1_cat = tf.concat([pool3_1, pool3_1], axis=(- 1))
    conv_bn_skip_4_1 = (conv_bn_4_3 + pool3_1_cat)
    pool4_1 = tf.layers.max_pooling3d(inputs=conv_bn_skip_4_1, pool_size=2, strides=2, name=(stage + 'pool4_1'))
    conv_bn_5_1 = conv_bn_relu(input=pool4_1, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block5_conv1'))
    conv_bn_5_2 = conv_bn_relu(input=conv_bn_5_1, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block5_conv2'))
    conv_bn_5_3 = conv_bn_relu(input=conv_bn_5_2, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block5_conv3'))
    pool4_1_cat = tf.concat([pool4_1, pool4_1], axis=(- 1))
    conv_bn_skip_5_1 = (conv_bn_5_3 + pool4_1_cat)
    deconv_bn_1_1 = deconv_bn_relu(input=conv_bn_skip_5_1, output_chn=128, is_training=True, name=(stage + 'deconv_1_1'))
    concat1 = tf.concat([deconv_bn_1_1, conv_bn_skip_4_1], axis=(- 1), name=(stage + 'concat1'))
    conv_bn_6_1 = conv_bn_relu(input=concat1, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block6_conv1'))
    conv_bn_6_2 = conv_bn_relu(input=conv_bn_6_1, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block6_conv2'))
    conv_bn_6_3 = conv_bn_relu(input=conv_bn_6_2, output_chn=256, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'blovk6_conv3'))
    deconv_bn_1_1_cat = tf.concat([deconv_bn_1_1, deconv_bn_1_1], axis=(- 1))
    conv_bn_skip_6_1 = (conv_bn_6_3 + deconv_bn_1_1_cat)
    deconv_bn_2_1 = deconv_bn_relu(input=conv_bn_skip_6_1, output_chn=64, is_training=True, name=(stage + 'deconv_2_1'))
    concat2 = tf.concat([deconv_bn_2_1, conv_bn_skip_3_1], axis=(- 1), name=(stage + 'concat2'))
    conv_bn_7_1 = conv_bn_relu(input=concat2, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block7_conv1'))
    conv_bn_7_2 = conv_bn_relu(input=conv_bn_7_1, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block7_conv2'))
    conv_bn_7_3 = conv_bn_relu(input=conv_bn_7_2, output_chn=128, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block7_conv3'))
    deconv_bn_2_1_cat = tf.concat([deconv_bn_2_1, deconv_bn_2_1], axis=(- 1))
    conv_bn_skip_7_1 = (conv_bn_7_3 + deconv_bn_2_1_cat)
    deconv_bn_3_1 = deconv_bn_relu(input=conv_bn_skip_7_1, output_chn=32, is_training=True, name=(stage + 'deconv_3_1'))
    concat3 = tf.concat([deconv_bn_3_1, conv_bn_skip_2_1], axis=(- 1), name=(stage + 'concat3'))
    conv_bn_8_1 = conv_bn_relu(input=concat3, output_chn=64, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block8_conv1'))
    conv_bn_8_2 = conv_bn_relu(input=conv_bn_8_1, output_chn=64, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block8_conv2'))
    deconv_bn_3_1_cat = tf.concat([deconv_bn_3_1, deconv_bn_3_1], axis=(- 1))
    conv_bn_skip_8_1 = (conv_bn_8_2 + deconv_bn_3_1_cat)
    deconv_bn_4_1 = deconv_bn_relu(input=conv_bn_skip_8_1, output_chn=16, is_training=True, name=(stage + 'deconv_4_1'))
    concat4 = tf.concat([deconv_bn_4_1, conv_bn_skip_1_1], axis=(- 1), name=(stage + 'conca4_1'))
    conv_bn_9_1 = conv_bn_relu(input=concat4, output_chn=32, kernel_size=3, stride=1, use_bias=False, is_training=True, name=(stage + 'block9_conv1'))
    deconv_bn_4_1_cat = tf.concat([deconv_bn_4_1, deconv_bn_4_1], axis=(- 1))
    conv_bn_skip_9_1 = (conv_bn_9_1 + deconv_bn_4_1_cat)
    pred = conv3d(input=conv_bn_skip_9_1, output_chn=output_channel, kernel_size=1, stride=1, use_bias=True, name=(stage + 'pred'))
    soft_prob_v = tf.nn.softmax(pred, name='pred_soft_v')
    pred_label_v = tf.argmax(soft_prob_v, axis=4, name='argmax_v')
    return (pred, pred_label_v)