Hello,
Thank you for sharing your KPCONV code! I'd like to ask if it is possible to add more features to the computation (i.e., XYZ, RGB, intensity or reflectance, no. of returns, return no.). I do not know if I am thinking right, but the changes should be don in datasets/Semantic3D.py (or other datasets.file) in line:
https://github.com/HuguesTHOMAS/KPConv/blob/16bfbb96ac9af48a3c829d1f8123152d35b63862/datasets/Semantic3D.py#L214-L236
by changing the structure of data file like XYZ, RGB, other
and
data = np.loadtxt(txt_file)
points = data[:, :3].astype(np.float32)
colors = data[:, 3:6].astype(np.uint8)
**addvalues = data[:, 6:9].astype(np.float32)**
and
sub_points, sub_colors, **sub_prop**, sub_labels = grid_subsampling(points,
features=colors,
**prop=addvalues,**
labels=labels,
sampleDl=0.01)
# Write the subsampled ply file
write_ply(ply_file_full, (sub_points, sub_colors, sub_prop, sub_labels), ['x', 'y', 'z', 'red', 'green', 'blue', **'reflectance', 'noreturn', 'returnno**', 'class'])
else:
# Write the full ply file
write_ply(ply_file_full, (points, colors,**addvalues**), ['x', 'y', 'z', 'red', 'green', 'blue', **'reflectance', 'noreturn', 'returnno'**])
then in https://github.com/HuguesTHOMAS/KPConv/blob/16bfbb96ac9af48a3c829d1f8123152d35b63862/datasets/Semantic3D.py#L288-L315
should be 1 line added:
data = read_ply(sub_ply_file)
sub_colors = np.vstack((data['red'], data['green'], data['blue'])).T
**sub_prop = np.vstack((data['reflectance'], data['noreturn'], data['returnno'])).T**
and in else also:
else:
# Read ply file
data = read_ply(file_path)
points = np.vstack((data['x'], data['y'], data['z'])).T
colors = np.vstack((data['red'], data['green'], data['blue'])).T
**sub_prop = np.vstack((data['reflectance'], data['noreturn'], data['returnno'])).T**
if cloud_split == 'test':
and in
# Subsample cloud
sub_data = grid_subsampling(points,
features=colors,
**prop=addvalues,**
labels=int_features,
sampleDl=subsampling_parameter)
**But how about rescaling?
# Rescale float color and squeeze label
sub_prop = sub_data[2] / 50 #if the reflectance is used?
**
The next step is to change lines:
https://github.com/HuguesTHOMAS/KPConv/blob/16bfbb96ac9af48a3c829d1f8123152d35b63862/datasets/Semantic3D.py#L327-L337
like:
# Save ply
if cloud_split == 'test':
sub_labels = None
write_ply(sub_ply_file,
[sub_data[0], sub_colors, sub_prop],
['x', 'y', 'z', 'red', 'green', 'blue', **'reflectance', 'noreturn', 'returnno'**])
else:
sub_labels = np.squeeze(sub_data[**3**])
write_ply(sub_ply_file,
[sub_data[0], sub_colors, sub_prop, sub_labels],
['x', 'y', 'z', 'red', 'green', 'blue', **'reflectance', 'noreturn', 'returnno'**, 'class'])
and:
https://github.com/HuguesTHOMAS/KPConv/blob/16bfbb96ac9af48a3c829d1f8123152d35b63862/datasets/Semantic3D.py#L339-L343
# Fill data containers
self.input_trees[cloud_split] += [search_tree]
self.input_colors[cloud_split] += [sub_colors]
**self.input_addvalues[cloud_split] +=[sub_prop]**
if cloud_split in ['training', 'validation']:
self.input_labels[cloud_split] += [sub_labels]
then in line:
https://github.com/HuguesTHOMAS/KPConv/blob/16bfbb96ac9af48a3c829d1f8123152d35b63862/datasets/Semantic3D.py#L581-L585
# Collect points and colors
input_points = (points[input_inds] - pick_point).astype(np.float32)
input_colors = self.input_colors[split][cloud_ind][input_inds]
**input_addvalues=self.input_addvalues[split][cloud_ind][input_inds]**
input_labels = self.input_labels[split][cloud_ind][input_inds]
input_labels = np.array([self.label_to_idx[l] for l in input_labels])
in https://github.com/HuguesTHOMAS/KPConv/blob/16bfbb96ac9af48a3c829d1f8123152d35b63862/datasets/Semantic3D.py#L606
**
c_list += [np.hstack((input_colors, input_addvalues, input_points + pick_point))]
**
in https://github.com/HuguesTHOMAS/KPConv/blob/16bfbb96ac9af48a3c829d1f8123152d35b63862/datasets/Semantic3D.py#L675-L677
# Collect points and colors
input_points = (points[input_inds] - pick_point).astype(np.float32)
input_colors = self.input_colors[data_split][cloud_ind][input_inds]
**input_addvalues=self.input_addvalues[split][cloud_ind][input_inds]**
https://github.com/HuguesTHOMAS/KPConv/blob/16bfbb96ac9af48a3c829d1f8123152d35b63862/datasets/Semantic3D.py#L703
**
c_list += [np.hstack((input_colors, input_addvalues, input_points + pick_point))]
**
Do the types and shapes have to be changed ?
https://github.com/HuguesTHOMAS/KPConv/blob/16bfbb96ac9af48a3c829d1f8123152d35b63862/datasets/Semantic3D.py#L736-L738
and the last part:
https://github.com/HuguesTHOMAS/KPConv/blob/16bfbb96ac9af48a3c829d1f8123152d35b63862/datasets/Semantic3D.py#L745-L792
def tf_map(stacked_points, stacked_colors, stacked_addvalues, point_labels, stacks_lengths, point_inds, cloud_inds):
# Get batch indice for each point
batch_inds = self.tf_get_batch_inds(stacks_lengths)
# Augment input points
stacked_points, scales, rots = self.tf_augment_input(stacked_points,
batch_inds,
config)
# First add a column of 1 as feature for the network to be able to learn 3D shapes
stacked_features = tf.ones((tf.shape(stacked_points)[0], 1), dtype=tf.float32)
# Get coordinates and colors
stacked_original_coordinates = stacked_colors[:, 3:]
stacked_colors = stacked_colors[:, :3]
** # Get coordinates and addvalues
stacked_original_coordinates = stacked_addvalues[:, 3:]
stacked_addvalues = stacked_addvalues[:, :3]**
# Augmentation : randomly drop colors
if config.in_features_dim in [4, 5]:
num_batches = batch_inds[-1] + 1
s = tf.cast(tf.less(tf.random_uniform((num_batches,)), config.augment_color), tf.float32)
stacked_s = tf.gather(s, batch_inds)
stacked_colors = stacked_colors * tf.expand_dims(stacked_s, axis=1)
# Then use positions or not
if config.in_features_dim == 1:
pass
elif config.in_features_dim == 2:
stacked_features = tf.concat((stacked_features, stacked_original_coordinates[:, 2:]), axis=1)
elif config.in_features_dim == 3:
stacked_features = stacked_colors
elif config.in_features_dim == 4:
stacked_features = tf.concat((stacked_features, stacked_colors), axis=1)
elif config.in_features_dim == 5:
stacked_features = tf.concat((stacked_features, stacked_colors, stacked_original_coordinates[:, 2:]), axis=1)
elif config.in_features_dim == 7:
stacked_features = tf.concat((stacked_features, stacked_colors, stacked_points), axis=1)
** elif config.in_features_dim == 10:
stacked_features = tf.concat((stacked_features, stacked_colors, stacked_addvalues, stacked_points), axis=1)**
else:
raise ValueError('Only accepted input dimensions are 1, 3, 4 and 7 , 10(without and with rgb/xyz)')
Is there something else should be changed or the changes should be done in different way?