question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question about grid_subsampling code

See original GitHub issue

Thanks for your great work and nice code.

My question is about the code in grid_subsampling when computing the subsampled_class for the subsampled point. The code is:

https://github.com/HuguesTHOMAS/KPConv/blob/935a2bd75775b07eda8cecbacf2d91b2dd7cbf8d/cpp_wrappers/cpp_subsampling/grid_subsampling/grid_subsampling.cpp#L100

The logic here is to find out the label with the most occurrence number. The label’s occurrence number is stored in an unordered_map, with different labels as different keys, and corresponding occurrence number as values.

The code is using max_element to do it, but does not pass the third comp param. So what the code actually does, is just to find the max key in the unordered_map. It’s not what we want.

I think we need to add the third param to max_element like this:

max_element(v.second.labels[i].begin(), v.second.labels[i].end(), 
    [](const pair<int, int>&a, const pair<int, int>&b){return a.second < b.second;})

My test code is as follows:

#include <iostream>
#include <unordered_map>
#include <algorithm>

using namespace std;

int main() {
    unordered_map<int, int> map; // label -> occurrence number
    map[5] = 2;
    map[2] = 3;

    auto r1 = max_element(map.begin(), map.end());
    cout << r1->first << "->" << r1->second << endl; // output: 5->2, it's wrong!


    auto r2 = max_element(map.begin(), map.end(),
            [](const pair<int, int>&a, const pair<int, int>&b){return a.second < b.second;});
    cout << r2->first << "->" << r2->second << endl; // output: 2->3, it's right

    return 0;
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
HuguesTHOMAScommented, Jun 1, 2020

Thanks for the info

0reactions
LiyaoTangcommented, Jun 1, 2020

I see, probably the pointXYZ part let me think it’s from PCL. Particularly, I encountered this piece of code in RandLA-Net (here: https://github.com/QingyongHu/RandLA-Net/tree/master/utils/cpp_wrappers)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Grid Subsampling - HuguesTHOMAS/KPConv-PyTorch - GitHub
I have a slight different question regarding visualizing feature map. In your KPConv paper, you have visualized feature maps for different ...
Read more >
Anyone know the code for GRID BASED SAMPLING
I read in a paper that grid based sampling is used for finding the patches in a an image based on color.Please share...
Read more >
Subsamplings - an overview | ScienceDirect Topics
A quincunx subsampling divides the image grid into a coarse grid that keeps one point out of two and a detail grid of...
Read more >
How to automate LiDAR point cloud sub-sampling with ... - ORBi
The ultimate guide to subsample 3D point clouds from scratch, with. Python. Two efficient methods are shown to import, process, structure as a...
Read more >
How to automate LiDAR point cloud sub-sampling with Python
The grid subsampling strategy will be based on the division of the 3D space in regular cubic cells called voxels. For each cell...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found