Fixed drawing mAP

This commit is contained in:
AlexeyAB
2018-12-12 23:20:44 +03:00
parent 6b4dca27d3
commit f0bed8ef73
3 changed files with 23 additions and 23 deletions

View File

@ -25,7 +25,7 @@ image get_image_from_stream_cpp(CvCapture *cap);
#include "http_stream.h"
IplImage* draw_train_chart(float max_img_loss, int max_batches, int number_of_lines, int img_size);
void draw_train_loss(IplImage* img, int img_size, float avg_loss, float max_img_loss, int current_batch, int max_batches, float precision);
void draw_train_loss(IplImage* img, int img_size, float avg_loss, float max_img_loss, int current_batch, int max_batches, float precision, int draw_precision);
#endif
@ -153,7 +153,7 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus,
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %d images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
#ifdef OPENCV
if(!dont_show)
draw_train_loss(img, img_size, avg_loss, max_img_loss, i, net.max_batches, -1);
draw_train_loss(img, img_size, avg_loss, max_img_loss, i, net.max_batches, -1, 0);
#endif // OPENCV
if (i >= (iter_save + 100)) {

View File

@ -26,7 +26,7 @@
#endif
IplImage* draw_train_chart(float max_img_loss, int max_batches, int number_of_lines, int img_size);
void draw_train_loss(IplImage* img, int img_size, float avg_loss, float max_img_loss, int current_batch, int max_batches, float precision);
void draw_train_loss(IplImage* img, int img_size, float avg_loss, float max_img_loss, int current_batch, int max_batches, float precision, int draw_precision);
#define CV_RGB(r, g, b) cvScalar( (b), (g), (r), 0 )
#endif // OPENCV
@ -229,14 +229,16 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
#ifdef OPENCV
if (!dont_show) {
int draw_precision = 0;
int calc_map_for_each = 4 * train_images_num / (net.batch * net.subdivisions);
if (calc_map && (i >= (iter_map + calc_map_for_each) || i == net.max_batches) && i >= net.burn_in && i >= 1000) {
iter_map = i;
mean_average_precision = validate_detector_map(datacfg, cfgfile, weightfile, 0.25, 0.5, &net);
printf("\n mean_average_precision = %f \n", mean_average_precision);
draw_precision = 1;
}
draw_train_loss(img, img_size, avg_loss, max_img_loss, i, net.max_batches, mean_average_precision);
draw_train_loss(img, img_size, avg_loss, max_img_loss, i, net.max_batches, mean_average_precision, draw_precision);
}
#endif // OPENCV

View File

@ -720,7 +720,7 @@ IplImage* draw_train_chart(float max_img_loss, int max_batches, int number_of_li
return img;
}
void draw_train_loss(IplImage* img, int img_size, float avg_loss, float max_img_loss, int current_batch, int max_batches, float precision)
void draw_train_loss(IplImage* img, int img_size, float avg_loss, float max_img_loss, int current_batch, int max_batches, float precision, int draw_precision)
{
int img_offset = 50;
int draw_size = img_size - img_offset;
@ -734,28 +734,26 @@ void draw_train_loss(IplImage* img, int img_size, float avg_loss, float max_img_
cvCircle(img, pt1, 1, CV_RGB(0, 0, 255), CV_FILLED, 8, 0);
// precision
if (precision >= 0) {
if (draw_precision) {
static float old_precision = 0;
static iteration_old = 0;
static int iteration_old = 0;
if(iteration_old == 0) cvPutText(img, "mAP%", cvPoint(0, 12), &font, CV_RGB(255, 0, 0));
if (old_precision != precision) {
cvLine(img,
cvPoint(img_offset + draw_size * (float)iteration_old / max_batches, draw_size * (1 - old_precision)),
cvPoint(img_offset + draw_size * (float)current_batch / max_batches, draw_size * (1 - precision)),
CV_RGB(255, 0, 0), 1, 8, 0);
cvLine(img,
cvPoint(img_offset + draw_size * (float)iteration_old / max_batches, draw_size * (1 - old_precision)),
cvPoint(img_offset + draw_size * (float)current_batch / max_batches, draw_size * (1 - precision)),
CV_RGB(255, 0, 0), 1, 8, 0);
old_precision = precision;
iteration_old = current_batch;
sprintf(char_buff, "%2.0f%% ", precision * 100);
CvFont font3;
cvInitFont(&font3, CV_FONT_HERSHEY_COMPLEX_SMALL, 0.7, 0.7, 0, 5, CV_AA);
cvPutText(img, char_buff, cvPoint(pt1.x - 30, draw_size * (1 - precision) + 15), &font3, CV_RGB(255, 255, 255));
old_precision = precision;
iteration_old = current_batch;
sprintf(char_buff, "%2.0f%% ", precision * 100);
CvFont font3;
cvInitFont(&font3, CV_FONT_HERSHEY_COMPLEX_SMALL, 0.7, 0.7, 0, 5, CV_AA);
cvPutText(img, char_buff, cvPoint(pt1.x - 30, draw_size * (1 - precision) + 15), &font3, CV_RGB(255, 255, 255));
CvFont font2;
cvInitFont(&font2, CV_FONT_HERSHEY_COMPLEX_SMALL, 0.7, 0.7, 0, 1, CV_AA);
cvPutText(img, char_buff, cvPoint(pt1.x - 30, draw_size * (1 - precision) + 15), &font2, CV_RGB(200, 0, 0));
}
cvPutText(img, "mAP%", cvPoint(0, 12), &font, CV_RGB(255, 0, 0));
CvFont font2;
cvInitFont(&font2, CV_FONT_HERSHEY_COMPLEX_SMALL, 0.7, 0.7, 0, 1, CV_AA);
cvPutText(img, char_buff, cvPoint(pt1.x - 30, draw_size * (1 - precision) + 15), &font2, CV_RGB(200, 0, 0));
}
sprintf(char_buff, "current avg loss = %2.4f iteration = %d", avg_loss, current_batch);