alicevision / CCTag

Detection of CCTag markers made up of concentric circles.
https://cctag.readthedocs.io
Mozilla Public License 2.0
351 stars 87 forks source link

CCTag reproducible output #203

Closed anauta00 closed 8 months ago

anauta00 commented 1 year ago

Hi,

I have just started using your nice library. The results are encouraging and fast (on the GPU). 😀

However, I would like each 'detection run' to yield the same output. Now, each run shows small deviations in the center points found.

I have looked at the code but cannot seem to find out how to do this.

Can anyone help?

Thanks and greetings, Auke Nauta

simogasp commented 1 year ago

most probably it's because of some randomness of the algorithm in choosing points. Whenever a random function is used in the code, a deterministic seed should be used so that the result are consistent over multiple runs. This may require some refactoring, though. I cannot pinpoint the exact parts but if you are willing to do it, it could be a nice contribution. :)

anauta00 commented 1 year ago

Hi,

I have researched this issue extensively now. Using the CPU, deterministic runs can be obtained by #defining 'CCTAG_SERIALIZE'.

However, for the GPU part, this is far from clear. I tried #defining 'SORT_ALL_EDGECOORDS_IN_EXPORT' but then CCTag would no longer compile: std::sort( _all_edgecoords.host.ptr, _all_edgecoords.host.ptr+all_sz, v_comp ); would not compile then...

As (at least some of) you have wrote the software, I would think (certainly hope!) that you could point me in the right direction. Having non-deterministic output (using the GPU) is not an option for my application.

Thanks for any help and greetings, Auke

simogasp commented 1 year ago

What is the compilation error for std::sort? @griwodz should know better what needs to be done.

anauta00 commented 1 year ago

Hi,

function "int2cmp::operator()" cannot be called with the given argument list    CCTag   C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\xutility  1092    

Several such errors are generated for 'xutility' as well as 'algorithm'.

Predicate 'int2cmp' is defined like this:

class int2cmp
{
public:
    __host__
    inline bool operator()( const int2& l, const int2& r )
    {
        return tpcmp( l, r );
    }
};
simogasp commented 1 year ago

Could it be that _all_edgecoords is a short2 instead of a int2? Maybe trying to define a short2cmp the same way as int2cmp in cmp_list.h and then use it inside the std::sort could solve the issue?

anauta00 commented 1 year ago

Thanks, that did the trick!

However, GPU output still is not deterministic. I tried lots of other things (like using the '--sync' switch) but to no avail. Unfortunately, my knowledge of CUDA programming is really limited and I can not get this to work (to my liking). Any additional help to create deterministic output would be appreciated!

Greetings, Auke

github-actions[bot] commented 9 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.