Skip to content

tf.image.convert_image_dtype behaves incorrectly on Windows (but fine on MacOS) #60078

Closed

Description

@petered
Click to expand!

Issue Type

Bug

Have you reproduced the bug with TF nightly?

No

Source

source

Tensorflow Version

2.9.1

Custom Code

No

OS Platform and Distribution

Windows

Mobile device

No response

Python version

3.10

Current Behaviour?

Compare the result of the line

tf.image.convert_image_dtype(1., tf.uint32)

Between MacOS and Windows.

  • 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.

Standalone code to reproduce the issue

assert int(tf.image.convert_image_dtype(1., tf.uint32))==2**32-1

Relevant log output

No response

Activity

  1. added
    comp:ops
    TF 2.9
    on Mar 23, 2023
  2. sushreebarsa commented on Mar 23, 2023

    @sushreebarsa
    Contributor

    @petered Thank you for reporting an issue!
    Could you please provide a complete standalone code to replicate this issue?
    Thank you!

  3. added
    stat:awaiting response
    on Mar 23, 2023
  4. DEKHTIARJonathan commented on Mar 23, 2023

    @DEKHTIARJonathan
    Contributor

    Out of curiosity. Do you know if it changes anything with/without GPU?

    @sushreebarsa this should be enough for you to reproduce ...

    import tensorflow as tf
    assert int(tf.image.convert_image_dtype(1., tf.uint32))==2**32-1
  5. petered commented on Mar 23, 2023

    @petered
    Author

    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.

  6. removed
    stat:awaiting response
    on Mar 23, 2023
  7. sushreebarsa commented on Mar 28, 2023

    @sushreebarsa
    Contributor

    @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!

  8. added
    stat:awaiting response
    on Mar 28, 2023
  9. petered commented on Mar 28, 2023

    @petered
    Author

    I believe it was just pip install tensorflow though I don't have the command-history available at the moment. Are you not able to reproduce it?

  10. removed
    stat:awaiting response
    on Mar 28, 2023
  11. 5 remaining items

  12. added
    stat:awaiting response
    on Apr 18, 2023
  13. github-actions commented on Apr 26, 2023

    @github-actions

    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.

  14. added
    stale
    on Apr 26, 2023
  15. petered commented on Apr 26, 2023

    @petered
    Author
  16. removed
    stale
    stat:awaiting response
    on Apr 26, 2023
  17. added
    comp:gpu
    on May 4, 2023
  18. SuryanarayanaY commented on May 4, 2023

    @SuryanarayanaY
    Collaborator

    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=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.

    Thank you!

  19. added
    stat:awaiting response
    on May 4, 2023
  20. petered commented on May 4, 2023

    @petered
    Author
  21. removed
    stat:awaiting response
    on May 4, 2023
  22. SuryanarayanaY commented on May 8, 2023

    @SuryanarayanaY
    Collaborator

    Hi @petered ,

    Could you please spare some time to close the issue as it resolved already. Thanks!

  23. added
    stat:awaiting response
    on May 8, 2023
  24. google-ml-butler commented on May 8, 2023

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

TF 2.9comp:gpucomp:opsstat:awaiting responsetype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions