Skip to content
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

同CPU下,paddle-gpu在use_gpu=False时,无法使用多线程 #69388

Open
PureWaterCatt opened this issue Nov 14, 2024 · 0 comments
Open
Assignees
Labels

Comments

@PureWaterCatt
Copy link

请提出你的问题 Please ask your question

问题:
我在没有gpu驱动的docker环境下,以及有gpu的环境,使用相同的代码运行,前者可以开启多线程qps为10.2/s,而后者则是单线程qps只有1.1/s

代码

import io

import numpy as np
from PIL import Image
from fastapi import File, UploadFile
from paddleocr import PaddleOCR

# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True, lang="ch", enable_mkldnn=True,
                cpu_threads=16, use_gpu=False)  # need to run only once to download and load model into memory


async def single(file: UploadFile = File(...)):
    # 读取文件的二进制内容z`
    image_bytes = await file.read()

    # 将字节流转换为PIL图像
    image = Image.open(io.BytesIO(image_bytes))

    # 将PIL图像转换为numpy数组
    image_np = np.array(image)
    result = ocr.ocr(image_np, cls=True)
    for idx in range(len(result)):
        res = result[idx]
        if res is None or len(res) != 1:
            return '未识别'
        else:
            return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants