From b6a824df39d1a79f15916d2c11133ce27bc0ab06 Mon Sep 17 00:00:00 2001 From: AlexeyAB Date: Mon, 8 Apr 2019 02:42:44 +0300 Subject: [PATCH] Minor fix --- README.md | 4 ++++ src/blas.c | 2 +- src/http_stream.cpp | 3 +++ src/image_opencv.cpp | 11 +++++++---- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0a0f43a0..e5a51ed9 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,8 @@ Training Yolo v3: * change line batch to [`batch=64`](https://github.com/AlexeyAB/darknet/blob/0039fd26786ab5f71d5af725fc18b3f521e7acfd/cfg/yolov3.cfg#L3) * change line subdivisions to [`subdivisions=8`](https://github.com/AlexeyAB/darknet/blob/0039fd26786ab5f71d5af725fc18b3f521e7acfd/cfg/yolov3.cfg#L4) + * change line max_batches to (`classes*2000`), f.e. [`max_batches=6000`](https://github.com/AlexeyAB/darknet/blob/0039fd26786ab5f71d5af725fc18b3f521e7acfd/cfg/yolov3.cfg#L20) if you train for 3 classes + * change line steps to 80% and 90% of max_batches, f.e. [`steps=4800,5400`](https://github.com/AlexeyAB/darknet/blob/0039fd26786ab5f71d5af725fc18b3f521e7acfd/cfg/yolov3.cfg#L22) * change line `classes=80` to your number of objects in each of 3 `[yolo]`-layers: * https://github.com/AlexeyAB/darknet/blob/0039fd26786ab5f71d5af725fc18b3f521e7acfd/cfg/yolov3.cfg#L610 * https://github.com/AlexeyAB/darknet/blob/0039fd26786ab5f71d5af725fc18b3f521e7acfd/cfg/yolov3.cfg#L696 @@ -467,6 +469,8 @@ Or just train with `-map` flag: So you will see mAP-chart (red-line) in the Loss-chart Window. mAP will be calculated for each 4 Epochs using `valid=valid.txt` file that is specified in `obj.data` file (`1 Epoch = images_in_train_txt / batch` iterations) +(to change the max x-axis value - change [`max_batches=`](https://github.com/AlexeyAB/darknet/blob/0039fd26786ab5f71d5af725fc18b3f521e7acfd/cfg/yolov3.cfg#L20) parameter to `2000*classes`, f.e. `max_batches=6000` for 3 classes) + ![loss_chart_map_chart](https://hsto.org/webt/yd/vl/ag/ydvlagutof2zcnjodstgroen8ac.jpeg) Example of custom object detection: `darknet.exe detector test data/obj.data yolo-obj.cfg yolo-obj_8000.weights` diff --git a/src/blas.c b/src/blas.c index 09033e25..c68b64c3 100644 --- a/src/blas.c +++ b/src/blas.c @@ -234,7 +234,7 @@ void smooth_l1_cpu(int n, float *pred, float *truth, float *delta, float *error) } else { error[i] = 2*abs_val - 1; - delta[i] = (diff < 0) ? 1 : -1; + delta[i] = (diff > 0) ? 1 : -1; } } } diff --git a/src/http_stream.cpp b/src/http_stream.cpp index 550beb78..3ce2a212 100644 --- a/src/http_stream.cpp +++ b/src/http_stream.cpp @@ -489,11 +489,14 @@ public: }; // ---------------------------------------- +static std::mutex mtx_mjpeg; + struct mat_cv : cv::Mat { int a[0]; }; void send_mjpeg(mat_cv* mat, int port, int timeout, int quality) { try { + std::lock_guard lock(mtx_mjpeg); static MJPG_sender wri(port, timeout, quality); //cv::Mat mat = cv::cvarrToMat(ipl); wri.write(*mat); diff --git a/src/image_opencv.cpp b/src/image_opencv.cpp index ead2ee72..b3c5ae43 100644 --- a/src/image_opencv.cpp +++ b/src/image_opencv.cpp @@ -862,7 +862,7 @@ void draw_detections_cv_v3(mat_cv* mat, detection *dets, int num, float thresh, } } if (class_id >= 0) { - int width = show_img->rows * .006; + int width = std::max(1.0f, show_img->rows * .002f); //if(0){ //width = pow(prob, 1./2.)*10+1; @@ -908,7 +908,8 @@ void draw_detections_cv_v3(mat_cv* mat, detection *dets, int num, float thresh, //int b_height = bot - top; //sprintf(labelstr, "%d x %d - w: %d, h: %d", b_x_center, b_y_center, b_width, b_height); - float const font_size = show_img->rows / 1200.F; + float const font_size = show_img->rows / 1000.F; + cv::Size const text_size = cv::getTextSize(labelstr, cv::FONT_HERSHEY_COMPLEX_SMALL, font_size, 1, 0); CvPoint pt1, pt2, pt_text, pt_text_bg1, pt_text_bg2; pt1.x = left; pt1.y = top; @@ -917,8 +918,9 @@ void draw_detections_cv_v3(mat_cv* mat, detection *dets, int num, float thresh, pt_text.x = left; pt_text.y = top - 4;// 12; pt_text_bg1.x = left; - pt_text_bg1.y = top - (3 + 25 * font_size); + pt_text_bg1.y = top - (1 + 18 * font_size); pt_text_bg2.x = right; + if ((right - left) < text_size.width) pt_text_bg2.x = left + text_size.width; pt_text_bg2.y = top; CvScalar color; color.val[0] = red * 256; @@ -952,7 +954,8 @@ void draw_detections_cv_v3(mat_cv* mat, detection *dets, int num, float thresh, cv::rectangle(*show_img, pt_text_bg1, pt_text_bg2, color, width, 8, 0); cv::rectangle(*show_img, pt_text_bg1, pt_text_bg2, color, CV_FILLED, 8, 0); // filled cv::Scalar black_color = CV_RGB(0,0,0); - cv::putText(*show_img, labelstr, pt_text, CV_FONT_HERSHEY_SIMPLEX, font_size, black_color, font_size * 3, CV_AA); + cv::putText(*show_img, labelstr, pt_text, CV_FONT_HERSHEY_COMPLEX_SMALL, font_size, black_color, 2*font_size, CV_AA); + // CV_FONT_HERSHEY_COMPLEX_SMALL, CV_FONT_HERSHEY_SIMPLEX } } if (ext_output) {