Invalid output of tf.image.transform
operation when outputShape
is different from input image shape (on cpu and wasm backends)
#6657
Labels
type:bug
Something isn't working
System information
Describe the current behavior
There is a bug in the implementation of the tf.image.transform operation in the cpu and wasm backends.
The problem manifests itself when we want to get the output of the operation with a shape other than the shape of the input image (using the
outputShape
parameter).For example, using an input image of 256x256 and the
outputShape
set to [512,512], we get the following results:webgl-backend
(correct output):cpu-backend/wasm-backend
(incorrect output):The problem also occurs when
outputShape
is smaller than the shape of the input image, for example, using 256x256 input image and settingoutputShape
to [96,96] we get the following results:webgl-backend
- correct output, as abovecpu-backend
- incorrect output:wasm-backend
-RuntimeError: memory access out of bounds
Describe the expected behavior
tf.image.transform
operation works correctly regardless of theoutputShape
.Standalone code to reproduce the issue
Snippet to reproduce:
Such a call causes a RuntimeError:
Other info / logs
I debugged this operation and found the source of the problem.
The error is related to the indexing of the output. The memory for the output tensor is allocated according to the
outputShape
, but when writing values to it - the strides values calculated for the input image (instead of the output size) are used to calculate the index:rowStride
andcolStride
values are incorrect here, which results in the output as in the examples above (and in the case of theoutputShape
smaller than the input shape - it even refers to the out of bounds memory).The problematic code is here:
The text was updated successfully, but these errors were encountered: