libffcv / ffcv

FFCV: Fast Forward Computer Vision (and other ML workloads!)
https://ffcv.io
Apache License 2.0
2.79k stars 180 forks source link

Import error - libopencv_impgproc missing #346

Open GooseIt opened 10 months ago

GooseIt commented 10 months ago

I've installed ffcv library and I get the following error on line import ffcv:


    import ffcv
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/__init__.py", line 1, in <module>
    from .loader import Loader
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/loader/__init__.py", line 1, in <module>
    from .loader import Loader, OrderOption
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/loader/loader.py", line 14, in <module>
    from ffcv.fields.base import Field
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/fields/__init__.py", line 1, in <module>
    from .base import Field
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/fields/base.py", line 6, in <module>
    from ..pipeline.operation import Operation
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/pipeline/__init__.py", line 2, in <module>
    from .pipeline_spec import PipelineSpec
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/pipeline/pipeline_spec.py", line 5, in <module>
    from ..transforms.module import ModuleWrapper
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/transforms/__init__.py", line 5, in <module>
    from .random_resized_crop import RandomResizedCrop
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/transforms/random_resized_crop.py", line 5, in <module>
    from .utils import fast_crop
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/transforms/utils/fast_crop.py", line 4, in <module>
    from ...libffcv import ctypes_resize
  File "/home/vlad/anaconda3/envs/ffcv/lib/python3.9/site-packages/ffcv/libffcv.py", line 6, in <module>
    import ffcv._libffcv
ImportError: libopencv_imgproc.so.408: cannot open shared object file: No such file or directory

I've tried running conda remove opencv && conda install opencv and pip install -U ffcv.

I've also tried solutions suggested here - https://github.com/libffcv/ffcv/issues/329#issuecomment-1634407591.

Nothing changed. Please help fixing the issue.

It seems there was an issue like mine - https://github.com/libffcv/ffcv/issues/136. However, it was solved by Slack in February 2022, and ffcv Slack server does not hold messages more than 90 days of age. If you know which solution worked there, I'm happy to hear it.

andrewilyas commented 10 months ago

Hi @GooseIt ! Can you try instaling opencv 4.5.2 instead of the latest version?

SerezD commented 5 months ago

Hi there,

@GooseIt did you manage to solve the issue?

I was able to solve it by installing numba==0.56.2.

Here is my full environment.yaml file:

name: torch-ffcv
channels:
  - pytorch
  - nvidia
  - conda-forge
dependencies:
  - pytorch
  - torchvision
  - torchaudio
  - pytorch-cuda==12.1
  - cupy
  - pkg-config
  - libjpeg-turbo>=2.1.4
  - opencv
  - numba==0.56.2
  - pip
  - pip:
      - tqdm
      - ffcv

@andrewilyas I also tried with opencv==4.5.2 but it did not work. Do you have any clues on what is causing the error ?

Thank you

richardrl commented 2 months ago

I am running into this issue today with latest build: ImportError: libopencv_imgproc.so.407: cannot open shared object file: No such file or directory

arnaghosh commented 1 month ago

I am running into this issue as well. Degrading opencv or numba versions did not help solve the issue. Side note: Degrading numba to 0.56.2 also degraded pytorch version to 1.12. Does that happen to you as well @SerezD?

Any suggestions for fix @andrewilyas? Thanks in advance.

SerezD commented 1 month ago

Degrading opencv or numba versions did not help solve the issue. Side note: Degrading numba to 0.56.2 also degraded pytorch version to 1.12. Does that happen to you as well @SerezD?

Hi @arnaghosh. No, it does not happen in my case. Note that I install the previously posted environment from conda as:

conda env create -f environment.yaml

using libmamba for faster solving: https://www.anaconda.com/blog/a-faster-conda-for-a-growing-community

I tried installing the environment on different machines and it always worked for me. Unfortunately, I still have no idea about the cause of the error, so I can't help on that.

arnaghosh commented 1 month ago

Hi @SerezD,

Thank you so much. Can I ask you which pytorch version you are using? I was hoping to use pytorch 2.1.2. Just wondering if the pytorch version conflicts with the numba version.

SerezD commented 1 month ago

Hi @SerezD,

Thank you so much. Can I ask you which pytorch version you are using? I was hoping to use pytorch 2.1.2. Just wondering if the pytorch version conflicts with the numba version.

Without further indications in the environment file, it will attempt to install the latest version of pytorch. For example, in one of my local environments it installed pytorch 2.2.0 and numba 0.56.2.

arnaghosh commented 1 month ago

Thanks again @SerezD. I tried installing my env from scratch, and this time it did not degrade pytorch (as you predicted). However, importing ffcv still doesn't work, i.e. I still get the same error: ImportError: libopencv_imgproc.so.407: cannot open shared object file: No such file or directory

arnaghosh commented 1 month ago

Update: The solution proposed by @SerezD worked for me! 🎉 Thanks a lot! I was using a cached version of ffcv. Using pip install ffcv --no-cache-dir in worked! :)

These are the steps that worked for me, in case anyone else finds this list helpful:

conda create --prefix <env_location>/<env_name> -y python=3.9 conda conda-libmamba-solver -c conda-forge
conda activate <env_location>/<env_name>

export CONDA_EXE="$(hash -r; which conda)"
conda config --set solver libmamba
conda config --set channel_priority flexible

conda install -y cupy pkg-config compilers libjpeg-turbo opencv pytorch=2.1.2 torchvision=0.16.2 pytorch-cuda=12.1 torchmetrics numba=0.56.2 terminaltables matplotlib scikit-learn pandas assertpy pytz -c pytorch -c nvidia -c conda-forge

pip install ffcv --no-cache-dir