dwojtasik / PyHook

Python hook for ReShade processing
MIT License
30 stars 4 forks source link

Error: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation. #2

Closed suphamster closed 1 year ago

suphamster commented 1 year ago
PyHook v1.3.0 (c) 2022 by Dominik Wojtasik
- Loading pipelines...
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\ai_cartoon_gan.py".
-- Cannot load pipeline file "D:\PyHook-1.3.0-win_amd64\pipelines\ai_cartoon_gan.py".
--- Error: OpenCV loader: missing configuration file: ['config-3.10.py', 'config-3.py']. Check OpenCV installation.
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\ai_colorization.py".
['C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\base_library.zip', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\lib-dynload', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842', 'C:\\OpenCV', 'G:\\anaconda3\\envs\\opencv_build\\Lib', 'G:\\anaconda3\\envs\\opencv_build\\DLLs', 'G:\\anaconda3\\envs\\opencv_build', 'G:\\anaconda3\\envs\\opencv_build\\Lib\\site-packages']
-- Cannot load pipeline file "D:\PyHook-1.3.0-win_amd64\pipelines\ai_colorization.py".
--- Error: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\ai_depth_estimation.py".
['C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\base_library.zip', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\lib-dynload', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842', 'C:\\OpenCV', 'G:\\anaconda3\\envs\\opencv_build\\Lib', 'G:\\anaconda3\\envs\\opencv_build\\DLLs', 'G:\\anaconda3\\envs\\opencv_build', 'G:\\anaconda3\\envs\\opencv_build\\Lib\\site-packages']
-- Cannot load pipeline file "D:\PyHook-1.3.0-win_amd64\pipelines\ai_depth_estimation.py".
--- Error: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\ai_dnn_super_resolution.py".
['C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\base_library.zip', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\lib-dynload', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842', 'C:\\OpenCV', 'G:\\anaconda3\\envs\\opencv_build\\Lib', 'G:\\anaconda3\\envs\\opencv_build\\DLLs', 'G:\\anaconda3\\envs\\opencv_build', 'G:\\anaconda3\\envs\\opencv_build\\Lib\\site-packages']
-- Cannot load pipeline file "D:\PyHook-1.3.0-win_amd64\pipelines\ai_dnn_super_resolution.py".
--- Error: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\ai_multi_style_transfer.py".
['C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\base_library.zip', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\lib-dynload', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842', 'C:\\OpenCV', 'G:\\anaconda3\\envs\\opencv_build\\Lib', 'G:\\anaconda3\\envs\\opencv_build\\DLLs', 'G:\\anaconda3\\envs\\opencv_build', 'G:\\anaconda3\\envs\\opencv_build\\Lib\\site-packages']
-- Cannot load pipeline file "D:\PyHook-1.3.0-win_amd64\pipelines\ai_multi_style_transfer.py".
--- Error: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\ai_object_detection.py".
['C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\base_library.zip', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\lib-dynload', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842', 'C:\\OpenCV', 'G:\\anaconda3\\envs\\opencv_build\\Lib', 'G:\\anaconda3\\envs\\opencv_build\\DLLs', 'G:\\anaconda3\\envs\\opencv_build', 'G:\\anaconda3\\envs\\opencv_build\\Lib\\site-packages']
-- Cannot load pipeline file "D:\PyHook-1.3.0-win_amd64\pipelines\ai_object_detection.py".
--- Error: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\ai_semantic_segmentation.py".
['C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\base_library.zip', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\lib-dynload', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842', 'C:\\OpenCV', 'G:\\anaconda3\\envs\\opencv_build\\Lib', 'G:\\anaconda3\\envs\\opencv_build\\DLLs', 'G:\\anaconda3\\envs\\opencv_build', 'G:\\anaconda3\\envs\\opencv_build\\Lib\\site-packages']
-- Cannot load pipeline file "D:\PyHook-1.3.0-win_amd64\pipelines\ai_semantic_segmentation.py".
--- Error: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\ai_style_transfer.py".
['C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\base_library.zip', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\lib-dynload', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842', 'C:\\OpenCV', 'G:\\anaconda3\\envs\\opencv_build\\Lib', 'G:\\anaconda3\\envs\\opencv_build\\DLLs', 'G:\\anaconda3\\envs\\opencv_build', 'G:\\anaconda3\\envs\\opencv_build\\Lib\\site-packages']
-- Cannot load pipeline file "D:\PyHook-1.3.0-win_amd64\pipelines\ai_style_transfer.py".
--- Error: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\cv2_sharpen.py".
['C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\base_library.zip', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\lib-dynload', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842', 'C:\\OpenCV', 'G:\\anaconda3\\envs\\opencv_build\\Lib', 'G:\\anaconda3\\envs\\opencv_build\\DLLs', 'G:\\anaconda3\\envs\\opencv_build', 'G:\\anaconda3\\envs\\opencv_build\\Lib\\site-packages']
-- Cannot load pipeline file "D:\PyHook-1.3.0-win_amd64\pipelines\cv2_sharpen.py".
--- Error: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\test_rgb.py".
-- Loading pipeline: "D:\PyHook-1.3.0-win_amd64\pipelines\test_static_img.py".
['C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\base_library.zip', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842\\lib-dynload', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\_MEI152842', 'C:\\OpenCV', 'G:\\anaconda3\\envs\\opencv_build\\Lib', 'G:\\anaconda3\\envs\\opencv_build\\DLLs', 'G:\\anaconda3\\envs\\opencv_build', 'G:\\anaconda3\\envs\\opencv_build\\Lib\\site-packages']
-- Cannot load pipeline file "D:\PyHook-1.3.0-win_amd64\pipelines\test_static_img.py".
--- Error: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
- Searching for process with ReShade...
-- Selected process: Game.exe [PID=1468, 64bit] with ReShade v5.7.0 @ G:\Game\opengl32.dll
- Started addon injection for C:\Users\Admin\AppData\Local\Temp\_MEI152842\PyHook.addon...
-- Addon injected!
- Loading PyHook configuration if exists...
- Writing configuration to addon...
- Started processing...

Is it because of Python 3.11? It's not like I had abilty to choose Python version when following OpenCV+CUDA installation guide posted here. LOCAL_PYTHON_64 = G:\anaconda3\envs\opencv_build\python.exe. Anacoda's installed Python:

(base) C:\Users\Admin>python -V
Python 3.9.16
(base) C:\Users\Serg>G:\anaconda3\envs\opencv_build\python.exe
Python 3.11.0 | packaged by conda-forge | (main, Oct 25 2022, 06:12:32) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.cuda.getCudaEnabledDeviceCount())
1
>>> print(cv2.getBuildInformation())

General configuration for OpenCV 4.6.0 =====================================
  Version control:               4.6.0

  Extra modules:
    Location (extra):            C:/CV2/opencv_contrib/modules
    Version control (extra):     4.6.0

  Platform:
    Timestamp:                   2023-03-16T09:47:13Z
    Host:                        Windows 10.0.19045 AMD64
    CMake:                       3.26.0
    CMake generator:             Visual Studio 16 2019
    CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/MSBuild.exe
    MSVC:                        1929
    Configuration:               Debug Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (18 files):         + SSSE3 SSE4_1
      SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (33 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe  (ver 19.29.30146.0)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MD /O2 /Ob2 /DNDEBUG
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MDd /Zi /Ob0 /Od /RTC1
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP   /MD /O2 /Ob2 /DNDEBUG
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP /MDd /Zi /Ob0 /Od /RTC1
    Linker flags (Release):      /machine:x64  /INCREMENTAL:NO
    Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cudnn.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.0/lib/x64
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 alphamat cvv freetype java julia matlab ovis python2 sfm viz
    Applications:                tests perf_tests apps
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI:                           WIN32UI
    Win32 UI:                    YES
    VTK support:                 NO

  Media I/O:
    ZLib:                        build (ver 1.2.12)
    JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                YES (4.0.0)
    GStreamer:                   YES (1.22.0)
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      YES

  Parallel framework:            Concurrency

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   C:/CV2/opencv/build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                C:/CV2/opencv/build/3rdparty/ippicv/ippicv_win/iw
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.19.1)

  NVIDIA CUDA:                   YES (ver 11.0, CUFFT CUBLAS)
    NVIDIA GPU arch:             35 37 50 52 60 61 70 75 80
    NVIDIA PTX archs:

  cuDNN:                         YES (ver 8.0.5)

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/CV2/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 G:/anaconda3/envs/opencv_build/python.exe (ver 3.11)
    Libraries:                   G:/anaconda3/envs/opencv_build/libs/python3 (ver 3.11.0)
    numpy:                       G:/anaconda3/envs/opencv_build/Lib/site-packages/numpy/core/include (ver 1.24.2)
    install path:                G:/anaconda3/envs/opencv_build/Lib/site-packages/cv2/python-3.11

  Python (for build):            G:/anaconda3/envs/opencv_build/python.exe

  Java:
    ant:                         NO
    JNI:                         C:/Program Files/Java/jdk-17/include C:/Program Files/Java/jdk-17/include/win32 C:/Program Files/Java/jdk-17/include
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    C:/CV2/OpenCV-4.6.0
-----------------------------------------------------------------
suphamster commented 1 year ago

CPU version also not works very well:

-- Addon injected!
- Loading PyHook configuration if exists...
- Writing configuration to addon...
- Started processing...
Pipeline="[AI] DNN Super Resolution" was loaded with CPU support.
-- ERROR: Frame modification detected for multistage processing in frame=960! Frame skipped...
-- ERROR: Frame modification detected for multistage processing in frame=961! Frame skipped...
-- Connected process does not have addon loaded anymore. Exiting...
-- Check ReShade logs for more informations.

Others plugins simply don't work or crashes also:

-- ERROR: Unexpected error during load of pipeline="ai_cartoon_gan.py"
Traceback (most recent call last):
  File "pyhook.py", line 250, in pyhook_main
  File "pipeline.py", line 214, in load
  File "D:\PyHook-1.3.0-win_amd64\pipelines\ai_cartoon_gan.py", line 145, in on_load
    state_dict = torch.load(model_path)
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 712, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 1049, in _load
    result = unpickler.load()
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 1019, in persistent_load
    load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 1001, in load_tensor
    wrap_storage=restore_location(storage, location),
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 175, in default_restore_location
    result = fn(storage, location)
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 152, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 136, in validate_cuda_device
    raise RuntimeError('Attempting to deserialize object on a CUDA '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
-- ERROR: Unexpected error during load of pipeline="ai_style_transfer.py"
Traceback (most recent call last):
  File "pyhook.py", line 250, in pyhook_main
  File "pipeline.py", line 214, in load
  File "D:\PyHook-1.3.0-win_amd64\pipelines\ai_style_transfer.py", line 140, in on_load
    state_dict = torch.load(model_path)
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 713, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 930, in _legacy_load
    result = unpickler.load()
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 876, in persistent_load
    wrap_storage=restore_location(obj, location),
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 175, in default_restore_location
    result = fn(storage, location)
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 152, in _cuda_deserialize
    device = validate_cuda_device(location)
  File "G:\anaconda3\envs\pyhook64env\lib\site-packages\torch\serialization.py", line 136, in validate_cuda_device
    raise RuntimeError('Attempting to deserialize object on a CUDA '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
Pipeline="[Test] RGB" was loaded.
BEFORE: Settings change: Brightness = 0.5199999809265137.
AFTER: Settings change: Brightness = 0.5199999809265137.
Unhandled exception occurred.
Traceback (most recent call last):
  File "pyhook.py", line 280, in pyhook_main
KeyError: 'autosave_settings_seconds'
dwojtasik commented 1 year ago

On the 1st part: I should totally freeze python version for OpenCV build script. You could rebuild your OpenCV with Python 3.10.6 by adding freezed version after env name while creation of virtual env. conda create -y --name %envName% python=3.10.6 numpy Also setting LOCAL_PYTHON_64 is legacy and path to local python can be set in PyHook settings.

On the 2nd part: -- ERROR: Frame modification detected for multistage processing in frame=960! Frame skipped... suggest that you have changed in-game resolution while processing frame somehow - maybe dynamic resolution is enabled? Please, provide additonal info about resolution set in game.

It seems like your PyTorch installation does not support CUDA which is possible as pip's latest PyTorch that support CUDA 11.0 is 1.7.1 and pipelines use newer code based on 1.12.1. RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False

For KeyError it looks like settings.json file is messed up:

Unhandled exception occurred. Traceback (most recent call last): File "pyhook.py", line 280, in pyhook_main KeyError: 'autosave_settings_seconds'

Please verify if you have "autosave_settings_seconds": 5 provided in settings.json file in directory with PyHook.exe or remove the file completly so PyHook could create new valid one.

To summarize: Try to install CUDA 11.3, then setup virtual env with Python 3.10.6. Install valid PyTorch version with CUDA support inside your virtual env: pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113

dwojtasik commented 1 year ago

Closed due to inactivity.