Пример #1
0
def deconv_net(scope, latent_variable):
    with tf.variable_scope(scope):
        x = latent_variable
        x = U.dense(x, 2048, 'l3', U.normc_initializer(1.0))
        x = tf.nn.relu(U.dense(x, 128 * 8 * 11, 'l4',
                               U.normc_initializer(1.0)))
        x = tf.reshape(x, [tf.shape(x)[0], 8, 11, 128])  # Unflatten
        x = tf.nn.relu(
            U.conv2d_transpose(x, [4, 4, 128, 128],
                               [tf.shape(x)[0], 19, 25, 128],
                               "uc1", [4, 4], [2, 2],
                               pad="VALID"))
        x = tf.nn.relu(
            U.conv2d_transpose(x, [6, 6, 128, 128],
                               [tf.shape(x)[0], 38, 50, 128],
                               "uc2", [6, 6], [2, 2],
                               pad="SAME"))
        x = tf.nn.relu(
            U.conv2d_transpose(x, [6, 6, 128, 128],
                               [tf.shape(x)[0], 80, 105, 128],
                               "uc3", [6, 6], [2, 2],
                               pad="VALID"))
        x = U.conv2d_transpose(x, [8, 8, 1, 128],
                               [tf.shape(x)[0], 160, 210, 1],
                               "uc4", [8, 8], [2, 2],
                               pad="SAME")
        return x
Пример #2
0
	def decoder_net(self, latent_variable):
		x = latent_variable
		x = U.dense(x, 256, 'l2', U.normc_initializer(1.0))
		x = tf.nn.relu(U.dense(x, 1024, 'l3', U.normc_initializer(1.0)))
		x = tf.reshape(x, [tf.shape(x)[0], 4,4,64]) # Unflatten [4, 4, 64]
		x = tf.nn.relu(U.conv2d_transpose(x, [4,4,64,64], [tf.shape(x)[0], 8,8,64], "uc1", [2, 2], pad="SAME")) # [8, 8, 64]
		x = tf.nn.relu(U.conv2d_transpose(x, [4,4,32,64], [tf.shape(x)[0], 16,16,32], "uc2", [2, 2], pad="SAME")) # [16, 16, 32]
		x = tf.nn.relu(U.conv2d_transpose(x, [4,4,32,32], [tf.shape(x)[0], 32,32,32], "uc3", [2, 2], pad="SAME")) # [32, 32, 32]
		x = U.conv2d_transpose(x, [4,4,3,32], [tf.shape(x)[0], 64,64,3], "uc4", [2, 2], pad="SAME") # [64, 64, 1]
		return x
Пример #3
0
def get_model(point_cloud, is_training, bn_decay=None):
    """ Autoencoder for point clouds.
    Input:
        point_cloud: TF tensor BxNx3
        is_training: boolean
        bn_decay: float between 0 and 1
    Output:
        net: TF tensor BxNx3, reconstructed point clouds
        end_points: dict
    """
    global num_point
    batch_size = point_cloud.get_shape()[0].value
    point_dim = point_cloud.get_shape()[2].value
    end_points = {}

    input_image = tf.expand_dims(point_cloud, -1)

    # Encoder
    net = tf_util.conv2d(input_image, 64, [1,point_dim],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv2', bn_decay=bn_decay)
    point_feat = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv3', bn_decay=bn_decay)
    net = tf_util.conv2d(point_feat, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv4', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 1024, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv5', bn_decay=bn_decay)
    global_feat = tf.reduce_max(net, axis=1, keepdims=False)

    net = tf.reshape(global_feat, [batch_size, -1])
    net = tf_util.fully_connected(net, 1024, bn=True, is_training=is_training, scope='fc00', bn_decay=bn_decay)
    end_points['embedding'] = net

    # UPCONV Decoder
    net = tf.reshape(net, [batch_size, 1, 2, -1])
    net = tf_util.conv2d_transpose(net, 512, kernel_size=[2,2], stride=[2,2], padding='VALID', scope='upconv1', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 256, kernel_size=[3,3], stride=[1,1], padding='VALID', scope='upconv2', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 256, kernel_size=[4,5], stride=[2,3], padding='VALID', scope='upconv3', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 128, kernel_size=[5,7], stride=[3,3], padding='VALID', scope='upconv4', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 3, kernel_size=[1,1], stride=[1,1], padding='VALID', scope='upconv5', activation_fn=None)
    end_points['xyzmap'] = net
    net = tf.reshape(net, [batch_size, -1, 3])

    return net, end_points
Пример #4
0
def Decoder(vector, is_training, bn_decay=None):
    """ Classification PointNet, input is BxNx3, output Bx40 """
    batch_size = vector.get_shape()[0].value
    print(np.shape(vector))
    net = tf.reshape(vector, [batch_size, 1, 1, -1])
    net = tf_util.conv2d_transpose(net,
                                   512,
                                   kernel_size=[2, 2],
                                   stride=[2, 2],
                                   padding='VALID',
                                   scope='upconv2',
                                   bn=True,
                                   bn_decay=bn_decay,
                                   is_training=is_training)
    net = tf_util.conv2d_transpose(net,
                                   256,
                                   kernel_size=[3, 3],
                                   stride=[1, 1],
                                   padding='VALID',
                                   scope='upconv3',
                                   bn=True,
                                   bn_decay=bn_decay,
                                   is_training=is_training)
    net = tf_util.conv2d_transpose(net,
                                   256,
                                   kernel_size=[4, 4],
                                   stride=[2, 2],
                                   padding='VALID',
                                   scope='upconv4',
                                   bn=True,
                                   bn_decay=bn_decay,
                                   is_training=is_training)
    net = tf_util.conv2d_transpose(net,
                                   128,
                                   kernel_size=[5, 5],
                                   stride=[3, 3],
                                   padding='VALID',
                                   scope='upconv5',
                                   bn=True,
                                   bn_decay=bn_decay,
                                   is_training=is_training)
    net = tf_util.conv2d_transpose(net,
                                   3,
                                   kernel_size=[1, 1],
                                   stride=[1, 1],
                                   padding='VALID',
                                   scope='upconv6',
                                   activation_fn=None)
    net = tf.reshape(net, [batch_size, -1, 3])
    pred = net

    return pred
def pc_decoder(y_tilde, batch_size, is_training, bn_decay):
    # UPCONV Decoder
    net = tf.reshape(y_tilde, [batch_size, 1, 1, 512])
    net = tf_util.conv2d_transpose(net, 512, kernel_size=[2, 2], stride=[1, 1], padding='VALID', scope='upconv1',
                                   bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 256, kernel_size=[2, 2], stride=[1, 1], padding='VALID', scope='upconv2',
                                   bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 256, kernel_size=[3, 3], stride=[1, 1], padding='VALID', scope='upconv3',
                                   bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 128, kernel_size=[4, 4], stride=[3, 3], padding='VALID', scope='upconv4',
                                   bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 3, kernel_size=[1, 1], stride=[1, 1], padding='VALID', scope='upconv5',
                                   activation_fn=None)
    pc_upconv = tf.reshape(net, [batch_size, -1, 3])

    # FC Decoder
    net = tf_util.fully_connected(y_tilde, 256, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 256, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 256 * 3, activation_fn=None, scope='fc3')
    pc_fc = tf.reshape(net, (batch_size, -1, 3))
    net = tf.concat(values=[pc_fc, pc_upconv], axis=1)
    pc_fc = tf.reshape(net, (batch_size, -1, 3))
    return pc_fc
Пример #6
0
def pointnet_deconv(inputs, num_output_channels, n_upsample, is_training, bn_decay, scope):
    '''
    Input: 
    	inputs: (batch_size, ndataset1, nfeature1) TF tensor   
    Output:
    	new_points: (batch_size, ndataset2, nfeature2) TF tensor   
    
    '''
    with tf.variable_scope(scope) as sc:
      	batch_size = inputs.get_shape()[0].value
      	npoints = inputs.get_shape()[1].value
      	inputs = tf.expand_dims(inputs, 2)
      	new_points = tf_util.conv2d_transpose(inputs, num_output_channels, [1, n_upsample], scope='deconv', stride=[1, n_upsample], bn_decay=bn_decay)
      	new_points = tf.reshape(new_points, [batch_size, n_upsample*npoints, num_output_channels])
       
        return new_points    	
Пример #7
0
    def inference(self, inputs, is_training):

        d_out = self.config.d_out
        feature = inputs['features']
        feature = tf.layers.dense(feature, 8, activation=None, name='fc0')
        feature = tf.nn.leaky_relu(tf.layers.batch_normalization(feature, -1, 0.99, 1e-6, training=is_training))
        feature = tf.expand_dims(feature, axis=2)

        # ###########################Encoder############################
        f_encoder_list = []
        for i in range(self.config.num_layers):
            f_encoder_i = self.dilated_res_block(feature, inputs['xyz'][i], inputs['neigh_idx'][i], d_out[i],
                                                 'Encoder_layer_' + str(i), is_training)
            f_sampled_i = self.random_sample(f_encoder_i, inputs['sub_idx'][i])
            feature = f_sampled_i
            if i == 0:
                f_encoder_list.append(f_encoder_i)
            f_encoder_list.append(f_sampled_i)
        # ###########################Encoder############################

        feature = tf_util.conv2d(f_encoder_list[-1], f_encoder_list[-1].get_shape()[3].value, [1, 1],
                                 'decoder_0', [1, 1], 'VALID', True, is_training)

        # ###########################Decoder############################
        f_decoder_list = []
        for j in range(self.config.num_layers):
            f_interp_i = self.nearest_interpolation(feature, inputs['interp_idx'][-j - 1])
            f_decoder_i = tf_util.conv2d_transpose(tf.concat([f_encoder_list[-j - 2], f_interp_i], axis=3),
                                                   f_encoder_list[-j - 2].get_shape()[-1].value, [1, 1],
                                                   'Decoder_layer_' + str(j), [1, 1], 'VALID', bn=True,
                                                   is_training=is_training)
            feature = f_decoder_i
            f_decoder_list.append(f_decoder_i)
        # ###########################Decoder############################

        f_layer_fc1 = tf_util.conv2d(f_decoder_list[-1], 64, [1, 1], 'fc1', [1, 1], 'VALID', True, is_training)
        f_layer_fc2 = tf_util.conv2d(f_layer_fc1, 32, [1, 1], 'fc2', [1, 1], 'VALID', True, is_training)
        f_layer_drop = tf_util.dropout(f_layer_fc2, keep_prob=0.5, is_training=is_training, scope='dp1')
        f_layer_fc3 = tf_util.conv2d(f_layer_drop, self.config.num_classes, [1, 1], 'fc', [1, 1], 'VALID', False,
                                     is_training, activation_fn=None)
        f_out = tf.squeeze(f_layer_fc3, [2])
        return f_out
Пример #8
0
def get_model(point_cloud, is_training, bn_decay=None):
    """ Autoencoder for point clouds.
    Input:
        point_cloud: TF tensor BxNx3
        is_training: boolean
        bn_decay: float between 0 and 1
    Output:
        net: TF tensor BxNx3, reconstructed point clouds
        end_points: dict
    """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    assert(num_point==2048)
    point_dim = point_cloud.get_shape()[2].value
    end_points = {}

    input_image = tf.expand_dims(point_cloud, -1)

    # Encoder
    net = tf_util.conv2d(input_image, 64, [1,point_dim],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv2', bn_decay=bn_decay)
    point_feat = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv3', bn_decay=bn_decay)
    net = tf_util.conv2d(point_feat, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv4', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 1024, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv5', bn_decay=bn_decay)
    global_feat = tf_util.max_pool2d(net, [num_point,1],
                                     padding='VALID', scope='maxpool')

    net = tf.reshape(global_feat, [batch_size, -1])
    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc00', bn_decay=bn_decay)
    embedding = tf.reshape(net, [batch_size, -1])
    end_points['embedding'] = embedding

    # FC Decoder
    net = tf_util.fully_connected(embedding, 512, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 512, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    net = tf_util.fully_connected(net, 1024*3, activation_fn=None, scope='fc3')
    pc_fc = tf.reshape(net, (batch_size, -1, 3))

    # UPCONV Decoder
    net = tf.reshape(embedding, [batch_size, 1, 1, -1])                                                                                                                 # 1 x 1 = 1
    net = tf_util.conv2d_transpose(net, 512, kernel_size=[2,2], stride=[1,1], padding='VALID', scope='upconv1', bn=True, bn_decay=bn_decay, is_training=is_training)    # 2 x 2 = 4
    net = tf_util.conv2d_transpose(net, 256, kernel_size=[3,3], stride=[1,1], padding='VALID', scope='upconv2', bn=True, bn_decay=bn_decay, is_training=is_training)    # 4 x 4 = 16
    net = tf_util.conv2d_transpose(net, 256, kernel_size=[4,4], stride=[2,2], padding='VALID', scope='upconv3', bn=True, bn_decay=bn_decay, is_training=is_training)    # 10x10 = 100
    net = tf_util.conv2d_transpose(net, 128, kernel_size=[5,5], stride=[3,3], padding='VALID', scope='upconv4', bn=True, bn_decay=bn_decay, is_training=is_training)    # 32x32 = 1024
    # net = tf_util.conv2d_transpose(net, 80,  kernel_size=[5,5], stride=[2,2], padding= 'SAME', scope='upconv5', bn=True, bn_decay=bn_decay, is_training=is_training)    # 64x64 = 4096
    net = tf_util.conv2d_transpose(net, 3, kernel_size=[1,1], stride=[1,1], padding='VALID', scope='upconv6', activation_fn=None)
    end_points['xyzmap'] = net
    pc_upconv = tf.reshape(net, [batch_size, -1, 3])

    # Set union
    net = tf.concat(values=[pc_fc,pc_upconv], axis=1)

    assert(net.get_shape()[1].value == 2048)

    return net, end_points
Пример #9
0
def get_model(point_cloud, is_training, bn_decay=None):
    """ Autoencoder for point clouds.
    Input:
        point_cloud: TF tensor BxNx3
        is_training: boolean
        bn_decay: float between 0 and 1
    Output:
        net: TF tensor BxNx3, reconstructed point clouds
        end_points: dict
    """
    batch_size = point_cloud.get_shape()[0].value
    num_point = point_cloud.get_shape()[1].value
    assert(num_point==2048)
    point_dim = point_cloud.get_shape()[2].value
    end_points = {}

    input_image = tf.expand_dims(point_cloud, -1)

    # Encoder
    net = tf_util.conv2d(input_image, 64, [1,point_dim],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv2', bn_decay=bn_decay)
    point_feat = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv3', bn_decay=bn_decay)
    net = tf_util.conv2d(point_feat, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv4', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 1024, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv5', bn_decay=bn_decay)
    global_feat = tf_util.max_pool2d(net, [num_point,1],
                                     padding='VALID', scope='maxpool')

    net = tf.reshape(global_feat, [batch_size, -1])
    net = tf_util.fully_connected(net, 1024, bn=True, is_training=is_training, scope='fc00', bn_decay=bn_decay)
    #
    z_mu = tf.reshape(net, [batch_size, -1])
    end_points['embedding'] = z_mu
    z_log_sigma_sq = tf_util.fully_connected(z_mu, 1024, scope='enc_fc4_sigma', activation_fn=None)
    eps = tf.random_normal(shape=tf.shape(z_log_sigma_sq),
                           mean=0, stddev=1, dtype=tf.float32)
    net = net + tf.sqrt(tf.exp(z_log_sigma_sq)) * eps


    # latent_loss = -0.5 * tf.reduce_sum(1 + z_log_sigma_sq - tf.square(z_mu) - tf.exp(z_log_sigma_sq), axis=1)
    # end_points['latent_loss'] = tf.reduce_mean(latent_loss)

    # UPCONV Decoder
    net = tf.reshape(net, [batch_size, 1, 2, -1])
    net = tf_util.conv2d_transpose(net, 512, kernel_size=[2,2], stride=[2,2], padding='VALID', scope='upconv1', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 256, kernel_size=[3,3], stride=[1,1], padding='VALID', scope='upconv2', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 256, kernel_size=[4,5], stride=[2,3], padding='VALID', scope='upconv3', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 128, kernel_size=[5,7], stride=[3,3], padding='VALID', scope='upconv4', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 3, kernel_size=[1,1], stride=[1,1], padding='VALID', scope='upconv5', activation_fn=None)
    end_points['xyzmap'] = net
    net = tf.reshape(net, [batch_size, -1, 3])

    return net, end_points
Пример #10
0
def get_model(point_cloud, is_training, bn_decay=None):
    """ ConvNet baseline, input is BxNx3 gray image """
    batch_size = point_cloud.get_shape()[0].value
    image_h = point_cloud.get_shape()[1].value
    image_w = point_cloud.get_shape()[2].value
    num_point = image_h * image_w
    num_classes = 2
    input_image = point_cloud
    print(
        '___________________________model_structure____________________________________'
    )
    print('input_image', input_image.shape)
    # CONV
    #    net = tf_util.conv2d(input_image, 64, [1,1], padding='VALID', stride=[1,1],
    #                         bn=True, is_training=is_training, scope='conv1', bn_decay=bn_decay)
    #    net = tf_util.conv2d(net, 64, [1,1], padding='VALID', stride=[1,1],
    #                         bn=True, is_training=is_training, scope='conv2', bn_decay=bn_decay)
    #    net = tf_util.conv2d(net, 64, [1,1], padding='VALID', stride=[1,1],
    #                         bn=True, is_training=is_training, scope='conv3', bn_decay=bn_decay)
    #    net = tf_util.conv2d(net, 128, [1,1], padding='VALID', stride=[1,1],
    #                         bn=True, is_training=is_training, scope='conv4', bn_decay=bn_decay)
    #    print('conv4',net.shape)
    #    points_feat1 = tf_util.conv2d(net, 1024, [1,1], padding='VALID', stride=[1,1],
    #                         bn=True, is_training=is_training, scope='conv5', bn_decay=bn_decay)
    #    print('feat1',points_feat1.shape)
    #    # MAX
    #    pc_feat1 = tf_util.max_pool2d(points_feat1, [image_h,image_w], padding='VALID', scope='maxpool1')
    #    # FC
    #    pc_feat1 = tf.reshape(pc_feat1, [batch_size, -1])
    #    pc_feat1 = tf_util.fully_connected(pc_feat1, 256, bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay)
    #    pc_feat1 = tf_util.fully_connected(pc_feat1, 128, bn=True, is_training=is_training, scope='fc2', bn_decay=bn_decay)
    #    print('feat fc1',pc_feat1.shape)
    #
    #    # CONCAT
    #    pc_feat1_expand = tf.tile(tf.reshape(pc_feat1, [batch_size, 1, 1, -1]), [1, image_h, image_w, 1])
    #    points_feat1_concat = tf.concat(axis=3, values=[points_feat1, pc_feat1_expand])
    #    print('concat1 ',points_feat1_concat.shape)
    #    # CONV
    #    net = tf_util.conv2d(points_feat1_concat, 512, [1,1], padding='VALID', stride=[1,1],
    #                         bn=True, is_training=is_training, scope='conv6')
    #    net = tf_util.conv2d(net, 256, [1,1], padding='VALID', stride=[1,1],
    #                         bn=True, is_training=is_training, scope='conv7')
    #    net = tf_util.dropout(net, keep_prob=0.4, is_training=is_training, scope='dp1')
    #    net = tf_util.conv2d(net, 5, [1,1], padding='VALID', stride=[1,1],
    #                         activation_fn=None, scope='conv8')
    #    print('convf ',net.shape)
    #    res_1 = tf_util.conv2d(input_image, 7, [1,1],
    #                         padding='SAME', stride=[1,1],
    #                         bn=True, is_training=is_training,
    #                         scope='conv_input', bn_decay=bn_decay)
    res_1 = tf_util.max_pool2d(input_image, [2, 2],
                               stride=[1, 1],
                               padding='SAME',
                               scope='res_1')
    print('res_1', np.shape(res_1))
    #---------------------------------------------------------
    print('input image', np.shape(input_image))
    net = tf_util.conv2d(input_image,
                         8, [1, 1],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv1',
                         bn_decay=bn_decay)
    print('conv1', np.shape(net))
    net = tf_util.conv2d(net,
                         8, [1, 1],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv2',
                         bn_decay=bn_decay)
    print('conv2', np.shape(net))
    net = tf_util.max_pool2d(net, [2, 2],
                             stride=[1, 1],
                             padding='SAME',
                             scope='maxpool1')
    print('after pooling1', np.shape(net))
    convtp_1 = tf_util.conv2d_transpose(net,
                                        8, [1, 1],
                                        padding='SAME',
                                        stride=[1, 1],
                                        bn=True,
                                        is_training=is_training,
                                        scope='convtp_1',
                                        bn_decay=bn_decay)
    print('convtp_1', np.shape(convtp_1))
    convtp_1p = tf_util.conv2d_transpose(res_1,
                                         16, [2, 2],
                                         padding='SAME',
                                         stride=[1, 1],
                                         bn=True,
                                         is_training=is_training,
                                         scope='convtp_1p',
                                         bn_decay=bn_decay)
    print('convtp_1p', np.shape(convtp_1p))
    #--------------------------------------------------------------

    res_2 = tf_util.max_pool2d(net, [2, 3],
                               stride=[1, 1],
                               padding='SAME',
                               scope='res_2')
    print('res_2', np.shape(res_2))
    net = tf.concat([net, res_1], axis=3)
    print('hebing_1', np.shape(net))
    net = tf_util.conv2d(net,
                         8, [2, 2],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv3',
                         bn_decay=bn_decay)
    print('conv3', np.shape(net))
    net = tf_util.conv2d(net,
                         16, [2, 2],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv4',
                         bn_decay=bn_decay)
    print('conv4', np.shape(net))
    net = tf_util.max_pool2d(net, [2, 3],
                             stride=[1, 1],
                             padding='SAME',
                             scope='maxpool2')
    print('after pooling2', np.shape(net))
    convtp_2 = tf_util.conv2d_transpose(net,
                                        16, [2, 3],
                                        padding='SAME',
                                        stride=[1, 1],
                                        bn=True,
                                        is_training=is_training,
                                        scope='convtp_2',
                                        bn_decay=bn_decay)
    print('convtp_2', np.shape(convtp_2))
    convtp_2p = tf_util.conv2d_transpose(res_2,
                                         32, [2, 3],
                                         padding='SAME',
                                         stride=[1, 1],
                                         bn=True,
                                         is_training=is_training,
                                         scope='convtp_2p',
                                         bn_decay=bn_decay)
    print('convtp_2p', np.shape(convtp_2p))
    #-----------------------------------------------------------

    res_3 = tf_util.max_pool2d(net, [2, 2],
                               stride=[1, 1],
                               padding='SAME',
                               scope='res_3')
    print('res_3', np.shape(res_3))
    net = tf.concat([net, res_2], axis=3)
    print('hebing_2', np.shape(net))
    net = tf_util.conv2d(net,
                         16, [2, 2],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv5',
                         bn_decay=bn_decay)
    print('conv5', np.shape(net))
    net = tf_util.conv2d(net,
                         16, [2, 2],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv6',
                         bn_decay=bn_decay)
    print('conv6', np.shape(net))
    net = tf_util.max_pool2d(net, [3, 3],
                             stride=[1, 1],
                             padding='SAME',
                             scope='maxpool3')
    print('after pooling3', np.shape(net))
    convtp_3 = tf_util.conv2d_transpose(net,
                                        16, [4, 6],
                                        padding='SAME',
                                        stride=[1, 1],
                                        bn=True,
                                        is_training=is_training,
                                        scope='convtp_3',
                                        bn_decay=bn_decay)
    print('convtp_3', np.shape(convtp_3))
    convtp_3p = tf_util.conv2d_transpose(res_3,
                                         32, [4, 6],
                                         padding='SAME',
                                         stride=[1, 1],
                                         bn=True,
                                         is_training=is_training,
                                         scope='convtp_3p',
                                         bn_decay=bn_decay)
    print('convtp_3p', np.shape(convtp_3p))
    #----------------------------------------------------------

    res_4 = tf_util.max_pool2d(net, [2, 2],
                               stride=[1, 1],
                               padding='SAME',
                               scope='res_4')
    print('res_4', np.shape(res_4))

    net = tf.concat([net, res_3], axis=3)
    print('hebing_3', np.shape(net))
    net = tf_util.conv2d(net,
                         16, [3, 3],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv7',
                         bn_decay=bn_decay)
    print('conv7', np.shape(net))
    net = tf_util.conv2d(net,
                         32, [3, 3],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv8',
                         bn_decay=bn_decay)
    print('conv8', np.shape(net))
    net = tf_util.max_pool2d(net, [3, 3],
                             stride=[1, 1],
                             padding='SAME',
                             scope='maxpool4')
    print('after pooling4', np.shape(net))
    dp_net4 = tf_util.dropout(net,
                              keep_prob=0.8,
                              is_training=is_training,
                              scope='dp_net4')
    convtp_4 = tf_util.conv2d_transpose(dp_net4,
                                        32, [8, 12],
                                        padding='SAME',
                                        stride=[1, 1],
                                        bn=True,
                                        is_training=is_training,
                                        scope='convtp_4',
                                        bn_decay=bn_decay)
    print('convtp_4', np.shape(convtp_4))
    convtp_4p = tf_util.conv2d_transpose(res_4,
                                         64, [8, 12],
                                         padding='SAME',
                                         stride=[1, 1],
                                         bn=True,
                                         is_training=is_training,
                                         scope='convtp_4p',
                                         bn_decay=bn_decay)
    print('convtp_4p', np.shape(convtp_4p))

    #-----------------------------------------------------------
    net = tf.concat([net, res_4], axis=3)
    print('hebing_4', np.shape(net))
    net = tf_util.conv2d(net,
                         64, [3, 3],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv9',
                         bn_decay=bn_decay)
    print('conv9', np.shape(net))
    net = tf_util.conv2d(net,
                         256, [3, 3],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv10',
                         bn_decay=bn_decay)
    print('conv10', np.shape(net))
    net = tf_util.conv2d(net,
                         512, [4, 6],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv10p',
                         bn_decay=bn_decay)
    print('conv10p', np.shape(net))
    net = tf_util.max_pool2d(net, [6, 9],
                             stride=[1, 1],
                             padding='SAME',
                             scope='maxpool5')
    print('after pooling5', np.shape(net))
    dp_net5 = tf_util.dropout(net,
                              keep_prob=0.8,
                              is_training=is_training,
                              scope='dp_net5')
    convtp_5 = tf_util.conv2d_transpose(dp_net5,
                                        128, [14, 18],
                                        padding='SAME',
                                        stride=[1, 1],
                                        bn=True,
                                        is_training=is_training,
                                        scope='convtp_5',
                                        bn_decay=bn_decay)
    print('convtp_5', np.shape(convtp_5))
    #----------------------------------------------------------
    net = tf.concat([
        convtp_5, convtp_4, convtp_3, convtp_2, convtp_1, convtp_1p, convtp_2p,
        convtp_3p, convtp_4p
    ],
                    axis=3)
    print('tranpose_hebing', np.shape(net))
    net = tf_util.dropout(net,
                          keep_prob=0.8,
                          is_training=is_training,
                          scope='dp1')
    net = tf_util.conv2d(net,
                         512, [1, 1],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv11',
                         bn_decay=bn_decay)
    print('conv11', np.shape(net))
    net = tf_util.dropout(net,
                          keep_prob=0.6,
                          is_training=is_training,
                          scope='dp2')
    net = tf_util.conv2d(net,
                         256, [1, 1],
                         padding='SAME',
                         stride=[1, 1],
                         bn=True,
                         is_training=is_training,
                         scope='conv12',
                         bn_decay=bn_decay)
    print('conv12', np.shape(net))
    net = tf_util.dropout(net,
                          keep_prob=0.4,
                          is_training=is_training,
                          scope='dp3')
    net = tf_util.conv2d(net,
                         num_classes, [1, 1],
                         padding='VALID',
                         stride=[1, 1],
                         activation_fn=None,
                         scope='conv13')
    print('conv13', np.shape(net))

    #-------------------------dev_code----------------------------------

    #---------------------------------------------------------
    net = tf.reshape(net, [batch_size, num_point, num_classes])
    # net = tf.squeeze(net, [2])
    print('output ', net.shape)
    return net
Пример #11
0
def get_decoder_network(features, encoder, is_training):
    # Args:
    #     features: is tensor of size BxHxWxF where B is batch size, H, W and F are features dimensions
    #     encoder: the Python dictionary containning all tensors from get_encoder_network
    # Returns:
    #     edge_logits: is tensor of size BxVxHxWx1 where B is batch size, V is number of views, H and W are image dimensions
    net = {}
    net['conv20'] = tf_util.conv2d_transpose(features,
                                             128, [4, 4],
                                             activation_fn=leak_relu,
                                             bn=True,
                                             is_training=is_training,
                                             scope='decoder/conv20',
                                             stride=[2, 2],
                                             padding='SAME')  # H/16 * H/16
    concat = tf.concat(axis=3, values=[encoder['conv17'], net['conv20']])
    net['conv21'] = tf_util.conv2d(concat,
                                   128, [3, 3],
                                   activation_fn=leak_relu,
                                   scope='decoder/conv21',
                                   bn=True,
                                   is_training=is_training)  # H/16 * H/16
    net['conv22'] = tf_util.conv2d_transpose(net['conv21'],
                                             64, [4, 4],
                                             activation_fn=leak_relu,
                                             bn=True,
                                             is_training=is_training,
                                             scope='decoder/conv22',
                                             stride=[2, 2],
                                             padding='SAME')  # H/8 * H/8
    concat = tf.concat(axis=3, values=[encoder['conv13'], net['conv22']])
    net['conv23'] = tf_util.conv2d(concat,
                                   64, [3, 3],
                                   activation_fn=leak_relu,
                                   scope='decoder/conv23',
                                   bn=True,
                                   is_training=is_training)  # H/8 * H/8
    net['conv24'] = tf_util.conv2d_transpose(net['conv23'],
                                             64, [4, 4],
                                             activation_fn=leak_relu,
                                             bn=True,
                                             is_training=is_training,
                                             scope='decoder/conv24',
                                             stride=[2, 2],
                                             padding='SAME')  # H/4 * H/4
    concat = tf.concat(axis=3, values=[encoder['conv9'], net['conv24']])
    net['conv25'] = tf_util.conv2d(concat,
                                   64, [3, 3],
                                   activation_fn=leak_relu,
                                   scope='decoder/conv25',
                                   bn=True,
                                   is_training=is_training)  # H/4 * H/4
    net['conv26'] = tf_util.conv2d_transpose(net['conv25'],
                                             64, [4, 4],
                                             activation_fn=leak_relu,
                                             bn=True,
                                             is_training=is_training,
                                             scope='decoder/conv26',
                                             stride=[2, 2],
                                             padding='SAME')  # H/2 * H/2
    concat = tf.concat(axis=3, values=[encoder['conv5'], net['conv26']])
    net['conv27'] = tf_util.conv2d(concat,
                                   64, [3, 3],
                                   activation_fn=leak_relu,
                                   scope='decoder/conv27',
                                   bn=True,
                                   is_training=is_training)  # H/2 * H/2
    net['conv28'] = tf_util.conv2d_transpose(net['conv27'],
                                             32, [4, 4],
                                             activation_fn=leak_relu,
                                             bn=True,
                                             is_training=is_training,
                                             scope='decoder/conv28',
                                             stride=[2, 2],
                                             padding='SAME')  # H * W
    concat = tf.concat(axis=3, values=[encoder['conv2'], net['conv28']])
    net['conv29'] = tf_util.conv2d(concat,
                                   32, [3, 3],
                                   activation_fn=leak_relu,
                                   scope='decoder/conv29',
                                   bn=True,
                                   is_training=is_training)  # H * W
    edge_logits = tf_util.conv2d(net['conv29'],
                                 1, [3, 3],
                                 activation_fn=None,
                                 scope='decoder/edge_logit',
                                 bn=False,
                                 is_training=is_training)

    return edge_logits
Пример #12
0
def get_decoder(embedding, is_training, scope='', bn_decay=None, bn=True):

    batch_size = embedding.get_shape()[0].value
    print(embedding.shape)
    net = tf_util.fully_connected(embedding,
                                  512,
                                  bn=True,
                                  is_training=is_training,
                                  scope='fc1',
                                  bn_decay=bn_decay)
    net = tf_util.fully_connected(net,
                                  512,
                                  bn=True,
                                  is_training=is_training,
                                  scope='fc2',
                                  bn_decay=bn_decay)
    net = tf_util.fully_connected(net,
                                  1024 * 3,
                                  activation_fn=None,
                                  scope='fc3')
    pc_fc = tf.reshape(net, (batch_size, -1, 3))

    # UPCONV Decoder
    net = tf.reshape(embedding, [batch_size, 1, 1, -1])
    net = tf_util.conv2d_transpose(net,
                                   512,
                                   kernel_size=[2, 2],
                                   stride=[1, 1],
                                   padding='VALID',
                                   scope='upconv1',
                                   bn=True,
                                   bn_decay=bn_decay,
                                   is_training=is_training)
    net = tf_util.conv2d_transpose(net,
                                   256,
                                   kernel_size=[3, 3],
                                   stride=[1, 1],
                                   padding='VALID',
                                   scope='upconv2',
                                   bn=True,
                                   bn_decay=bn_decay,
                                   is_training=is_training)
    net = tf_util.conv2d_transpose(net,
                                   256,
                                   kernel_size=[4, 4],
                                   stride=[2, 2],
                                   padding='VALID',
                                   scope='upconv3',
                                   bn=True,
                                   bn_decay=bn_decay,
                                   is_training=is_training)
    net = tf_util.conv2d_transpose(net,
                                   128,
                                   kernel_size=[5, 5],
                                   stride=[3, 3],
                                   padding='VALID',
                                   scope='upconv4',
                                   bn=True,
                                   bn_decay=bn_decay,
                                   is_training=is_training)
    net = tf_util.conv2d_transpose(net,
                                   3,
                                   kernel_size=[1, 1],
                                   stride=[1, 1],
                                   padding='VALID',
                                   scope='upconv5',
                                   activation_fn=None)

    pc_upconv = tf.reshape(net, [batch_size, -1, 3])

    # Set union
    reconst_pc = tf.concat(values=[pc_fc, pc_upconv], axis=1)

    return reconst_pc
Пример #13
0
def get_model(point_cloud, is_training, bn_decay=None):
    """ Autoencoder for point clouds.
    Input:
        point_cloud: TF tensor BxNx3
        is_training: boolean
        bn_decay: float between 0 and 1
    Output:
        net: TF tensor BxNx3, reconstructed point clouds
        end_points: dict
    """
    batch_size = point_cloud.get_shape()[0].value
    point_dim = point_cloud.get_shape()[2].value
    end_points = {}

    input_image = tf.expand_dims(point_cloud, -1)

    # Encoder
    net = tf_util.conv2d(input_image, 64, [1,point_dim],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv1', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv2', bn_decay=bn_decay)
    point_feat = tf_util.conv2d(net, 64, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv3', bn_decay=bn_decay)
    net = tf_util.conv2d(point_feat, 128, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv4', bn_decay=bn_decay)
    net = tf_util.conv2d(net, 512, [1,1],
                         padding='VALID', stride=[1,1],
                         bn=True, is_training=is_training,
                         scope='conv5', bn_decay=bn_decay)
    global_feat = tf.reduce_max(net, axis=1, keepdims=False)
    global_feat = tf.reshape(global_feat, [batch_size, -1])
    '''
    net = tf_util.fully_connected(net, 1024, bn=True, is_training=is_training, scope='fc00', bn_decay=bn_decay)
    end_points['embedding'] = net
    '''
    with tf.variable_scope('vae'):
        def glorot_init(shape):
            return tf.random_normal(shape=shape, stddev=1. / tf.sqrt(shape[0] / 2.))
        # Variables
        hidden_dim = 512
        latent_dim = 1024
        weights = {
            'z_mean': tf.Variable(glorot_init([hidden_dim, latent_dim])),
            'z_std': tf.Variable(glorot_init([hidden_dim, latent_dim])),
        }
        biases = {
            'z_mean': tf.Variable(glorot_init([latent_dim])),
            'z_std': tf.Variable(glorot_init([latent_dim])),
        }
        z_mean = tf.matmul(global_feat, weights['z_mean']) + biases['z_mean']
        z_std = tf.matmul(global_feat, weights['z_std']) + biases['z_std']
        end_points['z_mean'] = z_mean
        end_points['z_std'] = z_std
        # Sampler: Normal (gaussian) random distribution
        samples = tf.random_normal([batch_size, latent_dim], dtype=tf.float32, mean=0., stddev=1.0, name='epsilon')
        # z = µ + σ * N (0, 1)
        z = z_mean + z_std * samples
        #z = z_mean + tf.exp(z_std / 2) * samples

    # UPCONV Decoder
    # (N,1024) -> (N,1,2,512)
    net = tf.reshape(z, [batch_size, 1, 2, -1])
    net = tf_util.conv2d_transpose(net, 512, kernel_size=[2,2], stride=[2,2], padding='VALID', scope='upconv1', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 256, kernel_size=[3,3], stride=[1,1], padding='VALID', scope='upconv2', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 256, kernel_size=[4,5], stride=[2,3], padding='VALID', scope='upconv3', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 128, kernel_size=[5,7], stride=[3,3], padding='VALID', scope='upconv4', bn=True, bn_decay=bn_decay, is_training=is_training)
    net = tf_util.conv2d_transpose(net, 3, kernel_size=[1,1], stride=[1,1], padding='VALID', scope='upconv5', activation_fn=None)
    end_points['xyzmap'] = net
    net = tf.reshape(net, [batch_size, -1, 3])

    return net, end_points