darknet icon indicating copy to clipboard operation
darknet copied to clipboard

【SOLVED】 Python `darknet.py` ERROR : `Could not find module 'darknet.dll'`, *** NO NEED *** to downgrade to py 3.7 on Windows 11

Open 12343954 opened this issue 9 months ago • 0 comments

$ python -V
 3.11.4

$ conda -V
 23.5.2

$ darknet -V
 Darknet code version: 2023.09.27
 CUDA-version: 10020 (11080), cuDNN: 7.6.5, CUDNN_HALF=1, GPU count: 1
 CUDNN_HALF=1
 OpenCV version: 4.2.0

$ winver
 Windows 11 22H2

ERROR

$ pytyon darknet_images.py

Traceback (most recent call last):
File "", line 1, in
File "D:\YOLOv4-W11\darknet-2023.9.27\build\darknet\x64\darknet.py", line 265, in
lib = ct.CDLL("yolo_cpp_dll.dll", winmode = 0, mode = ct.RTLD_GLOBAL)
File "D:\AI\miniconda3\Lib\ctypes_init_.py", line 376, in init
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'D:\YOLOv4-W11\darknet-2023.9.27\build\darknet\x64\yolo_cpp_dll.dll' (or one of its dependencies). Try using the full path with constructor syntax.

** Focus **

Higher versions of ctype, enable dependency verification of importing DLLs. so, make sure the missing dependency DLLs exist under the x64 folder.

Solution

1. Analyze the dependencies of yolo_cpp_dll.dll (Compile YOLO with VS2019, not vcpkg, watch this video)

ps: you can change the dll name to darknet.dll, or change the code darknet.dll to yolo_cpp_dll.dll in darknet.py

  1. open Developer Command Prompt for VS 2022
  2. list dependencies via dumpbin command
$ C:\Program Files\Microsoft Visual Studio\2022\Community>dumpbin D:\YOLOv4-W11\darknet-2023.9.27\build\darknet\x64\yolo_cpp_dll.dll

2. Copy missing dlls to x64 folder, from C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\{cuda version}

  1. copy cudart64_102.dll not worked
  2. copy cudnn64_7.dll, then it works
  3. you maybe try them one by one until it works
$ (base) PS D:\YOLOv4-W11\darknet-2023.9.27\build\darknet\x64> dir *.dll


    Directory: D:\YOLOv4-W11\darknet-2023.9.27\build\darknet\x64


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        2019/10/24     16:28         411648 cudart64_102.dll
-a----        2019/10/27     15:02      456168960 cudnn64_7.dll
-a----        2019/12/20     22:00       21177344 opencv_videoio_ffmpeg420.dll
-a----        2019/12/20     22:00       22066688 opencv_videoio_ffmpeg420_64.dll
-a----        2019/12/20     22:15       59127808 opencv_world420.dll
-a----        2019/12/20     22:06      111518208 opencv_world420d.dll
------         2023/9/27      8:04         185976 pthreadGC2.dll
------         2023/9/27      8:04          82944 pthreadVC2.dll
-a----         2023/9/27     20:05        2868736 yolo_cpp_dll.dll

3. Done, enjoy it !

 $ python darknet_images.py

 Try to load cfg: ./cfg/yolov4.cfg, weights: yolov4.weights, clear = 0
 0 : compute_capability = 750, cudnn_half = 1, GPU: NVIDIA GeForce RTX 2080 Ti
net.optimized_memory = 0
mini_batch = 1, batch = 8, time_steps = 1, train = 0
   layer   filters  size/strd(dil)      input                output
   0 Create CUDA-stream - 0
 Create cudnn-handle 0
conv     32       3 x 3/ 1    608 x 608 x   3 ->  608 x 608 x  32 0.639 BF
   1 conv     64       3 x 3/ 2    608 x 608 x  32 ->  304 x 304 x  64 3.407 BF
   2 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   3 route  1                                      ->  304 x 304 x  64

12343954 avatar Sep 27 '23 14:09 12343954