tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

cropAndResize puts 0 padding depending on the shape.

Open DameNianch opened this issue 2 years ago • 2 comments

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): yes
  • OS Platform and Distribution:
    • host: Ubuntu 20.04.4 LTS
    • docker: FROM node:16.13.2-buster-slim
  • TensorFlow.js installed from (npm or script link): npm
  • TensorFlow.js version (use command below):
npm ls
workdir@ /workdir
+-- @tensorflow/[email protected]
`-- @tensorflow/[email protected]

Describe the current behavior Even if the size is reduced, A puts 0 padding depending on the shape. (This ZERO is extrapolationValue.)

Describe the expected behavior Expect not to use extrapolated values when halving the image size.

Standalone code to reproduce the issue

const tf = require('@tensorflow/tfjs');
const tfnode = require('@tensorflow/tfjs-node');
// const tfnodegpu = require('@tensorflow/tfjs-node-gpu');

function doit(aTF, wh) {
    const x = aTF.ones([1, wh * 2, wh * 2, 1])
    const y = aTF.image.cropAndResize(x, [[0, 0, 1, 1]], [0], [wh, wh], "bilinear", 0.18782)
    console.log(wh, y.min().arraySync())
}

for (let i = 2; i < 130; i++) {
    doit(tf, i)
    doit(tfnode, i)
    // doit(tfnodegpu, wh)
}

Other info / logs

results
/workdir# node script/tfDebug.js 
2022-07-14 15:34:58.417548: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2 1
2 1
3 1
3 1
4 1
4 1
5 1
5 1
6 1
6 1
7 1
7 1
8 1
8 1
9 1
9 1
10 1
10 1
11 1
11 1
12 1
12 1
13 1
13 1
14 1
14 1
15 1
15 1
16 1
16 1
17 1
17 1
18 1
18 1
19 1
19 1
20 1
20 1
21 1
21 1
22 1
22 1
23 1
23 1
24 1
24 1
25 1
25 1
26 1
26 1
27 1
27 1
28 0.18782000243663788
28 0.18782000243663788
29 0.18782000243663788
29 0.18782000243663788
30 1
30 1
31 1
31 1
32 1
32 1
33 1
33 1
34 1
34 1
35 1
35 1
36 1
36 1
37 1
37 1
38 1
38 1
39 1
39 1
40 1
40 1
41 1
41 1
42 1
42 1
43 1
43 1
44 1
44 1
45 1
45 1
46 1
46 1
47 0.18782000243663788
47 0.18782000243663788
48 0.18782000243663788
48 0.18782000243663788
49 1
49 1
50 1
50 1
51 1
51 1
52 1
52 1
53 1
53 1
54 1
54 1
55 1
55 1
56 1
56 1
57 1
57 1
58 1
58 1
59 0.18782000243663788
59 0.18782000243663788
60 1
60 1
61 1
61 1
62 1
62 1
63 1
63 1
64 1
64 1
65 1
65 1
66 1
66 1
67 1
67 1
68 1
68 1
69 1
69 1
70 1
70 1
71 1
71 1
72 1
72 1
73 1
73 1
74 1
74 1
75 1
75 1
76 1
76 1
77 1
77 1
78 1
78 1
79 1
79 1
80 1
80 1
81 1
81 1
82 0.18782000243663788
82 0.18782000243663788
83 1
83 1
84 1
84 1
85 1
85 1
86 1
86 1
87 1
87 1
88 1
88 1
89 0.18782000243663788
89 0.18782000243663788
90 1
90 1
91 1
91 1
92 1
92 1
93 1
93 1
94 1
94 1
95 1
95 1
96 0.18782000243663788
96 0.18782000243663788
97 1
97 1
98 1
98 1
99 1
99 1
100 1
100 1
101 1
101 1
102 1
102 1
103 0.18782000243663788
103 0.18782000243663788
104 1
104 1
105 1
105 1
106 1
106 1
107 1
107 1
108 1
108 1
109 1
109 1
110 1
110 1
111 1
111 1
112 0.18782000243663788
112 0.18782000243663788
113 1
113 1
114 1
114 1
115 1
115 1
116 1
116 1
117 1
117 1
118 1
118 1
119 1
119 1
120 1
120 1
121 0.18782000243663788
121 0.18782000243663788
122 0.18782000243663788
122 0.18782000243663788
123 0.18782000243663788
123 0.18782000243663788
124 1
124 1
125 1
125 1
126 1
126 1
127 1
127 1
128 1
128 1
129 1
129 1

DameNianch avatar Jul 14 '22 15:07 DameNianch

For node bindings, you need setBackend('node'). (See https://js.tensorflow.org/api/latest/#setBackend).

rthadur avatar Jul 14 '22 18:07 rthadur

@rthadur Thank you for your reply. Let me ask you two questions.

  1. I'm sorry, but I don't understand why you made that point. Could you please tell me why I should do this?
  2. setBackend('node') say Error: Backend name 'node' not found in registry. setBackend("cpu") is bad idea for this problem. The documentation says cpu, webgl, wasm, etc, but does etc include node?

DameNianch avatar Jul 15 '22 08:07 DameNianch

Hi, @DameNianch

Thank you for opening this issue. Since this issue has been open for a long time, the code/debug information for this issue may not be relevant with the current state of the code base.

The TFJs team is constantly improving the framework by fixing bugs and adding new features. We suggest you try the latest TFJs version with the latest compatible hardware configuration which could potentially resolve the issue. If you are still facing the issue, please create a new GitHub issue with your latest findings, with all the debugging information which could help us investigate.

Please follow the release notes to stay up to date with the latest developments which are happening in the Tensorflow.js space.

Thank you for your support and cooperation.

gaikwadrahul8 avatar Sep 03 '23 22:09 gaikwadrahul8

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar Sep 11 '23 01:09 github-actions[bot]

This issue was closed due to lack of activity after being marked stale for past 7 days.

github-actions[bot] avatar Sep 19 '23 01:09 github-actions[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Sep 19 '23 01:09 google-ml-butler[bot]

Can someone please tell me if this test case is wrong? https://github.com/tensorflow/tfjs/pull/8231/commits/99ac8959650ea4091cb13b960f186643cc0465ec I'd like to clarify whether I just don't understand the behavior of nearest, or whether it's weird that the extrapolated value is referenced. If the reference to the extrapolated value is incorrect, I am willing to correct it myself.

DameNianch avatar Apr 03 '24 16:04 DameNianch

@gaikwadrahul8 @jinjingforever Could you please answer this question?

Can someone please tell me if this test case is wrong? 99ac895 I'd like to clarify whether I just don't understand the behavior of nearest, or whether it's weird that the extrapolated value is referenced. If the reference to the extrapolated value is incorrect, I am willing to correct it myself.

DameNianch avatar Apr 04 '24 06:04 DameNianch