Refactoring & documentation
Signed-off-by: Micaela Verucchi <micaelaverucchi@gmail.com>
This commit is contained in:
@@ -24,12 +24,6 @@
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
enum networkType_t{
|
||||
NETWORK_YOLO3,
|
||||
NETWORK_MOBILENETSSDLITE,
|
||||
NETWORK_CENTERNET
|
||||
};
|
||||
|
||||
class DetectionNN {
|
||||
|
||||
protected:
|
||||
@@ -52,7 +46,7 @@ class DetectionNN {
|
||||
/**
|
||||
* This method preprocess the image, before feeding it to the NN.
|
||||
*
|
||||
* @param original frame to adapt for inference.
|
||||
* @param frame original frame to adapt for inference.
|
||||
*/
|
||||
virtual void preprocess(cv::Mat &frame) = 0;
|
||||
|
||||
@@ -78,7 +72,8 @@ class DetectionNN {
|
||||
* Method used to inialize the class, allocate memory and compute
|
||||
* needed data.
|
||||
*
|
||||
* @param path to the rt file og the NN.
|
||||
* @param tensor_path path to the rt file og the NN.
|
||||
* @param n_classes number of classes for the given dataset.
|
||||
* @return true if everything is correct, false otherwise.
|
||||
*/
|
||||
virtual bool init(const std::string& tensor_path, const int n_classes=80) = 0;
|
||||
@@ -86,9 +81,10 @@ class DetectionNN {
|
||||
/**
|
||||
* This method performs the whole detection of the NN.
|
||||
*
|
||||
* @param frame to run detection on.
|
||||
* @param if set to true, preprocess, inference and postprocess times
|
||||
* @param frame frame to run detection on.
|
||||
* @param save_times if set to true, preprocess, inference and postprocess times
|
||||
* are saved on a csv file, otherwise not.
|
||||
* @param times pointer to the output stream where to write times
|
||||
*/
|
||||
void update(cv::Mat &frame, bool save_times=false, std::ofstream *times=nullptr){
|
||||
if(!frame.data)
|
||||
@@ -129,11 +125,10 @@ class DetectionNN {
|
||||
/**
|
||||
* Method to draw boundixg boxes and labels on a frame.
|
||||
*
|
||||
* @param orginal frame to draw bounding box on.
|
||||
* @param frame orginal frame to draw bounding box on.
|
||||
* @return frame with boundig boxes.
|
||||
*/
|
||||
cv::Mat draw(cv::Mat &frame)
|
||||
{
|
||||
cv::Mat draw(cv::Mat &frame) {
|
||||
tk::dnn::box b;
|
||||
int x0, w, x1, y0, h, y1;
|
||||
int objClass;
|
||||
|
||||
+74
-22
@@ -8,20 +8,9 @@
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "tkdnn.h"
|
||||
#include "BoundingBox.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
struct BoundingBox : public tk::dnn::box
|
||||
{
|
||||
friend std::ostream& operator<<(std::ostream& os, const BoundingBox& bb);
|
||||
int uniqueTruthIndex = -1;
|
||||
int truthFlag = 0;
|
||||
float maxIoU = 0;
|
||||
|
||||
void clear();
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const BoundingBox& bb);
|
||||
bool boxComparison (const BoundingBox& a,const BoundingBox& b) ;
|
||||
|
||||
struct Frame
|
||||
{
|
||||
@@ -42,19 +31,82 @@ struct PR
|
||||
void print();
|
||||
};
|
||||
|
||||
float boxOverlap(float x1, float w1, float x2, float w2);
|
||||
float boxIntersection(const BoundingBox &a, const BoundingBox &b);
|
||||
float boxUnion(const BoundingBox &a, const BoundingBox &b);
|
||||
float boxIoU(const BoundingBox &a, const BoundingBox &b);
|
||||
void readmAPParams( char* config_filename, int& classes, int& map_points,
|
||||
int& map_levels, float& map_step, float& IoU_thresh,
|
||||
float& conf_thresh, bool& verbose);
|
||||
|
||||
void readmAPParams(char* config_filename, int& classes, int& map_points,
|
||||
int& map_levels, float& map_step, float& IoU_thresh,
|
||||
float& conf_thresh, bool& verbose);
|
||||
/**
|
||||
* This method computes the mean Average Precision for a set of detections and
|
||||
* groundtruths. It returns the mAP for a given IoU threshold, and a given
|
||||
* confidence threshold over all the classes.
|
||||
*
|
||||
* @param images collection of frames on which to compute the metrics
|
||||
* @param classes number of classes of the considered dataset
|
||||
* @param IoU_thresh threshold used to compute Intersection over Union
|
||||
* @param conf_thresh threshold used to filter bounding boxes based on their
|
||||
* confidence (or probability)
|
||||
* @param map_points number of point used to compute the mAP. if 0 is given,
|
||||
* all the recall levels are evaluated, otherwise only
|
||||
* map_point recall levels are used. For COCO evaluation
|
||||
* 101 points are used.
|
||||
* @param verbose is set to true, prints on screen additional info
|
||||
*
|
||||
* @return mAP computed
|
||||
*/
|
||||
double computeMap( std::vector<Frame> &images,const int classes,
|
||||
const float IoU_thresh, const float conf_thresh=0.3,
|
||||
const int map_points=101, const bool verbose=false);
|
||||
|
||||
double computeMap(std::vector<Frame> &images,const int classes,const float IoU_thresh, const float conf_thresh=0.3, const int map_points=101, const bool verbose=false);
|
||||
double computeMapNIoULevels(std::vector<Frame> &images,const int classes,const float i_IoU_thresh=0.5, const float conf_thresh=0.3, const int map_points=101, const float map_step=0.05, const int map_levels=10, const bool verbose=false, const bool write_on_file = false, std::string net = "");
|
||||
|
||||
void computeTPFPFN(std::vector<Frame> &images,const int classes,const float IoU_thresh=0.5, const float conf_thresh=0.3, bool verbose=false, const bool write_on_file=false, std::string net="");
|
||||
/**
|
||||
* This method computes the mean Average Precision for a set of detections and
|
||||
* groundtruths on several IoU thresholds. It is used to compute, for example,
|
||||
* the most used metric in Object Detection, namely the mAP 0.5:0.95, which is
|
||||
* the average among the mAP for IoU level from 0.5 to 0.95 with a step of 0.05.
|
||||
*
|
||||
* @param images collection of frames on which to compute the metrics
|
||||
* @param classes number of classes of the considered dataset
|
||||
* @param IoU_thresh starting threshold used to compute Intersection over Union
|
||||
* @param conf_thresh threshold used to filter bounding boxes based on their
|
||||
* confidence (or probability)
|
||||
* @param map_points number of point used to compute the mAP. if 0 is given,
|
||||
* all the recall levels are evaluated, otherwise only
|
||||
* map_point recall levels are used. For COCO evaluation
|
||||
* 101 points are used.
|
||||
* @param map_step step used to increment IoU theshold
|
||||
* @param map_levels number of IoU step to perform
|
||||
* @param verbose is set to true, prints on screen additional info
|
||||
* @param write_on_file if set to true, the results produced by this function
|
||||
* are written on file
|
||||
* @param net name of the considerd neural network
|
||||
*
|
||||
* @return mAP IoU_tresh:IoU_tresh+map_step*map_levels (e.g. mAP 0.5:0.95 when
|
||||
* map_step=0.05 and map_levels=10)
|
||||
*/
|
||||
double computeMapNIoULevels(std::vector<Frame> &images,const int classes,
|
||||
const float i_IoU_thresh=0.5, const float conf_thresh=0.3,
|
||||
const int map_points=101, const float map_step=0.05,
|
||||
const int map_levels=10, const bool verbose=false,
|
||||
const bool write_on_file = false, std::string net = "");
|
||||
/**
|
||||
* This method computes the numper of True Positive (TP), False Positive (FP),
|
||||
* False Negative (FN), precision, recall and f1-score.
|
||||
* Those values are computer over all the detections, over all the classes.
|
||||
*
|
||||
* @param images collection of frames on which to compute the metrics
|
||||
* @param classes number of classes of the considered dataset
|
||||
* @param IoU_thresh threshold used to compute Intersection over Union
|
||||
* @param conf_thresh threshold used to filter bounding boxes based on their
|
||||
* confidence (or probability)
|
||||
* @param verbose is set to true, prints on screen additional info
|
||||
* @param write_on_file if set to true, the results produced by this function
|
||||
* are written on file
|
||||
* @param net name of the considerd neural network
|
||||
*/
|
||||
void computeTPFPFN( std::vector<Frame> &images,const int classes,
|
||||
const float IoU_thresh=0.5, const float conf_thresh=0.3,
|
||||
bool verbose=false, const bool write_on_file=false,
|
||||
std::string net="");
|
||||
|
||||
}}
|
||||
#endif /*EVALUATION_H*/
|
||||
|
||||
Reference in New Issue
Block a user