Skip to content

Note and Clarify the Error Raised in tf.raw_ops.ExtractGlimpse() and tf.raw_ops.ExtractGlimpseV2() #100134

@ILCSFNO

Description

@ILCSFNO

Issue type

Documentation Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

binary

TensorFlow version

tf v2.20.0-rc0-4-g72fbba3d20f 2.20.0

Custom code

Yes

OS platform and distribution

Linux Ubuntu 22.04

Mobile device

Linux Ubuntu 22.04

Python version

3.9

Bazel version

None

GCC/compiler version

None

CUDA/cuDNN version

None

GPU model and memory

None

Current behavior?

The doc of tf.raw_ops.ExtractGlimpse() shows its description as below:

attr {
name: "uniform_noise"
description: <<END
indicates if the noise should be generated using a
uniform distribution or a Gaussian distribution.
END
}
attr {
name: "noise"
description: <<END
indicates if the noise should `uniform`, `gaussian`, or
`zero`. The default is `uniform` which means the noise type
will be decided by `uniform_noise`.
END
}

For repro below, I accept that it should error, but:

  • First, the description of the error is not suitable, it shows that "The uniform_noise and noise should not be specified at the same time", but the truth is that "The uniform_noise should not be True when noise is not uniform", for that it will be always specified because of the default value in codes.
    And it will not raise error when uniform_noise is specified to True with noise specified to uniform.

if (uniform_noise && (!noise.empty() && noise != "uniform")) {
return errors::InvalidArgument(
"The uniform_noise and noise should not be specified at the same "
"time");
}

  • Second, it should be note that the behavior above in First will lead to an Error in the docstring of tf.raw_ops.ExtractGlimpse.

  • It also needs to be fixed in tf.raw_ops.ExtractGlimpseV2().

Standalone code to reproduce the issue

import tensorflow as tf

def generate_random_data():
    batch_size = 1
    height = 100
    width = 100
    channels = 3
    input_tensor = tf.random.uniform(shape=[batch_size, height, width, channels], minval=0, maxval=1, dtype=tf.float32, seed=42)
    size = tf.constant([20, 20], dtype=tf.int32)
    offsets = tf.constant([[50, 50]], dtype=tf.float32)
    return (input_tensor, size, offsets)

(input_tensor, size, offsets) = generate_random_data()
glimpse = tf.raw_ops.ExtractGlimpse(input=input_tensor, size=size, offsets=offsets, centered=True, normalized=True, uniform_noise=True, noise='gaussian')
print(glimpse.shape)

Relevant log output

InvalidArgumentError: {{function_node __wrapped__ExtractGlimpse_device_/job:localhost/replica:0/task:0/device:CPU:0}} The uniform_noise and noise could not be specified at the same time [Op:ExtractGlimpse] name:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions