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

改成视频检测后,每次进行第二帧的inference时都会多消耗几百倍的时间。 #47

Open
monoloxo opened this issue Jul 2, 2021 · 1 comment

Comments

@monoloxo
Copy link

monoloxo commented Jul 2, 2021

在main.cpp中改写成视频检测,主要代码如下:

`VideoCapture capture;
std::cout << "finish load network and open the video" << std::endl;

capture.open("/home/****/libtorch-yolov5/test.mp4");
if (!capture.isOpened())
    {
        std::cout << "can not open ...\n" << std::endl;
        return -1;
    }
Mat frame;
namedWindow("output",WINDOW_AUTOSIZE);
// set up threshold
float conf_thres = 0.4;//opt["conf-thres"].as<float>();
float iou_thres = 0.5;//opt["iou-thres"].as<float>();
for (;;)
{
    capture >> frame;
    //Mat pic;
    if (frame.empty()) break;
    //imshow("output",frame);
    std::cout << "start forward" <<std::endl;
    auto result = detector.Run(frame, conf_thres, iou_thres);
    Demo(frame, result, class_names);
    imshow("output",frame);
    if (waitKey(33) >= 0) break;
}

capture.release();
cv::destroyAllWindows();
//return 0;`

然后程序运行时,加载模型后第一帧马上就会显示出检测后的图像,也能正确画出检测框,这个过程很快,但第二帧就需要几百倍的时间,在inference阶段。。之后又回复到更短的时间,每次都是这样,换了视频也是如此,我统计了时间:
----------New Frame----------
img size:1080x1920
pre-process takes : 4 ms
inference takes : 137 ms <-------------------------------------------------------137
post-process takes : 19 ms
start forward
----------New Frame----------
img size:1080x1920
pre-process takes : 5 ms
inference takes : 7869 ms <--------------------------------------------------------7869
post-process takes : 24 ms
start forward
----------New Frame----------
img size:1080x1920
pre-process takes : 3 ms
inference takes : 8 ms <------------------------------------------------------------8
post-process takes : 25 ms
start forward
----------New Frame----------
img size:1080x1920
pre-process takes : 4 ms
inference takes : 8 ms <-------------------------------------------------------------8
post-process takes : 23 ms

请问这可能是什么原因造成的呢?
注:不知道有什么作用,所以我取消掉了warm up。

@CGump
Copy link

CGump commented Aug 3, 2021

同样的问题,我直接循环跑单图前两张图消耗时间非常大

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