diff --git a/README.md b/README.md index 7f1016d..5e46bd8 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,10 @@ M. Verucchi, L. Bartoli, F. Bagni, F. Gatti, P. Burgio and M. Bertogna, "Real-Ti - [2)Export weights for DLA34 and ResNet101](#2export-weights-for-dla34-and-resnet101) - [3)Export weights for CenterNet](#3export-weights-for-centernet) - [4)Export weights for MobileNetSSD](#4export-weights-for-mobilenetssd) - - [Run the demo](#run-the-demo) + - [How to convert weights](#how-to-convert-weights) - [FP16 inference](#fp16-inference) - [INT8 inference](#int8-inference) + - [Run the demo](#run-the-demo) - [mAP demo](#map-demo) - [Existing tests and supported networks](#existing-tests-and-supported-networks) - [References](#references) @@ -113,26 +114,8 @@ cd pytorch-ssd conda env create -f env_mobv2ssd.yml python run_ssd_live_demo.py mb2-ssd-lite ``` -## Run the demo -To run the an object detection demo follow these steps (example with yolov3): -``` -rm yolo3_fp32.rt # be sure to delete(or move) old tensorRT files -./test_yolo3 # run the yolo test (is slow) -./demo yolo3_fp32.rt ../demo/yolo_test.mp4 y -``` -In general the demo program takes 4 parameters: -``` -./demo -``` -where -* `````` is the rt file generated by a test -* ```<``` is the path to a video file or a camera input -* `````` is the type of network. Thee types are currently supported: ```y``` (YOLO family), ```c``` (CenterNet family) and ```m``` (MobileNet-SSD family) -* ``````is the number of classes the network is trained on -N.b. By default it is used FP32 inference - -![demo](https://user-images.githubusercontent.com/11562617/72547657-540e7800-388d-11ea-83c6-49dfea2a0607.gif) +## How to convert weights ### FP16 inference @@ -187,6 +170,29 @@ rm yolo3_fp32.rt # be sure to delete(or move) old tensorRT fil ./test_rtinference yolo3_fp32.rt 4 # test with a batch size of 4 ``` +## Run the demo + +To run the an object detection demo follow these steps (example with yolov3): +``` +rm yolo3_fp32.rt # be sure to delete(or move) old tensorRT files +./test_yolo3 # run the yolo test (is slow) +./demo yolo3_fp32.rt ../demo/yolo_test.mp4 y # add parameter y for yolo. c for CNET & m for Mobilenet. +./demo yolo3_fp32.rt ../demo/yolo_test.mp4 y 1 #if number of classes not 80. Add class number parameter. +``` +In general the demo program takes 5 parameters: +``` +./demo +``` +where +* `````` is the rt file generated by a test +* ```<``` is the path to a video file or a camera input +* `````` is the type of network. Thee types are currently supported: ```y``` (YOLO family), ```c``` (CenterNet family) and ```m``` (MobileNet-SSD family) +* ``````is the number of classes the network is trained on +N.b. By default it is used FP32 inference +* `````` benchmark or save_result. Adding benchmark will not show opencv detection video allowing demo to be run from terminal, providing performance results without showing the video. Adding save_result will save output of detection to results.mp4. + +![demo](https://user-images.githubusercontent.com/11562617/72547657-540e7800-388d-11ea-83c6-49dfea2a0607.gif) + ## mAP demo To compute mAP, precision, recall and f1score, run the map_demo. diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index 75012b6..b37ed7f 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -10,6 +10,7 @@ bool gRun; bool SAVE_RESULT = false; +bool BENCHMARK = false; void sig_handler(int signo) { std::cout<<"request gateway stop\n"; @@ -33,7 +34,13 @@ int main(int argc, char *argv[]) { ntype = argv[3][0]; int n_classes = 80; if(argc > 4) - n_classes = atoi(argv[4]); + n_classes = atoi(argv[4]); + if(argc > 5 && strcmp(argv[5], "benchmark") == 0) { + BENCHMARK = true; + } + if(argc > 5 && strcmp(argv[5], "save_result") == 0) { + SAVE_RESULT = true; + } tk::dnn::Yolo3Detection yolo; tk::dnn::CenternetDetection cnet; @@ -76,8 +83,9 @@ int main(int argc, char *argv[]) { cv::Mat frame; cv::Mat dnn_input; + if(!BENCHMARK) { cv::namedWindow("detection", cv::WINDOW_NORMAL); - + } std::vector detected_bbox; while(gRun) { @@ -91,9 +99,13 @@ int main(int argc, char *argv[]) { //inference detNN->update(dnn_input); + if(!BENCHMARK) { frame = detNN->draw(frame); + } + if(!BENCHMARK) { cv::imshow("detection", frame); + } cv::waitKey(1); if(SAVE_RESULT) resultVideo << frame; @@ -106,9 +118,9 @@ int main(int argc, char *argv[]) { std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())<<" ms\n"; std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())<<" ms\n"; for(int i=0; istats.size(); i++) mean += detNN->stats[i]; mean /= detNN->stats.size(); - std::cout<<"Avg: "<