Points / segmentation labels shape mismatch
superkido511 opened this issue · comments
Hello, I'm facing a problem that the input (points) and output segmentation labels shape loaded from tfrecord does not match. I'm using tensorflow code. Here is how i'm generating tfrecord:
from libs import points_new
points , normals, features, labels = [], [], [], []
for i in range(0, len(stl_list)):
try:
p = stl_list[i]
mesh = trimesh.load(p)
mesh_label = 1.0 if "label-1" in p else 2.0
for v in mesh.vertices: # shape (n, 3)
for j in range(3):
points.append(v[j])
labels.append(mesh_label)
if (i % 2) == 1:
points = np.array(points).reshape(-1, 3).astype(np.float32)
labels = np.array(labels).reshape(-1, 1).astype(np.float32)
print(points.shape[0] == labels.shape[0])
point_cloud = points_new(points, [], [], labels)
out_path = os.path.join(out_dir, os.path.dirname(p).split(os.sep)[-1] + ".points")
write_point_cloud(point_cloud, out_path)
points_list.append(out_path + " 0")
then generate tfrecord by running
python convert_tfrecords.py --file_dir O-CNN/points --list_file O-CNN/filenames.txt --records_name O-CNN/dataset_test.tfrecords
When loaded in tensorflow/script/dataset.py
at line points, label = self.parse_example(record)
, I noticed the shape mismatch
I tried with partnet tfrecord files and the shape matched. In the paper, it's stated that when creating octree, empty octant will be labeled as 0. Is this automated in the code ? What did I do wrong?
The normals & features must not be empty at the same time. If there is no normal, you can simply provide a fake normal, such as (0,0,1) for each point or provide a one-dimensional feature 1 for each point.
You can refer to this function to generate a point cloud with labels.
Thanks for your response! Can you please check if my command to convert_tfrecords.py is correct?
when I try points, label = self.parse_example(record)
the index seems to be messed up.
For example:
points_list = [points1, points2, points3, points4]
labels = [labels4, labels2, labels1, labels3]
where pointsn = (len_n, 4) and labelsn = (len_n, 1)
I tried passing dummy normals list, still get the wrong index for points and labels
This does not happen when I use tfrecord from your dataset (eg: bed_level3.tfrecord)
points = np.array(points).reshape(-1, 3).astype(np.float32)
The data type of points is wrong. The points should be saved in a python list, not a numpy array: [x_1, y_1, z_1, ..., x_n, y_n, z_n]
For simplicity, you can store your data in the widely used *.ply format. Then follow the example here to build the tfrecords.
Thank you! I converted my data to .ply and follow the example. It works now