omnipose icon indicating copy to clipboard operation
omnipose copied to clipboard

ImportError: cannot import name 'ifft' from 'scipy'

Open romainGuiet opened this issue 1 year ago • 10 comments

Dear omnipose team,

Thank you for making your tool available for the community!

Following your installation instructions I created a new environment :

mamba create -n omnipose-106 'python==3.10.12' pytorch torchvision pytorch-cuda=11.8 -c pytorch -c nvidia -y
mamba activate omnipose-106
pip install omnipose

and to check the installation I ran: omnipose --help which returns :

Traceback (most recent call last):
  File "D:\conda\conda-envs\omnipose-106\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\conda\conda-envs\omnipose-106\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\conda\conda-envs\omnipose-106\Scripts\omnipose.exe\__main__.py", line 4, in <module>
  File "D:\conda\conda-envs\omnipose-106\lib\site-packages\omnipose\__init__.py", line 1, in <module>
    from . import core, utils, loss, plot, misc, cli, data, gpu
  File "D:\conda\conda-envs\omnipose-106\lib\site-packages\omnipose\misc.py", line 648, in <module>
    import peakdetect
  File "D:\conda\conda-envs\omnipose-106\lib\site-packages\peakdetect\__init__.py", line 3, in <module>
    from .peakdetect import *
  File "D:\conda\conda-envs\omnipose-106\lib\site-packages\peakdetect\peakdetect.py", line 5, in <module>
    from scipy import fft, ifft
ImportError: cannot import name 'ifft' from 'scipy' (D:\conda\conda-envs\omnipose-106\lib\site-packages\scipy\__init__.py)

I tried to pip install scipy but it returns :

Requirement already satisfied: scipy in d:\conda\conda-envs\omnipose-106\lib\site-packages (1.12.0)
Requirement already satisfied: numpy<1.29.0,>=1.22.4 in d:\conda\conda-envs\omnipose-106\lib\site-packages (from scipy) (1.26.3)

Please find below the packages content :

# packages in environment at D:\conda\conda-envs\omnipose-106:
#
# Name                    Version                   Build  Channel
blas                      1.0                         mkl
brotli-python             1.0.9           py310hd77b12b_7
bzip2                     1.0.8                he774522_0
ca-certificates           2023.12.12           haa95532_0
certifi                   2024.2.2        py310haa95532_0
charset-normalizer        2.0.4              pyhd3eb1b0_0
colorama                  0.4.6                    pypi_0    pypi
contourpy                 1.2.0                    pypi_0    pypi
cuda-cccl                 12.3.101                      0    nvidia
cuda-cudart               11.8.89                       0    nvidia
cuda-cudart-dev           11.8.89                       0    nvidia
cuda-cupti                11.8.87                       0    nvidia
cuda-libraries            11.8.0                        0    nvidia
cuda-libraries-dev        11.8.0                        0    nvidia
cuda-nvrtc                11.8.89                       0    nvidia
cuda-nvrtc-dev            11.8.89                       0    nvidia
cuda-nvtx                 11.8.86                       0    nvidia
cuda-profiler-api         12.3.101                      0    nvidia
cuda-runtime              11.8.0                        0    nvidia
cycler                    0.12.1                   pypi_0    pypi
edt                       2.4.0                    pypi_0    pypi
fastremap                 1.14.1                   pypi_0    pypi
filelock                  3.13.1          py310haa95532_0
fonttools                 4.49.0                   pypi_0    pypi
freetype                  2.12.1               ha860e81_0
fsspec                    2024.2.0                 pypi_0    pypi
gmpy2                     2.1.2           py310h7f96b67_0
idna                      3.4             py310haa95532_0
igraph                    0.11.4                   pypi_0    pypi
imageio                   2.34.0                   pypi_0    pypi
intel-openmp              2023.1.0         h59b6b97_46320
jinja2                    3.1.3           py310haa95532_0
joblib                    1.3.2                    pypi_0    pypi
jpeg                      9e                   h2bbff1b_1
kiwisolver                1.4.5                    pypi_0    pypi
lazy-loader               0.3                      pypi_0    pypi
lerc                      3.0                  hd77b12b_0
libcublas                 11.11.3.6                     0    nvidia
libcublas-dev             11.11.3.6                     0    nvidia
libcufft                  10.9.0.58                     0    nvidia
libcufft-dev              10.9.0.58                     0    nvidia
libcurand                 10.3.4.107                    0    nvidia
libcurand-dev             10.3.4.107                    0    nvidia
libcusolver               11.4.1.48                     0    nvidia
libcusolver-dev           11.4.1.48                     0    nvidia
libcusparse               11.7.5.86                     0    nvidia
libcusparse-dev           11.7.5.86                     0    nvidia
libdeflate                1.17                 h2bbff1b_1
libffi                    3.4.4                hd77b12b_0
libjpeg-turbo             2.0.0                h196d8e1_0
libnpp                    11.8.0.86                     0    nvidia
libnpp-dev                11.8.0.86                     0    nvidia
libnvjpeg                 11.9.0.86                     0    nvidia
libnvjpeg-dev             11.9.0.86                     0    nvidia
libpng                    1.6.39               h8cc25b3_0
libtiff                   4.5.1                hd77b12b_0
libuv                     1.44.2               h2bbff1b_0
libwebp-base              1.3.2                h2bbff1b_0
llvmlite                  0.42.0                   pypi_0    pypi
lz4-c                     1.9.4                h2bbff1b_0
mahotas                   1.4.13                   pypi_0    pypi
markupsafe                2.1.3           py310h2bbff1b_0
matplotlib                3.8.3                    pypi_0    pypi
mgen                      1.2.1                    pypi_0    pypi
mkl                       2023.1.0         h6b88ed4_46358
mkl-service               2.4.0           py310h2bbff1b_1
mkl_fft                   1.3.8           py310h2bbff1b_0
mkl_random                1.2.4           py310h59b6b97_0
mpc                       1.1.0                h7edee0f_1
mpfr                      4.0.2                h62dcd97_1
mpir                      3.0.0                hec2e145_1
mpmath                    1.3.0           py310haa95532_0
ncolor                    1.2.1                    pypi_0    pypi
networkx                  3.1             py310haa95532_0
numba                     0.59.0                   pypi_0    pypi
numpy                     1.26.3          py310h055cbcc_0
numpy-base                1.26.3          py310h65a83cf_0
omnipose                  1.0.6                    pypi_0    pypi
opencv-python-headless    4.9.0.80                 pypi_0    pypi
openjpeg                  2.4.0                h4fc8c34_0
openssl                   3.0.13               h2bbff1b_0
packaging                 23.2                     pypi_0    pypi
pandas                    2.2.0                    pypi_0    pypi
pbr                       6.0.0                    pypi_0    pypi
peakdetect                1.2                      pypi_0    pypi
pillow                    10.2.0          py310h2bbff1b_0
pip                       23.3.1          py310haa95532_0
pyparsing                 3.1.1                    pypi_0    pypi
pysocks                   1.7.1           py310haa95532_0
python                    3.10.12              he1021f5_0
python-dateutil           2.8.2                    pypi_0    pypi
pytorch                   2.2.0           py3.10_cuda11.8_cudnn8_0    pytorch
pytorch-cuda              11.8                 h24eeafa_5    pytorch
pytorch-mutex             1.0                        cuda    pytorch
pytz                      2024.1                   pypi_0    pypi
pyyaml                    6.0.1           py310h2bbff1b_0
requests                  2.31.0          py310haa95532_1
scikit-image              0.22.0                   pypi_0    pypi
scikit-learn              1.4.1.post1              pypi_0    pypi
scipy                     1.12.0                   pypi_0    pypi
setuptools                68.2.2          py310haa95532_0
six                       1.16.0                   pypi_0    pypi
sqlite                    3.41.2               h2bbff1b_0
sympy                     1.12            py310haa95532_0
tbb                       2021.8.0             h59b6b97_0
texttable                 1.7.0                    pypi_0    pypi
threadpoolctl             3.3.0                    pypi_0    pypi
tifffile                  2024.2.12                pypi_0    pypi
tk                        8.6.12               h2bbff1b_0
torchvf                   0.1.4                    pypi_0    pypi
torchvision               0.17.0                   pypi_0    pypi
tqdm                      4.66.2                   pypi_0    pypi
typing_extensions         4.9.0           py310haa95532_1
tzdata                    2024.1                   pypi_0    pypi
urllib3                   2.1.0           py310haa95532_1
vc                        14.2                 h21ff451_1
vs2015_runtime            14.27.29016          h5e58377_2
wheel                     0.41.2          py310haa95532_0
win_inet_pton             1.1.0           py310haa95532_0
xz                        5.4.5                h8cc25b3_0
yaml                      0.2.5                he774522_0
zlib                      1.2.13               h8cc25b3_0
zstd                      1.5.5                hd43e919_0

Do you have any recommendations ?

Best regards,

Romain

romainGuiet avatar Feb 19 '24 08:02 romainGuiet

Current workaround suggested by @lacan :

mamba create -n omnipose-106_2 'python==3.9.18' pytorch torchvision pytorch-cuda=11.8 -c pytorch -c nvidia -y
mamba activate omnipose-106_2
git clone https://github.com/kevinjohncutler/omnipose.git
cd omnipose
pip install -e .

But I had to also add : pip install aicsimageio

This install works with GPU support !

Cheers

R

romainGuiet avatar Feb 19 '24 08:02 romainGuiet

and pip install torch_optimizer to use -RAdam

romainGuiet avatar Feb 19 '24 15:02 romainGuiet

Can reproduce the bug.

tinevez avatar Mar 10 '24 09:03 tinevez

Current workaround suggested by @lacan :

The fix also works for me.

tinevez avatar Mar 10 '24 10:03 tinevez

We recently observed an issue when calling omnipose from QuPath on Windows (but it works fine on Linux / WSL) if installation is made with conda/mamba:

mamba create -n omnipose 'python==3.9.18' pytorch torchvision pytorch-cuda=11.8 -c pytorch -c nvidia -y
mamba activate omnipose
pip install git+https://github.com/kevinjohncutler/omnipose.git@bf456e475be4490821f782cb785bbc943bb12abb
pip install aicsimageio torch_optimizer

BUT if installation is done with pip it works fine (but installation is a bit messier)

mamba create -n omnipose python=3.9 -y
mamba activate omnipose
pip install git+https://github.com/kevinjohncutler/omnipose.git@bf456e475be4490821f782cb785bbc943bb12abb
pip uninstall torch torchvision
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
pip install aicsimageio torch_optimizer scikit-image

We documented the issue on our wiki

romainGuiet avatar Mar 11 '24 08:03 romainGuiet

pip install torch_optimizer

I can confirm the bug and the solution. The solution also works with python 3.10.13

JulianoGianlupi avatar Apr 09 '24 17:04 JulianoGianlupi

Thanks Romain it's fixed and work for me too with these little correction for anaconda distribution on windows

conda create -n omnipose 'python==3.9.18' pytorch torchvision pytorch-cuda=11.8 -c pytorch -c nvidia
conda activate omnipose
conda install -c anaconda git
pip install git+https://github.com/kevinjohncutler/omnipose.git@bf456e475be4490821f782cb785bbc943bb12abb
pip uninstall torch torchvision
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
pip install aicsimageio torch_optimizer scikit-image

Nicolas-G-Biologeek avatar Apr 23 '24 14:04 Nicolas-G-Biologeek

Hi everyone, I encountered the same issue. After some investigations, I realized that there are a fft and ifft in scipy but they are in scipy.fft. https://docs.scipy.org/doc/scipy/reference/generated/scipy.fft.fft.html Shouldn't the code be: from scipy.ftt import fft, ifft instead of: from scipy import fft, ifft ?

QuentinRapilly avatar May 24 '24 13:05 QuentinRapilly

Current workaround suggested by @lacan :

mamba create -n omnipose-106_2 'python==3.9.18' pytorch torchvision pytorch-cuda=11.8 -c pytorch -c nvidia -y
mamba activate omnipose-106_2
git clone https://github.com/kevinjohncutler/omnipose.git
cd omnipose
pip install -e .

But I had to also add : pip install aicsimageio

This install works with GPU support !

Cheers

R

Hi everyone,

I tried this method on my iMac with M3 chip and ran Omnipose from my terminal, but got error message as:

pkg_resources.DistributionNotFound: The 'omnipose' distribution was not found and is required by the application

Does anyone know what's going wrong? Thanks a lot!!

MoZhou519 avatar Jun 20 '24 19:06 MoZhou519

Hi, I think @QuentinRapilly has the right idea. Bit it looks like the import code is in the peakdetect package, rather than omnipose. Unfortunately that package doesn't seem to be updated anymore, as far as I can tell.

AWehrhahn avatar Aug 20 '24 20:08 AWehrhahn