PaddleOCR
PaddleOCR copied to clipboard
Cannot import paddleocr together with yolov8
- Windows 11
- paddleocr 2.6.1.3
import paddleocr
import ultralytics
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\__init__.py", line 5, in <module>
from ultralytics.hub import start
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\hub\__init__.py", line 5, in <module>
from ultralytics.hub.auth import Auth
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\hub\auth.py", line 5, in <module>
from ultralytics.hub.utils import HUB_API_ROOT, PREFIX, request_with_credentials
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\hub\utils.py", line 14, in <module>
from ultralytics.yolo.utils import (ENVIRONMENT, LOGGER, ONLINE, RANK, SETTINGS, TESTS_RUNNING, TQDM_BAR_FORMAT,
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\yolo\__init__.py", line 3, in <module>
from . import v8
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\yolo\v8\__init__.py", line 3, in <module>
from ultralytics.yolo.v8 import classify, detect, pose, segment
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\yolo\v8\classify\__init__.py", line 3, in <module>
from ultralytics.yolo.v8.classify.predict import ClassificationPredictor, predict
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\ultralytics\yolo\v8\classify\predict.py", line 3, in <module>
import torch
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\torch\__init__.py", line 202, in <module>
from torch._C import * # noqa: F403
RuntimeError: generic_type: type "_CudaDeviceProperties" is already registered!
import ultralytics
import paddleocr
Error: Can not import paddle core while this file exists: C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\fluid\libpaddle.pyd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddleocr\__init__.py", line 14, in <module>
from .paddleocr import *
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddleocr\paddleocr.py", line 21, in <module>
import paddle
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\__init__.py", line 31, in <module>
from .framework import monkey_patch_variable
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\framework\__init__.py", line 17, in <module>
from . import random # noqa: F401
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\framework\random.py", line 17, in <module>
from paddle import fluid
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\fluid\__init__.py", line 36, in <module>
from . import framework
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\fluid\framework.py", line 35, in <module>
from . import core
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\fluid\core.py", line 356, in <module>
raise e
File "C:\Users\shy13\scoop\apps\python39\current\lib\site-packages\paddle\fluid\core.py", line 269, in <module>
from . import libpaddle
ImportError: generic_type: type "_gpuDeviceProperties" is already registered!
When import paddleocr
or ultralytics
separately, both are work fine. But get error when import them together.
在Python中单独导入paddleocr
或ultralytics
时无误。但同时导入将报错。
This problem may related to C++ level code, I cannot solve it by myself.
I tried to import two libraries in two subprocess, and use xmlrpc
to provide function api on localhost:some-port
. But the performance is intolerable.
这个问题可能涉及到paddle的底层C++代码,我无法独自解决。
我试图用xmlrpc
库将它们分别在两个子进程中导入,然后开启本地服务器提供函数访问接口。但是效率不忍直视,最好有能直接导入且不让它们冲突的解决方案。
I was facing the same problem. It may occurs due to the PaddlePaddle dependency, which uses CUDA as default. To solve that, I tried PaddlePaddle without CUDA (CPU).
For instance: python -m pip install paddlepaddle==2.5.0 -i https://mirror.baidu.com/pypi/simple
.
您好,我也遇到了同样的问题,请问您解决了吗
Hi, I can import paddle-ocr with yolo v8. Use Cuda only on yolov8 ultralytics and installed paddlepaddle(cpu version) works great. As per my understanding, the Cuda was initialized while running ultralytics for patch detection. Again, call the cuda with paddleocr (i.e ocr.ocr )will get the error prompt like ImportError: generic_type: type "_gpuDeviceProperties" is already registered! Because Cuda is already registered and running.
It due to personal requirement. My only need is their forward refering, so I look up code and implement ONNX format loader (no import). It works, but I don't think it's a real solution.
这与个人需求有关。我只需要正向推理的功能,所以我查阅资料使用ONNX格式(那样就不必同时导入二者了)。这样做对我来说可行,但我感觉没有实际解决问题。
Hi, I can import paddle-ocr with yolo v8. Use Cuda only on yolov8 ultralytics and installed paddlepaddle(cpu version) works great. As per my understanding, the Cuda was initialized while running ultralytics for patch detection. Again, call the cuda with paddleocr (i.e ocr.ocr )will get the error prompt like ImportError: generic_type: type "_gpuDeviceProperties" is already registered! Because Cuda is already registered and running.
Hi, does the inference speed of paddle run with speed of gpu or cpu if you change it this way. If it still have cpu inference speed I don't think it solve the problem
it seems that the problem cames out not only yolov8 ultralytics with paddleocr, but also paddlepaddle-gpu with torch. Is there any possible way to fix this.
it seems that the problem cames out not only yolov8 ultralytics with paddleocr, but also paddlepaddle-gpu with torch. Is there any possible way to fix this.
Try to reinstall paddlepaddle-gpu to version 2.4.2. It works for me.
it seems that the problem cames out not only yolov8 ultralytics with paddleocr, but also paddlepaddle-gpu with torch. Is there any possible way to fix this.
Try to reinstall paddlepaddle-gpu to version 2.4.2. It works for me. What version of pytorch is yours?
it seems that the problem cames out not only yolov8 ultralytics with paddleocr, but also paddlepaddle-gpu with torch. Is there any possible way to fix this.
Try to reinstall paddlepaddle-gpu to version 2.4.2. It works for me. What version of pytorch is yours?
1.12.1
These library version work for me
protobuf==3.19.0 paddlepaddle-gpu==2.4.2.post116 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html paddleocr==2.6.1.3 ultralytics==8.0.137
for me paddlepaddle-gpu 2.4.2 in compile by cuda11.8 with torch 2.0.1 in cuda cuda11.8 will course the same issue, but change to paddlepaddle-gpu 2.4.2 in compile by cuda11.7 is fine! https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html
@QuntuamLoop
Could you share a bit more details of your working environment? (Python Ver, cuda, paddleocr, etc.)
I am facing the same issue with: OS: Windows 11 Python Ver: 3.11 In my conda environment, the pip packages are:
- paddleocr==2.6.0.1
- paddlepaddle-gpu ==2.5.1
Thank you for your time.
Good day. I also had same errors. ImportError: generic_type: type "_gpuDeviceProperties" is already registered! or RuntimeError: generic_type: type "_CudaDeviceProperties" is already registered! Error depends from library startup sequences. As advised above, installed paddlepuddle-gpu version 2.4.2 with cuda 11.7, Torch works with cuda version 11.7 or 11.8. torch = 2.0.1+cu117 ultralytics = 8.0.189 paddleocr = 2.7.0.3 paddlepaddle-gpu = 2.4.2.post117
from torch._C import * # noqa: F403
^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: generic_type: type "_CudaDeviceProperties" is already registered!
- Win11
conda create --name model python=3.10 -y
#!/bin/bash
set -e
set -x
BASEDIR=$(dirname "$0")
pushd "$BASEDIR"
eval "$(conda shell.bash hook)"
conda activate model
pip install paddlepaddle-gpu==2.5.2
pip install ultralytics==8.0.223
pip install paddleocr==2.7.0.3
pip install opencv-python==4.6.0.66
pip install onnx==1.15.0
pip install paho-mqtt==1.6.1
pip install gradio==4.8.0
conda install -c conda-forge cudatoolkit=11.8 cudnn=8.9.2 zlib-wapi=1.2.13 -y
popd
In my case, helped: pip install paddlepaddle-gpu==2.4.2.post116 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html env looks like: paddlepaddle-gpu==2.4.2.post116 paddleocr==2.7.0.3 torch==2.2.0+cu118 protobuf==3.19.0
i use yolov8 and PaddleOCR(GPU)
from ultralytics import YOLO from paddleocr import PaddleOCR
the key is Don't make torch=118 equal to paddlepaddle-gpu=118,be differe like torch=118 paddlepaddle-gpu=117.
like this: My environment windows 11 CUDA = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8
torch==2.2.2+cu118 torchaudio==2.2.2+cu118 torchvision==0.17.2+cu118 paddlepaddle-gpu==2.4.2.post117 paddleocr==2.7.3
Not working for me. I tried all combinations possible and suggestions provided, but I am unable to find a valid setup to run Yolo (or even torch) with paddleocr. Is there an update on this issue?
This issue has not been updated for a long time. This issue is temporarily closed and can be reopened if necessary.
可以将yolo和ocr分别用两个进程来调用,可以执行,我尝试过了
You can call yolo and ocr with two processes respectively, and it can be executed. I have tried it. Yes, I am doing like that, however, I must implement an intercommunication process to provide the information from one process to the other, and I would like to simplify it. Thank you
我感觉是因为使用gpu冲突了,两个库都想用gpu,但是又没有分配机制导致的,目前好像无解。gpu底层驱动解决这个事情才行。 依据:我尝试改变两个库的建立顺序,报的错还不一样。 后调paddle为: from . import libpaddle ImportError: generic_type: type "_gpuDeviceProperties" is already registered! 先调用paddle为:from torch._C import * # noqa: F403 RuntimeError: generic_type: type "_CudaDeviceProperties" is already registered!
Yes, in my opinion it is an important issue to solve because it makes paddle useless for most projects, and I would like to draw attention to this. Downgrading yolo or paddle to previous version is a tricky solution, but is not valid for obvious reasons.
Any solution on this? How can you use Yolo and Paddle in the same project?
up ! Hey
Solution for this is to use older paddlepaddle-gpu version.
paddlepaddle-gpu==2.4.2.post117 works just fine.
Working environment: Windows 10/11
python-3.10.11-amd64 cuda_11.7.1_516.94_windows cudnn-windows-x86_64-8.4.1.50_cuda11.6-archive
opencv-contrib-python 4.6.0.66 opencv-python 4.6.0.66 paddleocr 2.8.1 paddlepaddle-gpu 2.4.2.post117 torch 1.13.1+cu117 torchaudio 0.13.1+cu117 torchvision 0.14.1+cu117 ultralytics 8.3.2 ultralytics-thop 2.0.8
It's not fixed, Why close this issue?
It's not fixed, Why close this issue?
https://github.com/PaddlePaddle/PaddleOCR/issues/10265#issuecomment-2385636539
This works 100%
Have installed it 10 times and each time there is no issue of any kind.
If it's working, can you please point into the solution? If the solution is to install an old version, it's just a patch and not accepted for obvious reasons. The question here (and in other similar posts too) is clear: is paddleocr current version compatible with yolo or torch current version into the same project? The answer as far as I see is no. Many users are asking for it. Can we have a solution for that? Thank you
If it's working, can you please point into the solution? If the solution is to install an old version, it's just a patch and not accepted for obvious reasons. The question here (and in other similar posts too) is clear: is paddleocr current version compatible with yolo or torch current version into the same project? The answer as far as I see is no. Many users are asking for it. Can we have a solution for that? Thank you
Solution for this is to use older paddlepaddle-gpu version.
paddlepaddle-gpu==2.4.2.post117 works just fine.
Working environment: Windows 10/11
python-3.10.11-amd64 cuda_11.7.1_516.94_windows cudnn-windows-x86_64-8.4.1.50_cuda11.6-archive
opencv-contrib-python 4.6.0.66 opencv-python 4.6.0.66 paddleocr 2.8.1 paddlepaddle-gpu 2.4.2.post117 torch 1.13.1+cu117 torchaudio 0.13.1+cu117 torchvision 0.14.1+cu117 ultralytics 8.3.2 ultralytics-thop 2.0.8