コード例 #1
0
 def upsample(self, node, current_level, is_training):
     if self.data_format == 'channels_last':
         # suppose that 'channels_last' means CPU
         # resize_trilinear is much faster on CPU
         return resize_trilinear(node,
                                 factors=[2, 2, 2],
                                 name='upsample' + str(current_level),
                                 data_format=self.data_format)
     else:
         # suppose that 'channels_first' means GPU
         # upsample3d_linear is much faster on GPU
         return upsample3d_linear(node,
                                  factors=[2, 2, 2],
                                  name='upsample' + str(current_level),
                                  data_format=self.data_format,
                                  padding='valid_cropped')
コード例 #2
0
 def upsample(self, node, current_level, is_training):
     return upsample3d_linear(node, [2, 2, 2],
                              name='upsample' + str(current_level),
                              data_format=self.data_format)
コード例 #3
0
def network_scn(input, num_labels, is_training, data_format='channels_first'):
    downsampling_factor = 4
    kernel_initializer = he_initializer
    activation = tf.nn.relu
    local_kernel_initializer = he_initializer
    local_activation = tf.nn.tanh
    spatial_kernel_initializer = he_initializer
    spatial_activation = None
    padding = 'reflect'
    with tf.variable_scope('unet'):
        unet = UnetClassicAvgLinear3d(64,
                                      4,
                                      data_format=data_format,
                                      double_filters_per_level=True,
                                      kernel_initializer=kernel_initializer,
                                      activation=activation,
                                      padding=padding)
        local_prediction = unet(input, is_training=is_training)
        local_prediction = conv3d(local_prediction,
                                  num_labels, [1, 1, 1],
                                  name='local_prediction',
                                  padding=padding,
                                  kernel_initializer=local_kernel_initializer,
                                  activation=local_activation,
                                  is_training=is_training)
    with tf.variable_scope('spatial_configuration'):
        local_prediction_pool = avg_pool3d(local_prediction,
                                           [downsampling_factor] * 3,
                                           name='local_prediction_pool')
        scconv = conv3d(local_prediction_pool,
                        64, [5, 5, 5],
                        name='scconv0',
                        padding=padding,
                        kernel_initializer=kernel_initializer,
                        activation=activation,
                        is_training=is_training)
        scconv = conv3d(scconv,
                        64, [5, 5, 5],
                        name='scconv1',
                        padding=padding,
                        kernel_initializer=kernel_initializer,
                        activation=activation,
                        is_training=is_training)
        scconv = conv3d(scconv,
                        64, [5, 5, 5],
                        name='scconv2',
                        padding=padding,
                        kernel_initializer=kernel_initializer,
                        activation=activation,
                        is_training=is_training)
        spatial_prediction_pool = conv3d(
            scconv,
            num_labels, [5, 5, 5],
            name='spatial_prediction_pool',
            padding=padding,
            kernel_initializer=spatial_kernel_initializer,
            activation=spatial_activation,
            is_training=is_training)
        spatial_prediction = upsample3d_linear(spatial_prediction_pool,
                                               [downsampling_factor] * 3,
                                               name='spatial_prediction',
                                               padding='valid_cropped')
    with tf.variable_scope('combination'):
        prediction = local_prediction * spatial_prediction
    return prediction, local_prediction, spatial_prediction