You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tf.image.convert_image_dtype behaves incorrectly on Windows (but fine on MacOS) #60078
On Mac it returns tf.Tensor(4294967295, shape=(), dtype=uint32)
On windows, tf.Tensor(0, shape=(), dtype=uint32).
It seems that Mac has the correct result - you expect the result to saturate to the max uint32 value of 2**32-1==4294967295 when the float-input is >=1 - but it actually jumps back down to zero. This caused a very sneaky bug in my code which caused the detection system to fail to detect in some cases.
Thanks for looking into it @sushreebarsa and thanks @DEKHTIARJonathan for responding. I never tried with GPU. Other possibly relevant info - the Mac in question (which provides the correct, continuous version convert_image_dtype) is an M1 Mac.
The issue has been fixed in tf-nightly(2.14.0-dev20230503).Please refer to attached gist.
But there is one point to note here. Images that are represented using floating point values are expected to have values in the range [0,1).If you are using floats outside this range you need to set saturate=True in the API.
Since floating point inputs to integer types may lead to over/underflow problems. Set saturate to True to avoid such problem in problematic conversions. If enabled, saturation will clip the output into the allowed range before performing a potentially dangerous cast. The same is documented now and you can refer the API Doc source for more explanation.
Activity
sushreebarsa commentedon Mar 23, 2023
@petered Thank you for reporting an issue!
Could you please provide a complete standalone code to replicate this issue?
Thank you!
DEKHTIARJonathan commentedon Mar 23, 2023
Out of curiosity. Do you know if it changes anything with/without GPU?
@sushreebarsa this should be enough for you to reproduce ...
petered commentedon Mar 23, 2023
Thanks for looking into it @sushreebarsa and thanks @DEKHTIARJonathan for responding. I never tried with GPU. Other possibly relevant info - the Mac in question (which provides the correct, continuous version
convert_image_dtype) is an M1 Mac.sushreebarsa commentedon Mar 28, 2023
@petered Could you please let us know the exact command you have used to install tensorflow here, it would help us to analyze the issue. Thank you!
petered commentedon Mar 28, 2023
I believe it was just
pip install tensorflowthough I don't have the command-history available at the moment. Are you not able to reproduce it?5 remaining items
github-actions commentedon Apr 26, 2023
This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.
petered commentedon Apr 26, 2023
SuryanarayanaY commentedon May 4, 2023
Hi @petered ,
The issue has been fixed in tf-nightly(2.14.0-dev20230503).Please refer to attached gist.
But there is one point to note here. Images that are represented using floating point values are expected to have values in the range [0,1).If you are using floats outside this range you need to set
saturate=Truein the API.Since floating point inputs to integer types may lead to over/underflow problems. Set saturate to True to avoid such problem in problematic conversions. If enabled, saturation will clip the output into the allowed range before performing a potentially dangerous cast. The same is documented now and you can refer the API Doc source for more explanation.
Thank you!
petered commentedon May 4, 2023
SuryanarayanaY commentedon May 8, 2023
Hi @petered ,
Could you please spare some time to close the issue as it resolved already. Thanks!
google-ml-butler commentedon May 8, 2023
Are you satisfied with the resolution of your issue?
Yes
No