Skip to content
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

Race condition in ObjectMorphology filters #4588

Open
makarovNick opened this issue Apr 15, 2024 · 2 comments
Open

Race condition in ObjectMorphology filters #4588

makarovNick opened this issue Apr 15, 2024 · 2 comments
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Comments

@makarovNick
Copy link

GlobalDefaultNumberOfThreads affects result
Applying ErodeObjectMorphologyImageFilter on binary image produces different result with
GlobalDefaultNumberOfThreads > 1

To Reproduce
Steps to reproduce the behavior:

  1. Operating system, version, and architecture
  • OS: [Ubuntu 18.4]
    Architecture: x86_64
    CPU(s): 16
  1. Programming language: Python 3.9.14]

  2. Version of SimpleITK:
    tested on 2.1.0, 2.2.0, 2.3.1

  3. How was SimpleITK installed?

  • binary distribution [e.g. python -m pip install SimpleITK]
  1. A minimal working example which causes the error.
    data - shape.zip
import SimpleITK as sitk
img = sitk.ReadImage("shape.nrrd")

sitk.ProcessObject.SetGlobalDefaultNumberOfThreads(1)
eroded_img = sitk.ErodeObjectMorphology(img)
result_volume = sitk.GetArrayFromImage(eroded_img).sum()
print("Expecting volume: ", result_volume)

sitk.ProcessObject.SetGlobalDefaultNumberOfThreads(16)
for _ in range(10):
    eroded_img = sitk.ErodeObjectMorphology(img)
    volume = sitk.GetArrayFromImage(eroded_img).sum()
    if result_volume != volume:
        print("Wrong result! Got", volume)

Got:

Expecting volume:  6039
Wrong result! Got 6213
Wrong result! Got 6109
Wrong result! Got 6046
Wrong result! Got 6119
Wrong result! Got 6212
Wrong result! Got 6042
Wrong result! Got 6183
Wrong result! Got 6212
Wrong result! Got 6044

Expected behavior
Expecting eroded image to be the same

Came here from SimpleITK issue as @blowekamp advised

@makarovNick makarovNick added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label Apr 15, 2024
Copy link

Thank you for contributing an issue! 🙏

Welcome to the ITK community! 🤗👋☀️

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜
Also, please check existing open issues and consider discussion on the ITK Discourse. 📖

This is an automatic message. Allow for time for the ITK community to be able to read the issue and comment on it.

@blowekamp
Copy link
Member

blowekamp commented Apr 17, 2024

edited Not clear to me what the race conditions are causing the varying results after my initial investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
Development

No branches or pull requests

2 participants