tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

tf.ClipByValue() does not work as expected for the parameters (0, 1)

Open Melvin-Abraham opened this issue 8 years ago • 14 comments

TensorFlow.js version: 0.10.0

Google Chrome version: 66.0.3359.181

The tf.ClipByValue() function fails to clip the values in a tensor when clipValueMin is set to 0 and clipValueMax is set to 1.

let tensor = tf.range(0, 10)
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

let t_clip = tensor.clipByValue(0, 1)

t_clip.print()
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// Spits out the same tensor without clipping the values

Melvin-Abraham avatar May 19 '18 17:05 Melvin-Abraham

cc @nsthorat @dsmilkov

caisq avatar May 20 '18 02:05 caisq

@reighlan this is a good starter bug!

nsthorat avatar May 20 '18 19:05 nsthorat

Hi @Melvin-Abraham , I couldn't reproduce the error. See this codepen that uses tfjs 0.10.0 and gives correct output.

Can you share more info? Are you running this on a desktop/laptop or a phone? Also, are you running this on the webgl (default) or cpu backend? Thanks!

dsmilkov avatar May 24 '18 18:05 dsmilkov

Well, the issue is there. The values greater than 1 are not clipped to 1. By the way, check this code on Codepen for comparison...

I am using laptop with default settings for tfjs.

Melvin-Abraham avatar May 25 '18 16:05 Melvin-Abraham

The code works fine for me for both webgl and cpu. This seems like an environment issue. Could you also add a screenshot of this page which might help?

manrajgrover avatar May 25 '18 17:05 manrajgrover

Are you using a mac & Safari by chance?

nsthorat avatar May 25 '18 20:05 nsthorat

@nsthorat I'm using Chrome in Windows 10 Pro.

@ManrajGrover I've included the screenshot of the debug page...

screenshot of debug page

This is the codepen screenshot for tf.clipByValue()

screenshot of codepen page

Melvin-Abraham avatar May 28 '18 11:05 Melvin-Abraham

Hi @nsthorat : I'm looking into good first issue labelled issues and seems most of them are done but not concluded to close. We could just check and close the issues which are no longer active/fixed. Ex: This

valishah avatar Jun 10 '18 20:06 valishah

Thanks for the ping. I think this issue should still be open since the user clearly gets the wrong result on Windows. If someone else can reproduce this on a Windows machine that would be great! Thanks!

dsmilkov avatar Jun 13 '18 15:06 dsmilkov

Hi @dsmilkov @Melvin-Abraham I'm using Chrome in Windows 10 Pro. And can't reproduce this issue. image image

DimaRomaniuk avatar Aug 30 '18 06:08 DimaRomaniuk

Thanks for the pointer. So the only difference I could see is that @DimaRomaniuk has WebGL 2.0, while @Melvin-Abraham has WebGL 1.0. I tried forcing WebGL 1.0 via the url flags tfjsflags=WEBGL_VERSION:1, but still couldn't reproduce the error.

Will keep this issue open, until we can get a machine that can reproduce this bug.

dsmilkov avatar Aug 30 '18 21:08 dsmilkov

Hi @dsmilkov @Melvin-Abraham the same result with flag ?tfjsflags=WEBGL_VERSION:1 image image

DimaRomaniuk avatar Sep 17 '18 07:09 DimaRomaniuk

It looks like you are on a very old version of tfjs, can you update to 0.13.0?

nsthorat avatar Sep 17 '18 13:09 nsthorat

Thanks, @nsthorat for pointing the use of old version of tensorflow.js. The issue seems to be solved in tfjs v0.13.0 for me...

tfjs_clip_codepen

Actually, as per my testing, the issue was already solved after the release of tfjs v0.11.7

Melvin-Abraham avatar Sep 17 '18 17:09 Melvin-Abraham