Skip to content

All values come out as 0 while converting int32 to float16 using tf.image.convert_image_dtype  #35450

Closed

Description

@msteknoadam

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes.
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 Version 1903
  • TensorFlow installed from (source or binary): Source (pip install is source I guess?)
  • TensorFlow version (use command below): v1.12.1-21327-gd3457b26a0 2.1.0-dev20191226
  • Python version: 3.7.3
  • GPU model and memory: GeForce 1050Ti / 16GB of RAM

Describe the current behavior
When I convert int32 type of data to float16, all values come out as 0.

Describe the expected behavior
The values should be like "1.0" I believe.

Code to reproduce the issue

>>> x = tf.constant([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]], dtype=tf.int32)
>>> x
<tf.Tensor: shape=(2, 2, 3), dtype=int32, numpy=
array([[[ 1,  2,  3],
        [ 4,  5,  6]],

       [[ 7,  8,  9],
        [10, 11, 12]]])>
>>> tf.image.convert_image_dtype(x, dtype=tf.float16, saturate=False) 
<tf.Tensor: shape=(2, 2, 3), dtype=float16, numpy=
array([[[0., 0., 0.],
        [0., 0., 0.]],

       [[0., 0., 0.],
        [0., 0., 0.]]], dtype=float16)>

Activity

  1. msteknoadam commented on Dec 27, 2019

    @msteknoadam
    ContributorAuthor

    @mihaimaruseac Hello, I created the issue but looks like I can't assign you so I'm just tagging you here.

  2. Lasers67 commented on Dec 28, 2019

    @Lasers67

    In the code:

    scale = 1. / image.dtype.max

    using scale as 1/image.dtype.max which is 1/(max Int32) and multiplying leads to very small values of order 1e-10, float16 cannot handle such large precisions, if you use dtype=float32 in convert_image_dtype the value is not 0 but the actual small value.

  3. msteknoadam commented on Dec 28, 2019

    @msteknoadam
    ContributorAuthor

    Hello, as your comment explains, I think that is some expected thing? But I'm not too sure about this so I'll leave decide to whether to close/not close this issue to @mihaimaruseac

  4. mihaimaruseac commented on Dec 28, 2019

    @mihaimaruseac
    Contributor

    Closing then as it is working as intended.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions