meiqua / pose_refine

cuda icp for 6D pose estimation
BSD 2-Clause "Simplified" License
96 stars 25 forks source link

cuda_render test fail when each pose is different? #2

Closed Guptajakala closed 5 years ago

Guptajakala commented 5 years ago

When I change the code here

std::vector<cuda_renderer::Model::mat4x4> mat4_v(100, mat4);
for (auto &mat:mat4_v)
 {
        mat.c3 += static_cast <float> (rand()) / static_cast <float> (RAND_MAX) * 100;
 }

Then the result of GPU and CPU is different. Is there anything I'm doing wrong?

meiqua commented 5 years ago

Oh, it's due to tiny differences of float between gpu and cpu. When casting to int, it may have a diff of 1, so totally same assertion is too strong here. This problem tends to come out if we have 100 rand poses. You can check this by putting these codes before assertion:

        for(size_t i=0; i<mat4_v.size(); i++){
            int diff_v = std::accumulate(result_diff.data() + i*height*width,
                                         result_diff.data() + (i+1)*height*width, 0);
            if(diff_v > 0){
                std::cout << "test: " << diff_v << std::endl;

                cv::Mat depth = cv::Mat(height, width, CV_32SC1, result_diff.data() + i*height*width);
                cv::imshow("diff_mask", depth>0);
                cv::waitKey(0);
            }
        }
Guptajakala commented 5 years ago

@meiqua
This is the problem. Thank you!