#ifndef EVALUATION_H #define EVALUATION_H #include #include #include #include #include "tkdnn.h" #include "BoundingBox.h" namespace tk { namespace dnn { struct Frame { std::string lFilename; std::string iFilename; std::vector gt; std::vector det; void print() const; }; struct PR { double precision = 0; double recall = 0; int tp = 0, fp = 0, fn = 0; void print(); }; void readmAPParams( const char* config_filename, int& classes1,float& conf_thresh1 , int& classes2,float& conf_thresh2 , int& classes3,float& conf_thresh3 , int& classes4,float& conf_thresh4 , int& classes5,float& conf_thresh5 ); /** * 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 &images,const int classes, const float IoU_thresh, const float conf_thresh=0.3, const int map_points=101, const bool verbose=false); /** * 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 threshold * @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 considered 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 &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 number 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 considered neural network */ void computeTPFPFN( std::vector &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=""); void printJsonCOCOFormat(std::ofstream *out_file, const std::string image_path, std::vector bbox, const int classes, const int w, const int h); }} #endif /*EVALUATION_H*/