-
-
Notifications
You must be signed in to change notification settings - Fork 55.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non-deterministic behavior in cv2.distanceTransform() #24082
Comments
Cannot reproduce the problem with Do you still have problem on the latest 4.8.0 release? Can you share your CPU arch and details from |
Got same problem when fix number of threads to 1 (cv2.setNumThreads(1)). I use AMD Ryzen Threadripper 1900X CPU |
@a-mos, thanks! Can confirm an error on 4.x branch with IPP enabled (WITH_IPP=OFF works fine). |
@opencv-alalek, @mshabunin, @eplankin, can you recommend how to assign the bug to IPP team? C++ reproducer: int cols = 10, rows = 10;
std::vector<Ipp32f> ref(cols * rows, 0);
std::vector<Ipp32f> dst(cols * rows, 0);
for (int i = 0; i < 2; ++i) {
std::vector<Ipp8u> src(cols * rows, 255);
src[0] = 0;
IppStatus status;
IppiSize roi = { cols, rows };
Ipp8u *pBuffer;
int bufSize=0;
status = ippiTrueDistanceTransformGetBufferSize_8u32f_C1R(roi, &bufSize);
pBuffer = (Ipp8u *)ippMalloc_L( bufSize );
if (i == 0) {
status = ippiTrueDistanceTransform_8u32f_C1R(src.data(), cols, ref.data(), cols*sizeof(float), roi, pBuffer);
} else {
status = ippiTrueDistanceTransform_8u32f_C1R(src.data(), cols, dst.data(), cols*sizeof(float), roi, pBuffer);
}
ippFree( pBuffer );
}
for (int y = 0; y < rows; ++y) {
for (int x = 0; x < cols; ++x) {
if (ref[y * cols + x] != dst[y * cols + x]) {
printf("(x=%d, y=%d) diff %e\n", x, y, fabs(ref[y * cols + x] - dst[y * cols + x]));
}
}
}
|
This is why OpenCV calls opencv/modules/imgproc/src/distransform.cpp Lines 780 to 784 in 2c1ec42
Origin of the macro is pretty old: 35c7216 |
After #24984 problem remains actual |
@dkurt, a bug to IPP was submitted. |
System Information
OpenCV python version: 4.5.5
Operating System: Ubuntu 16.04
Python version: 3.9.15
Detailed description
I am using cv2.distanceTransform in a deep learning application and have noticed non-deterministic training results in pytorch lightning. After setting manual seeds for all random number generators in my setup, the training was still not deterministic so I decided to have a closer look at the used data. I use cv2.distanceTransform in the ground truth data generation in my training and have noticed variation in the output using the same input.
It's possible to mitigate the problem by rounding the results to one decimal, although this is not the best solution ...
Is there a better way to fix this problem?
Steps to reproduce
Issue submission checklist
The text was updated successfully, but these errors were encountered: