PaddleDetection icon indicating copy to clipboard operation
PaddleDetection copied to clipboard

ppyoloe导出onnx模型错误

Open Monday-Leo opened this issue 4 years ago • 8 comments

训练的ppyoloe_s模型,使用paddle2onnx导出onnx文件,有两个输入,两个输出,且输入batch为-1,感觉有op不支持,请问该怎么解决? 微信图片_20220331011216 微信图片_20220331011226

Monday-Leo avatar Mar 31 '22 04:03 Monday-Leo

这个不是导出错误哈,两个输出也是对的,这个就是multiclass_nms的输出,constant是模型中保存的一些参数,等下我给你个示例,这个是可以在onnxruntime上跑通的

wangxinxin08 avatar Mar 31 '22 06:03 wangxinxin08

非常感谢!!!

Monday-Leo avatar Mar 31 '22 06:03 Monday-Leo

给你个示例代码,你可以放到PaddleDetection目录下跑下,如果路径不对的话,注意修改下路径:

import os
import cv2
import numpy as np
import onnxruntime

def preprocess(img):
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    img = cv2.resize(img, (640, 640), interpolation=cv2.INTER_LINEAR)
    img = img.astype(np.float32)
    img = img / 255.
    img -= np.array([0.485, 0.456, 0.406])[None, None, :]
    img /= np.array([0.229, 0.224, 0.225])[None, None, :]
    img = np.transpose(img, [2, 0, 1])
    scale_factor = np.array([1., 1.], dtype=np.float32)
    return img, scale_factor


def main(img_file, model_file):
    img = cv2.imread(img_file)
    img, scale_factor = preprocess(img)
    session = onnxruntime.InferenceSession(model_file)
    inputs = {'image': img[None, :, :, :], 'scale_factor': scale_factor[None, :]}
    ort_inputs = {i.name: inputs[i.name] for i in session.get_inputs() if i.name in inputs}
    output = session.run(None, ort_inputs)
    bbox, bbox_num = output
    keep_idx = (bbox[:, 1] > 0.5) & (bbox[:, 0] > -1)
    bbox = bbox[keep_idx, :]
    for (clsid, score, xmin, ymin, xmax, ymax) in bbox:
        print('class_id:{:d}, confidence:{:.4f}, left_top:[{:.2f},{:.2f}],'
                  'right_bottom:[{:.2f},{:.2f}]'.format(
                      int(clsid), score, xmin, ymin, xmax, ymax))


if __name__ == '__main__':
    img_file = 'demo/000000014439_640x640.jpg'
    model_file = 'ppyoloe_crn_s_300e_coco.onnx'
    main(img_file, model_file)

wangxinxin08 avatar Mar 31 '22 07:03 wangxinxin08

感谢,可以跑通!

Monday-Leo avatar Mar 31 '22 11:03 Monday-Leo

请问一下模型输出的8400*6有什么具体的含义吗,为什么是这个shape?

Monday-Leo avatar Mar 31 '22 12:03 Monday-Leo

这个是最大可能输出的框的数目,8400是anchor的个数

wangxinxin08 avatar Apr 01 '22 03:04 wangxinxin08

Since this issue has not been updated for more than three months, it will be closed, if it is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. It is recommended to pull and try the latest code first. 由于该问题超过三个月未更新,将会被关闭,若问题未解决或有后续问题,请随时重新打开(建议先拉取最新代码进行尝试),我们会继续跟进。

paddle-bot-old avatar Jul 05 '22 06:07 paddle-bot-old

使用paddle2onnx导出onnx文件,有两个输入,两个输出,怎么做的,用的什么命令啊,我需要这种的

wxs56837 avatar Sep 12 '25 15:09 wxs56837