Add getMemoryUsage function, detection update moved in abstract lass, splitted execution time in pre-inf-post, other minors.

Signed-off-by: Micaela Verucchi <micaelaverucchi@gmail.com>
This commit is contained in:
Micaela Verucchi
2020-04-01 19:18:43 +02:00
parent e2225d2449
commit 43567dc3ea
14 changed files with 255 additions and 128 deletions
+1 -27
View File
@@ -264,40 +264,14 @@ void CenternetDetection::preprocess(cv::Mat &frame)
#endif
}
void CenternetDetection::update(cv::Mat &frame)
void CenternetDetection::postprocess()
{
originalSize = frame.size();
if(!frame.data) {
std::cout<<"CENTERNET: NO IMAGE DATA\n";
return;
}
TIMER_START
preprocess(frame);
printCenteredTitle(" TENSORRT inference ", '=', 30); {
dim2.print();
TIMER_START
netRT->infer(dim2, input_d);
TIMER_STOP
dim2.print();
}
dnnType *rt_out[4];
rt_out[0] = (dnnType *)netRT->buffersRT[1];
rt_out[1] = (dnnType *)netRT->buffersRT[2];
rt_out[2] = (dnnType *)netRT->buffersRT[3];
rt_out[3] = (dnnType *)netRT->buffersRT[4];
postprocess(rt_out, 4);
// std::cout<<"TOTAL: \n";
TIMER_STOP
stats.push_back(t_ns);
}
void CenternetDetection::postprocess(dnnType **rt_out, const int n_out)
{
// auto start_t = std::chrono::steady_clock::now();
// auto step_t = std::chrono::steady_clock::now();
// auto end_t = std::chrono::steady_clock::now();
+1 -31
View File
@@ -243,45 +243,15 @@ void MobilenetDetection::preprocess(cv::Mat &frame)
#endif
}
void MobilenetDetection::update(cv::Mat &frame)
void MobilenetDetection::postprocess()
{
TIMER_START
if(!frame.data) {
std::cout<<"MOBILENET: NO IMAGE DATA\n";
return;
}
originalSize = frame.size();
//preprocess
preprocess(frame);
//do inference
tk::dnn::dataDim_t dim = tk::dnn::dataDim_t(1, 3, imageSize, imageSize, 1);;
printCenteredTitle(" TENSORRT inference ", '=', 30);
{
dim.print();
TIMER_START
netRT->infer(dim, input_d);
TIMER_STOP
dim.print();
}
//get confidences and locations_h
dnnType *rt_out[2];
rt_out[0] = (dnnType *)netRT->buffersRT[3];
rt_out[1] = (dnnType *)netRT->buffersRT[4];
detected.clear();
//postprocess
postprocess(rt_out, 2);
TIMER_STOP
stats.push_back(t_ns);
}
void MobilenetDetection::postprocess(dnnType **rt_out, const int n_out)
{
checkCuda(cudaMemcpy(confidences_h, rt_out[0], nPriors * classes * sizeof(float), cudaMemcpyDeviceToHost));
checkCuda(cudaMemcpy(locations_h, rt_out[1], N_COORDS * nPriors * sizeof(float), cudaMemcpyDeviceToHost));
convert_locatios_to_boxes_and_center();
+2 -34
View File
@@ -84,52 +84,20 @@ void Yolo3Detection::preprocess(cv::Mat &frame)
#endif
}
void Yolo3Detection::update(cv::Mat &frame)
void Yolo3Detection::postprocess()
{
TIMER_START
if(!frame.data) {
std::cout<<"YOLO: NO IMAGE DATA\n";
return;
}
originalSize = frame.size();
preprocess(frame);
//do inference
tk::dnn::dataDim_t dim = netRT->input_dim;
// printDeviceVector(netRT->input_dim.tot()*sizeof(dnnType),input_d);
printCenteredTitle(" TENSORRT inference ", '=', 30);
{
dim.print();
TIMER_START
netRT->infer(dim, input_d);
TIMER_STOP
dim.print();
}
//get yolo outputs
dnnType *rt_out[netRT->pluginFactory->n_yolos];
for(int i=0; i<netRT->pluginFactory->n_yolos; i++) {
rt_out[i] = (dnnType*)netRT->buffersRT[i+1];
}
postprocess(rt_out, netRT->pluginFactory->n_yolos);
TIMER_STOP
stats.push_back(t_ns);
}
void Yolo3Detection::postprocess(dnnType **rt_out, const int n_out)
{
float x_ratio = float(originalSize.width) / float(netRT->input_dim.w);
float y_ratio = float(originalSize.height) / float(netRT->input_dim.h);
// compute dets
nDets = 0;
for(int i=0; i<n_out; i++) {
for(int i=0; i<netRT->pluginFactory->n_yolos; i++) {
yolo[i]->dstData = rt_out[i];
yolo[i]->computeDetections(dets, nDets, netRT->input_dim.w, netRT->input_dim.h, confThreshold);
}
+33
View File
@@ -168,3 +168,36 @@ void matrixMulAdd( cublasHandle_t handle, dnnType* srcData, dnnType* dstData,
checkERROR( cublasSaxpy(handle, dim, &alpha, srcData, 1, dstData, 1));
}
void getMemUsage(double& vm_usage_kb, double& resident_set_kb)
{
using std::ios_base;
using std::ifstream;
using std::string;
vm_usage_kb = 0.0;
resident_set_kb = 0.0;
ifstream stat_stream("/proc/self/stat",ios_base::in);
//all the stats
string pid, comm, state, ppid, pgrp, session, tty_nr;
string tpgid, flags, minflt, cminflt, majflt, cmajflt;
string utime, stime, cutime, cstime, priority, nice;
string O, itrealvalue, starttime;
unsigned long vsize;
long rss;
stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
>> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
>> utime >> stime >> cutime >> cstime >> priority >> nice
>> O >> itrealvalue >> starttime >> vsize >> rss;
stat_stream.close();
long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
vm_usage_kb = vsize / 1024.0;
resident_set_kb = rss * page_size_kb;
}