SpatialLM icon indicating copy to clipboard operation
SpatialLM copied to clipboard

Question about position encoding

Open yiming-cc opened this issue 1 year ago • 4 comments

Hello authors,

Thank you for your excellent work and for sharing your code!

I have a question regarding the positional encoding strategy used in the model. From the code, I noticed that after obtaining the Sonata encoder features, the normalized grid_coord is used to generate the Fourier positional encoding.

        point = self.enc(point)
        context = point["sparse_conv_feat"].features

        if self.enable_fourier_encode:
            coords = point["grid_coord"]
            coords_normalised = coords / (self.reduced_grid_size - 1)
            encoded_coords = fourier_encode_vector(coords_normalised)

            context = torch.cat([context, encoded_coords], dim=-1)
            context = self.input_proj(context)

However, I'm a bit confused about this choice. Since the input point cloud undergoes positive shifting and other preprocessing steps to compute grid_coord, it seems that the resulting coordinates may not be fully aligned with the original point cloud. This leads to the misalignment between the predict bbox and the input point cloud bbox. Could you please clarify the rationale behind this design choice? Or let me know if there is something I might have misunderstood?

Looking forward to your insights. Thanks again for your great work!

yiming-cc avatar Jul 26 '25 12:07 yiming-cc

Hi, thank you for your question. The normalized grid coordinates represent the normalized voxel indices in the deepest layer of the encoder that matches the normalization values in the input point cloud. For example, if the original point cloud grid_coord along the x-axis is 128, which as normed value 128 / 1280 = 0.1, after passing through four downsampling layers in the encoder (each reducing the size by half), the unnormalized x-axis index becomes 128 / (2^4) = 8, the normed value is 8 * 16 / 1280 = 0.1. We followed the same positional encoding strategy as SceneScript .

In our experiments, we tested using only the Sonata encoded features, without including these relative positional embeddings, and observed noticeable misalignments between the predicted bounding boxes and the input point cloud. Our interpretation is that U-Net based method mainly leverage skip connections to pass XYZ from the input point cloud to the Decoder blocks, to remap features back to their accurate XYZ positions. The encoder primarily extracts semantic features, while positional information is largely restored in the decoder via these skip connections using the ground-truth point coordinates. It generally works well for segmentation tasks, or methods with a decoder.

Therefore, adding positional embeddings in the last layer helps the model predict more accurate position values in our cases. We have not yet explored more advanced positional embedding strategies, such as learnable Fourier embeddings or Rotary Positional Embeddings (RoPE), which are interesting directions for future work.

SamMaoYS avatar Jul 27 '25 08:07 SamMaoYS

Thanks for your quick reply! I completely agree that incorporating positional encoding can benefit bounding box prediction. However, I still have a couple of questions:

  • The input point cloud is first preprocessed with a positive shift, which modifies its XYZ coordinates. These shifted coordinates are then used in subsequent steps such as grid sampling. However, the bounding box annotations in the original point cloud are not shifted (or are the ground truth bounding boxes also shifted during training to match the point cloud?). Since the LLM uses the shifted coordinates to predict the bounding boxes, I'm concerned there might be a misalignment between the predicted and ground truth bounding boxes.

  • Why did you choose to use relative (normalized) positional encoding instead of absolute coordinates? Normalizing the positions removes scale information, which I believe is important for accurately predicting bounding box locations.

Thank you again for your time and for the helpful discussion!

yiming-cc avatar Jul 27 '25 10:07 yiming-cc

Sure, for the first question:

  • Yes, the ground truth annotations are shifted, normalized, and discretized to align with the grid sampling or any other augmentations during training. You can check the training data augmentation code here .

As for the second question:

  • As the grid_coords are not the actual XYZ values of the points, but the indices of the voxels. And the normalization here is not a min-max normalization, but normalize with a global max number of bins. This global scale information should be easy to recover during the training, as well as the mapping between XYZ values and the voxel indices.

SamMaoYS avatar Jul 27 '25 10:07 SamMaoYS

Thanks so much for your detailed explanations — that clears up all my questions. I really appreciate your help!

I'll go ahead and close the issue now. 🙏

yiming-cc avatar Jul 27 '25 11:07 yiming-cc