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

PaddleDetection PP-Vehicle车辆跟踪模块 部署 #9709

Closed
hbo-lambda opened this issue Nov 17, 2022 · 3 comments
Closed

PaddleDetection PP-Vehicle车辆跟踪模块 部署 #9709

hbo-lambda opened this issue Nov 17, 2022 · 3 comments
Assignees

Comments

@hbo-lambda
Copy link

系统:Linux bm1684 4.9.38-bm1684-v9.6.1 #1 SMP Fri Apr 22 16:59:15 CST 2022 aarch64 GNU/Linux
代码:Paddle-Lite-Demo/PaddleLite-armlinux-demo/yolo_detection_demo
部署对象:PaddleDetection PP-Vehicle车辆跟踪模块,模型下载地址https://bj.bcebos.com/v1/paddledet/models/pipeline/mot_ppyoloe_s_36e_ppvehicle.zip

我对yolo_detection_demo.cc做了如下修改(为了适应 PP-Vehicle)
Snip20221117_3

另外,yolo_detection_demo.cc之前为
Snip20221117_5
现在改为
Snip20221117_7

Input1类型为intshi时,运行会报错:Error input tensor precision type. Input index (1) Tensor name (scale_factor) Require precision type (float) Input precision type (int32_t)
input1为input_image.rows时,检测结果是0,即什么也没检测到。

我不懂c++,所做的修改是只是为了避免报错。
最后的检测结果展示
Snip20221116_2

我应该是哪里搞错了,同样的模型(转成.nb后,照着PaddleDetection在lite下部署教程做的)在手机端进行部署后,是可以正常检测的
result_demo

不知道问题出在哪里,请指教

@paddle-bot
Copy link

paddle-bot bot commented Nov 17, 2022

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网文档常见问题历史Issue来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQ and Github Issue to get the answer.Have a nice day!

@hong19860320
Copy link
Collaborator

hong19860320 commented Nov 17, 2022

image

这个模型是两个fp32的输入,你后面改的是正确的,

image

但是scale_factor[0]和scale_factor[1]的值不是1.0,我理解应该是 [640.0/origin_image.h, 640.0/origin_image.w] 或者 [640.0/origin_image.w, 640.0/origin_image.h],这两个你都试试。

@hbo-lambda
Copy link
Author

image

这个模型是两个fp32的输入,你后面改的是正确的,
image

但是scale_factor[0]和scale_factor[1]的值不是1.0,我理解应该是 [640.0/origin_image.h, 640.0/origin_image.w] 或者 [640.0/origin_image.w, 640.0/origin_image.h],这两个你都试试。

谢谢回复,我最后放弃改c++了。今天用python 实现了一遍,发现当时想复杂了。而且scale_factor这个参数没搞明白,后来鼓捣了鼓捣才明白这个参数是控制缩放的,设置后会对模型的输出有影响。
这是我的代码

from paddlelite.lite import *
import numpy as np
import cv2


config = MobileConfig()
config.set_model_from_file("./models/ppvehicle/model.nb")

predictor = create_paddle_predictor(config)
origin = cv2.imread('./images/car.jpg')
print(origin.shape)
height, width, _ = origin.shape
scale_h = 640 / height
scale_w = 640 / width


image = cv2.cvtColor(origin, cv2.COLOR_BGR2RGB)
resized_image = cv2.resize(image, (640, 640))
image_data = np.array(resized_image, dtype=np.float32).transpose(2, 0, 1).reshape(1, 3, 640, 640)

input_tensor = predictor.get_input(0)
input_tensor.from_numpy(image_data)

scale_tensor = predictor.get_input(1)
scale_factor = np.array((scale_h, scale_w), dtype=np.float32).reshape(1, -1)
scale_tensor.from_numpy(scale_factor)

predictor.run()
output_tensor = predictor.get_output(0)
output_data = output_tensor.numpy()

for i in range(output_data.shape[0]):
    class_id = output_data[i][0]
    prob = output_data[i][1]
    box = output_data[i][2:].astype(int)
    if prob < 0.5:
        continue

    print(box)
    draw = cv2.rectangle(origin, box[:2], box[2:], (255, 0, 255), 1)
    cv2.imwrite('./hello.jpg', draw)

再次感谢您的回复

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

3 participants