Signed-off-by: xavier <micaelaverucchi@gmail.com>
This commit is contained in:
xavier
2020-03-10 15:43:26 +01:00
16 changed files with 294 additions and 386 deletions
+5
View File
@@ -1,3 +1,6 @@
#ifndef CENTERNETDETECTION_H
#define CENTERNETDETECTION_H
#include "CenternetDetection.h"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/cudawarping.hpp>
@@ -419,3 +422,5 @@ void CenternetDetection::update(cv::Mat &imageORIG) {
stats.push_back(t_ns);
}
}}
#endif /*CENTERNETDETECTION_H*/
+31
View File
@@ -60,6 +60,37 @@ bool Yolo3Detection::init(std::string tensor_path) {
return true;
}
cv::Mat Yolo3Detection::draw(cv::Mat &imageORIG) {
tk::dnn::box b;
int x0, w, x1, y0, h, y1;
int objClass;
std::string det_class;
float prob;
int baseline = 0;
float fontScale = 0.5;
int thickness = 2;
// draw dets
for(int i=0; i<detected.size(); i++) {
b = detected[i];
x0 = b.x;
x1 = b.x + b.w;
y0 = b.y;
y1 = b.y + b.h;
det_class = getYoloLayer()->classesNames[b.cl];
prob = b.prob;
// std::cout<<det_class<<" ("<<prob<<"): "<<x0<<" "<<y0<<" "<<x1<<" "<<y1<<"\n";
// draw rectangle
cv::rectangle(imageORIG, cv::Point(x0, y0), cv::Point(x1, y1), colors[b.cl], 2);
// draw label
cv::Size textSize = getTextSize(det_class, cv::FONT_HERSHEY_SIMPLEX, fontScale, thickness, &baseline);
cv::rectangle(imageORIG, cv::Point(x0, y0), cv::Point((x0 + textSize.width - 2), (y0 - textSize.height - 2)), colors[b.cl], -1);
cv::putText(imageORIG, det_class, cv::Point(x0, (y0 - (baseline / 2))), cv::FONT_HERSHEY_SIMPLEX, fontScale, cv::Scalar(255, 255, 255), thickness);
}
return imageORIG;
}
void Yolo3Detection::update(cv::Mat &imageORIG) {
+43 -6
View File
@@ -1,4 +1,5 @@
#include "evaluation.h"
#include <fstream>
void BoundingBox::clear()
@@ -283,27 +284,51 @@ double computeMap(std::vector<Frame> &images,const int classes,const float IoU_t
return mean_average_precision;
}
double computeMapNIoULevels(std::vector<Frame> &images,const int classes,const float i_IoU_thresh, const float conf_thresh, const int map_points, const float map_step, const int map_levels, const bool verbose)
double computeMapNIoULevels(std::vector<Frame> &images,const int classes,const float i_IoU_thresh, const float conf_thresh, const int map_points, const float map_step, const int map_levels, const bool verbose, const bool write_on_file, std::string net)
{
double AP = 0;
std::ofstream out_file;
if(write_on_file)
{
out_file.open("map.csv", std::ios_base::app);
out_file<<net<<";";
}
double AP = 0, cur_AP = 0;
float IoU_thresh = i_IoU_thresh;
for(int i=0; i<map_levels; ++i)
{
for(auto& img:images)
for(auto & d:img.det)
d.clear();
AP += computeMap(images,classes,IoU_thresh,conf_thresh,map_points, verbose);
cur_AP = computeMap(images,classes,IoU_thresh,conf_thresh,map_points, verbose);
if(write_on_file)
out_file<<cur_AP<<";";
AP += cur_AP;
IoU_thresh +=map_step;
}
AP/=map_levels;
if(write_on_file)
{
out_file<<AP<<"\n";
out_file.close();
}
return AP;
}
void computeTPFPFN(std::vector<Frame> &images,const int classes,const float IoU_thresh, const float conf_thresh, bool verbose)
void computeTPFPFN(std::vector<Frame> &images,const int classes,const float IoU_thresh, const float conf_thresh, bool verbose, const bool write_on_file, std::string net)
{
std::ofstream out_file;
if(write_on_file)
{
out_file.open("pr.csv", std::ios_base::app);
out_file<<net<<";";
}
std::vector<int> truth_classes_count(classes,0);
std::vector<int> dets_classes_count(classes,0);
std::vector<PR> pr( classes);
std::vector<PR> pr(classes);
for(auto &img:images)
{
@@ -355,6 +380,8 @@ void computeTPFPFN(std::vector<Frame> &images,const int classes,const float IoU_
double avg_precision = 0, avg_recall = 0, f1_score = 0;
int TP = 0, FP = 0, FN = 0;
for(size_t i=0; i<classes; i++)
{
pr[i].precision = (pr[i].tp + pr[i].fp) > 0 ? (double)pr[i].tp / (double)(pr[i].tp +pr[i].fp) : 0;
@@ -364,13 +391,23 @@ void computeTPFPFN(std::vector<Frame> &images,const int classes,const float IoU_
// std::cout<<i<<"\t"<<pr[i].tp<<"\t"<<pr[i].fp<<"\t"<<pr[i].fn<<"\t"<<pr[i].precision<<"\t"<<pr[i].recall<<std::endl;
avg_precision += pr[i].precision;
avg_recall += pr[i].recall;
TP += pr[i].tp;
FP += pr[i].fp;
FN += pr[i].fn;
}
avg_precision /= classes;
avg_recall /= classes;
f1_score = avg_precision + avg_recall > 0 ? 2 * ( avg_precision * avg_recall ) / ( avg_precision + avg_recall ) : 0;
if(write_on_file)
{
out_file<<TP<<";"<<FP<<";"<<FN<<";"<<avg_precision<<";"<<avg_recall<<";"<<f1_score<<"\n";
out_file.close();
}
std::cout<<"avg precision: "<<avg_precision<<"\tavg recall: "<<avg_recall<<"\tavg f1 score:"<<f1_score<<std::endl;
}
}