Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unexpected extraporation cropAndResize #8231

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

DameNianch
Copy link

@DameNianch DameNianch commented Apr 3, 2024

As shown in the issue below, when halving the width of a certain image, the corners are filled with black. That's even if the original image width is an even number. We determined that this was due to a rounding error. I made a pull request for the code that reflects the results.
ref: #6624

@DameNianch DameNianch changed the title WIP: fix unexpected extraporation Fix unexpected extraporation Apr 6, 2024
@DameNianch DameNianch changed the title Fix unexpected extraporation Fix unexpected extraporation cropAndResize Apr 6, 2024
Multiplication is performed first to prevent rounding errors as shown in
 the example below.
55/27*27 => 55.00000000000001
Reference: tensorflow#6624
@pyu10055
Copy link
Collaborator

/gcbrun

@pyu10055
Copy link
Collaborator

@DameNianch Thanks for the contribution the test is failing with following errors:

Chrome 120.0.0.0 (Android 10) cropAndResize webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} halving-nearest FAILED
	Error: Arrays differ: actual[27] = -1000, expected[27] = 1.
	Actual:   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1000.
	Expected: 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:10126:15)
	    at expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:10088:12)
	    at ../../tfjs-core/src/ops/image/crop_and_resize_test.ts:47:5 <- tfjs/tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:61153:11
	    at Generator.next ()
	    at fulfilled (tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:59:27)

Chrome 120.0.0.0 (Android 10) cropAndResize webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} halving-nearest FAILED
	Error: Arrays differ: actual[27] = -1000, expected[27] = 1.
	Actual:   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1000.
	Expected: 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:10126:15)
	    at expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:10088:12)
	    at ../../tfjs-core/src/ops/image/crop_and_resize_test.ts:47:5 <- tfjs/tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:61153:11
	    at Generator.next ()
	    at fulfilled (tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:59:27)

Chrome 120.0.0.0 (Android 10) cropAndResize webgl2 {"WEBGL_VERSION":2,"WEBGL_CPU_FORWARD":false,"WEBGL_SIZE_UPLOAD_UNIFORM":0} halving-nearest FAILED
	Error: Arrays differ: actual[27] = -1000, expected[27] = 1.
	Actual:   1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1000.
	Expected: 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1.
	    at expectArraysPredicate (tfjs-core/src/test_util.ts:90:13 <- tfjs/tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:10126:15)
	    at expectArraysClose (tfjs-core/src/test_util.ts:32:10 <- tfjs/tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:10088:12)
	    at ../../tfjs-core/src/ops/image/crop_and_resize_test.ts:47:5 <- tfjs/tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:61153:11
	    at Generator.next ()
	    at fulfilled (tfjs-backend-webgl/src/tfjs-backend-webgl_test_bundle.js:59:27)

Copy link
Member

@mattsoulanille mattsoulanille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mattsoulanille
Copy link
Member

/gcbrun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants