question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scattering 2D doesn't work when using 2^J == image size (TensorFlow backend)

See original GitHub issue

Similar issues have been reported before (#284, #363) and also fixed (#412) for Torch backend. However, still not working in the tensorflow backend:

test:

import numpy as np
from kymatio.tensorflow import Scattering2D

scattering = Scattering2D(J=5, shape=(32, 32))
test_im = np.ones((1,1,32,32))
test = scattering.scattering(test_im)

Gives error:

      7 scattering = Scattering2D(J=5, shape=(32, 32))
      8 test_im = np.ones((1,1,32,32))
----> 9 test = scattering.scattering(test_im)

~/.local/lib/python3.9/site-packages/kymatio/scattering2d/frontend/tensorflow_frontend.py in scattering(self, input)
     48             input = tf.reshape(input, tf.concat(((-1,), signal_shape), 0))
     49 
---> 50             S = scattering2d(input, self.pad, self.unpad, self.backend, self.J, self.L, self.phi, self.psi,
     51                              self.max_order, self.out_type)
     52 

~/.local/lib/python3.9/site-packages/kymatio/scattering2d/core/scattering2d.py in scattering2d(x, pad, unpad, backend, J, L, phi, psi, max_order, out_type)
     13     out_S_0, out_S_1, out_S_2 = [], [], []
     14 
---> 15     U_r = pad(x)
     16 
     17     U_0_c = fft(U_r, 'C2C')

~/.local/lib/python3.9/site-packages/kymatio/scattering2d/backend/tensorflow_backend.py in __call__(self, x)
     27         paddings = [[0, 0]] * len(x.shape[:-2])
     28         paddings += [[self.pad_size[0], self.pad_size[1]], [self.pad_size[2], self.pad_size[3]]]
---> 29         return tf.cast(tf.pad(x, paddings, mode="REFLECT"), tf.complex64)
     30 
     31 def unpad(in_):

~/.local/lib/python3.9/site-packages/tensorflow/python/util/traceback_utils.py in error_handler(*args, **kwargs)
    151     except Exception as e:
    152       filtered_tb = _process_traceback_frames(e.__traceback__)
--> 153       raise e.with_traceback(filtered_tb) from None
    154     finally:
    155       del filtered_tb

~/.local/lib/python3.9/site-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     56   try:
     57     ctx.ensure_initialized()
---> 58     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
     59                                         inputs, attrs, num_outputs)
     60   except core._NotOkStatusException as e:

InvalidArgumentError: paddings must be less than the dimension size: 32, 32 not less than 32 [Op:MirrorPad]

(speculation) So possibly problems with the order of the padding being different in tensorflow from torch.

Should also probably include some tests for these types of problems like the tests for implemented for Torch in #346

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
MatthijsMarscommented, May 31, 2022

Ah yes you are completely right, I’m only working with square images so that’s why it doesn’t matter too much but might cause some trouble when not doing that. Thanks for pointing it out. ( I’ll edit the comment above for if someone ends up copying something from here)

0reactions
jandencommented, Jun 20, 2022

So what’s the status on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

tf.scatter_nd | TensorFlow v2.11.0
Scatter sparse updates according to individual values at the specified indices . This op returns an output tensor with the shape you specify ......
Read more >
kymatio 0.3.0 documentation
This class implements solid harmonic scattering on a 3D input image. ... If max_order is 2 it returns an np.ndarray with the first-...
Read more >
Kymatio: Wavelet scattering in Python - GitHub
Use Kymatio if you need a library that: supports 1-D, 2-D, and 3-D wavelets,; integrates wavelet scattering in a deep learning architecture, and;...
Read more >
Realtime Multiple Person 2D Pose Estimation using ...
resize=432x368 (size of the image at pre-processing); image=./images/ski.jpg (sample image inside images directory). python run.py --model= ...
Read more >
100-line Tensorflow code and Keras equivalent do not produce the ...
The following 2 python programs compile and run out-of-the-box, and produce exactly the same result. However, the TF version does not converge properly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found