Skip to content

Device id must be less than GPU count, but received id is: 3. GPU count is: 1 #15497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
xndm-tech opened this issue May 29, 2025 · 0 comments
Open
3 tasks done
Assignees

Comments

@xndm-tech
Copy link

xndm-tech commented May 29, 2025

🔎 Search before asking

  • I have searched the PaddleOCR Docs and found no similar bug report.
  • I have searched the PaddleOCR Issues and found no similar bug report.
  • I have searched the PaddleOCR Discussions and found no similar bug report.

🐛 Bug (问题描述)

Traceback (most recent call last):
File "/home/xxxxxxx/subtitle/video-subtitle-extractor/backend/test_device_id_bug.py", line 4, in
ocr = PaddleOCR(#device = 'GPU',
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddleocr/_pipelines/ocr.py", line 144, in init
super().init(**base_params)
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddleocr/_pipelines/base.py", line 73, in init
self.paddlex_pipeline = self._create_paddlex_pipeline()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddleocr/_pipelines/base.py", line 108, in _create_paddlex_pipeline
return create_pipeline(config=self._merged_paddlex_config, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/pipelines/init.py", line 165, in create_pipeline
pipeline = BasePipeline.get(pipeline_name)(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/utils/deps.py", line 195, in _wrapper
return old_init_func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/pipelines/_parallel.py", line 103, in init
self._pipeline = self._create_internal_pipeline(config, self.device)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/pipelines/_parallel.py", line 158, in _create_internal_pipeline
return self._pipeline_cls(
^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/pipelines/ocr/pipeline.py", line 114, in init
self.text_det_model = self.create_model(
^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/pipelines/base.py", line 99, in create_model
model = create_predictor(
^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/models/init.py", line 77, in create_predictor
return BasePredictor.get(model_name)(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/models/text_detection/predictor.py", line 57, in init
self.pre_tfs, self.infer, self.post_op = self._build()
^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/models/text_detection/predictor.py", line 77, in _build
infer = self.create_static_infer()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/models/base/predictor/base_predictor.py", line 240, in create_static_infer
return PaddleInfer(self.model_dir, self.MODEL_FILE_PREFIX, self._pp_option)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/models/common/static_infer.py", line 274, in init
self.predictor = self._create()
^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/subtitle/lib/python3.12/site-packages/paddlex/inference/models/common/static_infer.py", line 437, in _create
predictor = paddle.inference.create_predictor(config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: (InvalidArgument) Device id must be less than GPU count, but received id is: 3. GPU count is: 1.
[Hint: Expected id < GetGPUDeviceCount(), but received id:3 >= GetGPUDeviceCount():1.] (at ../paddle/phi/backends/gpu/cuda/cuda_info.cc:248)

问题还是源于GPUtil,但修复后需要确认下面的程序是否能跑通。

🏃‍♂️ Environment (运行环境)

python代码,如果文件名为test.py,则运行CUDA_VISIBLE_DEVICES=5 python backend/test_device_id_bug.py 会报错
from paddleocr import PaddleOCR
import cv2
ocr = PaddleOCR(#device = 'GPU',
# 设置文本检测模型路径
text_detection_model_name='PP-OCRv5_server_det',
# 设置每张图文本框批处理数量
text_recognition_batch_size=6,
# 设置文本识别模型路径
text_recognition_model_name='PP-OCRv5_server_rec',
use_doc_orientation_classify = False,
use_doc_unwarping = False,
use_textline_orientation = False,
text_det_unclip_ratio=1.2,
text_det_limit_side_len=1080,
text_det_limit_type='max',
text_rec_score_thresh = 0.5,
#lang='ch'
)

读取图片

img_path = "test_src.jpg"
image = cv2.imread(img_path)

执行 OCR 识别

result = ocr.predict(image)

🌰 Minimal Reproducible Example (最小可复现问题的Demo)

可参考上面内容
这里面涉及几个点:1、运行时设置CUDA_VISIBLE_DEVICES=5,也可以设置为其他值,对于8卡机,小于8大于0即可 ,2、报错一律为received id is: 3, 即这里拿到的id跟机器本身GPU的显存状态有关,3. GPU count is:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants