I am trying to do wavelet scattering of a 2d image with the following code:
#import torch
from kymatio import Scattering2D
import numpy as np
import PIL
from PIL import Image
FILENAME = "./square.png"
image = PIL.Image.open(FILENAME).convert("L")
a = np.array(image).astype(np.float64)
x = torch.from_numpy(a)
imageSize = x.shape
print( imageSize )
scattering = Scattering2D(J=2, shape=imageSize, frontend='numpy', L=8)
Sx = scattering(x)
print(Sx.size())
and get the following error messages. Can anyone help?
Traceback (most recent call last): File "/Users/pminev/Desktop/scatter2d.py", line 18, in Sx = scattering(x) ^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/kymatio/frontend/torch_frontend.py", line 22, in forward return self.scattering(x) ^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/kymatio/scattering2d/frontend/torch_frontend.py", line 98, in scattering S = scattering2d(input, self.pad, self.unpad, self.backend, self.J, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/kymatio/scattering2d/core/scattering2d.py", line 19, in scattering2d U_1_c = cdgmm(U_0_c, phi['levels'][0]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/kymatio/backend/torch_backend.py", line 192, in cdgmm raise TypeError('Input and filter must be of the same dtype.') TypeError: Input and filter must be of the same dtype.
Trying to do wavelet scattering of of an image.
You could try using the kymatio call to numpy like that. The use of torch seems to be the problem