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

版面检测模型时间消耗 #3394

Open
wangwenqi567 opened this issue Feb 18, 2025 · 4 comments
Open

版面检测模型时间消耗 #3394

wangwenqi567 opened this issue Feb 18, 2025 · 4 comments
Assignees

Comments

@wangwenqi567
Copy link

使用环境

ubuntu 22.04
Python 3.9.20
cuda 11.8
cuDNN 8.6
gpu 4090
驱动版本 550.107.02

paddlepaddle-gpu 3.0.0b2
paddlex 3.0.0b2
用docker 容器部署

在使用版面检测模型时,模型预测 model.predict所使用的时间很短
但是使用 for 循环从 output 中取出结果时,发现耗时比较长
想请教一下是什么原因?

@cuicheng01
Copy link
Collaborator

您好,辛苦贴一下你现在的代码呢?

@wangwenqi567
Copy link
Author

np_image = np.array(img)
output = model.predict(np_image, batch_size=1)
print(type(output))
print(f"output: {output}")
e1time = time.time()
c1time = e1time - stime
print(f"layout parser cost {c1time} seconds")
results = []
#print(len(output))

for det_result in output:
    #print(f"det_result: {det_result}")
    det_result_serializable = {
        "input_path": str(det_result["input_path"]),
        "boxes": [
            {
                "cls_id": int(box["cls_id"]),
                "label": str(box["label"]),
                "score": float(box["score"]),
                "coordinate": [float(coord) for coord in box["coordinate"]]
            }
            for box in det_result["boxes"]
        ]
    }
etime = time.time()
ctime = etime - stime
print(f"final layout parser cost {ctime} seconds")

即使不做任何的格式转换,将for循环下改为continue,或者
for res in output:
res.print()
res.save_to_img(save_path="./output/")
res.save_to_json(save_path="./output/res.json")
都发现模型走完model.predict的时间是很短的,但是取出所需要看到的输出时间就很长了

@cuicheng01
Copy link
Collaborator

你说的时间短或者长大概是什么量级呢?

@wangwenqi567
Copy link
Author

model.predict 时间是0.1-0.2s,for循环拿到结果或者保存结果是7s-10s,但是目前用高性能框架解决了时间问题
猜测是输出是generator类型惰性加载导致的

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