Batch size > 1 for the 3D demo.
This commit lets to use differtent batch size for 3D CenterNet and CenterTrack. Signed-off-by: Davide Sapienza <sapienza.dav@gmail.com>
This commit is contained in:
+47
-24
@@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h> /* srand, rand */
|
||||
#include <unistd.h>
|
||||
//#include <unistd.h>
|
||||
#include <mutex>
|
||||
|
||||
#include "CenternetDetection3D.h"
|
||||
@@ -24,7 +24,12 @@ int main(int argc, char *argv[]) {
|
||||
std::string net = "dla34_cnet3d_fp32.rt";
|
||||
if(argc > 1)
|
||||
net = argv[1];
|
||||
std::string input = "../demo/yolo_test.mp4";
|
||||
#ifdef __linux__
|
||||
std::string input = "../demo/yolo_test.mp4";
|
||||
#elif _WIN32
|
||||
std::string input = "..\\..\\..\\demo\\yolo_test.mp4";
|
||||
#endif
|
||||
|
||||
if(argc > 2)
|
||||
input = argv[2];
|
||||
char ntype = 'c';
|
||||
@@ -33,9 +38,18 @@ int main(int argc, char *argv[]) {
|
||||
int n_classes = 3;
|
||||
if(argc > 4)
|
||||
n_classes = atoi(argv[4]);
|
||||
bool show = false;
|
||||
int n_batch = 1;
|
||||
if(argc > 5)
|
||||
show = atoi(argv[5]);
|
||||
n_batch = atoi(argv[5]);
|
||||
bool show = true;
|
||||
if(argc > 6)
|
||||
show = atoi(argv[6]);
|
||||
float conf_thresh=0.3;
|
||||
if(argc > 7)
|
||||
conf_thresh = atof(argv[7]);
|
||||
|
||||
if(n_batch < 1 || n_batch > 64)
|
||||
FatalError("Batch dim not supported");
|
||||
|
||||
if(!show)
|
||||
SAVE_RESULT = true;
|
||||
@@ -57,7 +71,7 @@ int main(int argc, char *argv[]) {
|
||||
FatalError("Network type not allowed (3rd parameter)\n");
|
||||
}
|
||||
|
||||
detNN->init(net, n_classes);
|
||||
detNN->init(net, n_classes, n_batch, conf_thresh);
|
||||
|
||||
gRun = true;
|
||||
|
||||
@@ -75,30 +89,40 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
cv::Mat frame;
|
||||
cv::Mat dnn_input;
|
||||
if(show)
|
||||
cv::namedWindow("detection", cv::WINDOW_NORMAL);
|
||||
cv::namedWindow("detection", cv::WINDOW_NORMAL);
|
||||
|
||||
std::vector<tk::dnn::box> detected_bbox;
|
||||
std::vector<cv::Mat> batch_frame;
|
||||
std::vector<cv::Mat> batch_dnn_input;
|
||||
|
||||
while(gRun) {
|
||||
cap >> frame;
|
||||
if(!frame.data) {
|
||||
break;
|
||||
}
|
||||
|
||||
// this will be resized to the net format
|
||||
dnn_input = frame.clone();
|
||||
batch_dnn_input.clear();
|
||||
batch_frame.clear();
|
||||
|
||||
for(int bi=0; bi< n_batch; ++bi){
|
||||
cap >> frame;
|
||||
if(!frame.data)
|
||||
break;
|
||||
|
||||
batch_frame.push_back(frame);
|
||||
|
||||
// this will be resized to the net format
|
||||
batch_dnn_input.push_back(frame.clone());
|
||||
}
|
||||
if(!frame.data)
|
||||
break;
|
||||
|
||||
//inference
|
||||
detNN->update(dnn_input);
|
||||
frame = detNN->draw(frame);
|
||||
|
||||
if(show) {
|
||||
cv::imshow("detection", frame);
|
||||
cv::waitKey(1);
|
||||
}
|
||||
if(SAVE_RESULT)
|
||||
detNN->update(batch_dnn_input, n_batch);
|
||||
detNN->draw(batch_frame);
|
||||
|
||||
if(show){
|
||||
for(int bi=0; bi< n_batch; ++bi){
|
||||
cv::imshow("detection", batch_frame[bi]);
|
||||
cv::waitKey(1);
|
||||
}
|
||||
}
|
||||
if(n_batch == 1 && SAVE_RESULT)
|
||||
resultVideo << frame;
|
||||
}
|
||||
|
||||
@@ -124,7 +148,6 @@ int main(int argc, char *argv[]) {
|
||||
std::cout<<"Avg: "<<mean<<" ms\n"<<COL_END;
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user