def pointSIFT_group_four_with_idx(xyz, idx, points, use_xyz=True): grouped_xyz = group_point(xyz, idx) # (batch_size, npoint, 8/32, 3) # translation normalization grouped_xyz -= tf.tile(tf.expand_dims(xyz, 2), [1, 1, 32, 1]) #if points is not None: if not (len(points.shape) == 1): # (batch_size, npoint, 8/32, channel) grouped_points = group_point(points, idx) if use_xyz: # (batch_size, npoint, 8/32, 3+channel) new_points = tf.concat([grouped_xyz, grouped_points], axis=-1) else: new_points = grouped_points else: new_points = grouped_xyz return xyz, new_points, idx, grouped_xyz
def sample_and_group(npoint, radius, nsample, xyz, points, knn=False, use_xyz=True): ''' Input: npoint: int32 radius: float32 nsample: int32 xyz: (batch_size, ndataset, 3) TF tensor points: (batch_size, ndataset, channel) TF tensor, if None will just use xyz as points knn: bool, if True use kNN instead of radius search use_xyz: bool, if True concat XYZ with local point features, otherwise just use point features Output: new_xyz: (batch_size, npoint, 3) TF tensor new_points: (batch_size, npoint, nsample, 3+channel) TF tensor idx: (batch_size, npoint, nsample) TF tensor, indices of local points as in ndataset points grouped_xyz: (batch_size, npoint, nsample, 3) TF tensor, normalized point XYZs (subtracted by seed point XYZ) in local regions ''' new_xyz = gather_point(xyz, farthest_point_sample( npoint, xyz)) # (batch_size, npoint, 3) if knn: _, idx = knn_point(nsample, xyz, new_xyz) else: idx, pts_cnt = query_ball_point(radius, nsample, xyz, new_xyz) grouped_xyz = group_point(xyz, idx) # (batch_size, npoint, nsample, 3) grouped_xyz -= tf.tile(tf.expand_dims(new_xyz, 2), [1, 1, nsample, 1]) # translation normalization #if points is not None: if not (len(points.shape) == 1): # (batch_size, npoint, nsample, channel) grouped_points = group_point(points, idx) if use_xyz: # (batch_size, npoint, nample, 3+channel) new_points = tf.concat([grouped_xyz, grouped_points], axis=-1) else: new_points = grouped_points else: new_points = grouped_xyz return new_xyz, new_points, idx, grouped_xyz
def call(self, inputs, training=None, **kwargs): xyz, points = inputs if training is None: training = tf.keras.backend.learning_phase() # conv 1 _, new_points, idx, _ = pointSIFT_group(self.radius, xyz, points, use_xyz=self.use_xyz) for i in range(3): new_points = self.conv2d(new_points, self.out_channel, [1, 2], self._name + '-c0_conv%d' % (i), [1, 2], padding='VALID', activation_fn='ReLU', training=training) new_points = tf.squeeze(new_points, [2]) # conv 2 #_, new_points, idx, _ = pointSIFT_group_with_idx(xyz, # idx=idx, # points=new_points, #use_xyz=self.use_xyz) new_points = group_point(new_points, idx) for i in range(3): if i == 2: act = 'None' else: act = 'ReLU' new_points = self.conv2d(new_points, self.out_channel, [1, 2], self._name + '-c1_conv%d' % (i), [1, 2], padding='VALID', activation_fn=act, training=training) new_points = tf.squeeze(new_points, [2]) # residual part #if points is not None: if not (len(points.shape) == 1): if self.same_dim is True: points = self.conv1d(points, self.out_channel, 1, self._name + '-merge_channel_fc', 1, padding='VALID', activation_fn='ReLU', training=training) if self.merge == 'add': new_points = new_points + points elif self.merge == 'concat': new_points = tf.concat([new_points, points], axis=-1) else: print("way not found!!") new_points = tf.nn.relu(new_points) return xyz, new_points, idx