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

TypeError: 'module' object is not callable #723

Closed
marcogallotta opened this issue Apr 15, 2021 · 7 comments
Closed

TypeError: 'module' object is not callable #723

marcogallotta opened this issue Apr 15, 2021 · 7 comments

Comments

@marcogallotta
Copy link

marcogallotta commented Apr 15, 2021

Getting the following error using v0.2 on Ubuntu 20.10 using PyTorch. I was getting the same kind of error in a different line using the latest dev I built yesterday.

All I'm really doing right now is:

self.scattering = Scattering1D(J=8, shape=T, Q=12) 
out = self.scattering.forward(X)

where X is a 2D tensor.

  File "./torch_net.py", line 147, in <module>
    output = net(inputs)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "./torch_net.py", line 26, in forward
    out = self.scattering.forward(X)
  File "/usr/local/lib/python3.8/dist-packages/kymatio/frontend/torch_frontend.py", line 23, in forward
    return self.scattering(x)
  File "/usr/local/lib/python3.8/dist-packages/kymatio/scattering1d/frontend/torch_frontend.py", line 114, in scattering
    S = scattering1d(x, self.backend.pad, self.backend.unpad, self.backend, self.J, self.psi1_f, self.psi2_f, self.phi_f,\
  File "/usr/local/lib/python3.8/dist-packages/kymatio/scattering1d/core/scattering1d.py", line 78, in scattering1d
    U_0_hat = fft(U_0, 'C2C')
  File "/usr/local/lib/python3.8/dist-packages/kymatio/backend/base_backend.py", line 58, in __call__
    return self.fft_forward(x, direction=direction, inverse=inverse)
  File "/usr/local/lib/python3.8/dist-packages/kymatio/backend/base_backend.py", line 53, in fft_forward
    output = self.fft(x)
  File "/usr/local/lib/python3.8/dist-packages/kymatio/scattering1d/backend/torch_backend.py", line 134, in <lambda>
    fft = FFT(lambda x: torch.fft(x, 1, normalized=False),
TypeError: 'module' object is not callable```
@lostanlen lostanlen mentioned this issue Apr 18, 2021
@dminskiy
Copy link

I have the same issue with torch 1.8.1, while it all works fine with torch 1.7.1
torch.fft was depreciated in this version of torch: pytorch/pytorch#42175
Annoyingly, when you try to use new versions of these functions like this:

fft = FFT(lambda x: torch.fft.fft(x, 2, norm='backward'),
          lambda x: torch.fft.ifft(x, 2, norm='backward'),
          lambda x: torch.fft.irfft(x, 2, norm='backward', onesided=False),
          type_checks)

Then you get this error:

  File ".../kymatio/scattering2d/core/scattering2d.py", line 22, in scattering2d
    U_1_c = cdgmm(U_0_c, phi[0])
  File ".../kymatio/backend/torch_backend.py", line 193, in cdgmm
    raise TypeError('Input and filter must be of the same dtype.')
TypeError: Input and filter must be of the same dtype.

This error is caused by the fact that after torch has moved to these updated functions they return torch.complex64 as opposed to previously used torch.float32

My question to authors would be: is there a quick fix to this issue?

@OverLordGoldDragon
Copy link
Collaborator

quick fix

Use master branch, comment out every "sanity check" that breaks code, it should work same. Just ensure input-output behavior of whatever you're changing remains the same (check types etc).

dev has lots of stiching together to do, next release won't happen anytime soon.

@dminskiy
Copy link

@OverLordGoldDragon Thank you for a quick response!
Looks like I was using an old version of the library. It seem to work fine when I updated to a newer release.

@OverLordGoldDragon
Copy link
Collaborator

Fixed in dev, set to merge with master.

@Vin-itall
Copy link

Hey, I have still facing this error. pip install doesn't work, are there any updates?

@OverLordGoldDragon
Copy link
Collaborator

@Vin-itall Please provide the following: 1) minimal code to reproduce the error; 2) output of below script:

import kymatio, os, inspect, importlib

def print_substring_in_dir(backend_dir, s="fft"):
    backend_files = [p.rstrip('.py') for p in os.listdir(backend_dir) 
                     if '__' not in p]
    
    backend_modules = {}
    for f in backend_files:
        try:
            mname = backend_dir.replace('\\', '.').split('kymatio')[-1]
            m = importlib.import_module('kymatio' + mname + '.' + f)
            backend_modules[f] = m
        except:
            pass
    
    print(backend_dir)
    for name, m in backend_modules.items():
        print("\n== {} {}".format(name, "="*80)[:80])
        txt = inspect.getsource(m).split('\n')
        for line in txt:
            if s in line:
                print(line)

print(kymatio.__version__)
_dir = os.path.dirname(os.path.abspath(kymatio.__file__))
print_substring_in_dir(os.path.join(_dir, 'scattering1d', 'backend'))
print_substring_in_dir(os.path.join(_dir, 'backend'))

@Vin-itall
Copy link

Thanks for the quick reply, turns out I was running version 0.2.0. Reinstalled kymatio, it works fine now. Thanks and sorry for any unnecessary inconvenience caused.

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

No branches or pull requests

4 participants