From 6e736339259142c87bd86fd7362eac4e6043a8cc Mon Sep 17 00:00:00 2001 From: AlexeyAB Date: Tue, 29 Oct 2019 14:53:57 +0300 Subject: [PATCH] Fixed Blur and Try to use new Assisted Excitation. --- src/convolutional_kernels.cu | 33 +++++++++++++++++++++++---------- src/data.c | 2 +- src/image_opencv.cpp | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/convolutional_kernels.cu b/src/convolutional_kernels.cu index cb5a1b99..0b94dd29 100644 --- a/src/convolutional_kernels.cu +++ b/src/convolutional_kernels.cu @@ -978,10 +978,14 @@ void assisted_excitation_forward_gpu(convolutional_layer l, network_state state) float alpha = (1 + cos(3.141592 * iteration_num / state.net.max_batches)) / 2; //float alpha = (1 + cos(3.141592 * iteration_num / state.net.max_batches)); - if (l.assisted_excitation > 1) { - if (iteration_num < state.net.burn_in) alpha = 0; - else if (iteration_num > l.assisted_excitation) alpha = 0; - else alpha = (1 + cos(3.141592 * iteration_num / l.assisted_excitation)) / 2; + if (l.assisted_excitation == 1) { + if (iteration_num > state.net.max_batches / 2) return; + } + else { + if (iteration_num < state.net.burn_in) return; + else if (iteration_num > l.assisted_excitation) return; + else + alpha = (1 + cos(3.141592 * iteration_num / (state.net.burn_in + l.assisted_excitation))) / 2; // from 1 to 0 } //printf("\n epoch = %f, alpha = %f, seen = %d, max_batches = %d, train_images_num = %d \n", @@ -1011,11 +1015,19 @@ void assisted_excitation_forward_gpu(convolutional_layer l, network_state state) for (t = 0; t < state.net.num_boxes; ++t) { box truth = float_to_box_stride(truth_cpu + t*(4 + 1) + b*l.truths, 1); if (!truth.x) break; // continue; - - int left = floor((truth.x - truth.w / 2) * l.out_w); - int right = ceil((truth.x + truth.w / 2) * l.out_w); - int top = floor((truth.y - truth.h / 2) * l.out_h); - int bottom = ceil((truth.y + truth.h / 2) * l.out_h); + float beta = 1 - alpha; // from 0 to 1 + float dw = (1 - truth.w) * beta; + float dh = (1 - truth.h) * beta; + //printf(" alpha = %f, beta = %f, truth.w = %f, dw = %f, tw+dw = %f, l.out_w = %d \n", alpha, beta, truth.w, dw, truth.w+dw, l.out_w); + + int left = floor((truth.x - (dw + truth.w) / 2) * l.out_w); + int right = ceil((truth.x + (dw + truth.w) / 2) * l.out_w); + int top = floor((truth.y - (dh + truth.h) / 2) * l.out_h); + int bottom = ceil((truth.y + (dh + truth.h) / 2) * l.out_h); + if (left < 0) left = 0; + if (top < 0) top = 0; + if (right > l.out_w) right = l.out_w; + if (bottom > l.out_h) bottom = l.out_h; for (w = left; w <= right; w++) { for (h = top; h < bottom; h++) { @@ -1035,7 +1047,8 @@ void assisted_excitation_forward_gpu(convolutional_layer l, network_state state) //CHECK_CUDA(cudaPeekAtLastError()); // calc new output - assisted_activation2_gpu(alpha, l.output_gpu, l.gt_gpu, l.a_avg_gpu, l.out_w * l.out_h, l.out_c, l.batch); + assisted_activation2_gpu(1, l.output_gpu, l.gt_gpu, l.a_avg_gpu, l.out_w * l.out_h, l.out_c, l.batch); // AE3: gt increases (beta = 1 - alpha = 0) + //assisted_activation2_gpu(alpha, l.output_gpu, l.gt_gpu, l.a_avg_gpu, l.out_w * l.out_h, l.out_c, l.batch); //assisted_activation_gpu(alpha, l.output_gpu, l.gt_gpu, l.a_avg_gpu, l.out_w * l.out_h, l.out_c, l.batch); //cudaStreamSynchronize(get_cuda_stream()); //CHECK_CUDA(cudaPeekAtLastError()); diff --git a/src/data.c b/src/data.c index 2780a82c..622e401e 100644 --- a/src/data.c +++ b/src/data.c @@ -927,7 +927,7 @@ data load_data_detection(int n, char **paths, int m, int w, int h, int c, int bo int min_w_h = fill_truth_detection(filename, boxes, truth, classes, flip, dx, dy, 1. / sx, 1. / sy, w, h); - if (min_w_h/4 < blur && blur > 1) blur = min_w_h / 4; // disable blur if one of the objects is too small + if (min_w_h / 8 < blur && blur > 1) blur = min_w_h / 8; // disable blur if one of the objects is too small image ai = image_data_augmentation(src, w, h, pleft, ptop, swidth, sheight, flip, dhue, dsat, dexp, blur, boxes, d.y.vals[i]); diff --git a/src/image_opencv.cpp b/src/image_opencv.cpp index a9d3b560..912a0b1b 100644 --- a/src/image_opencv.cpp +++ b/src/image_opencv.cpp @@ -1198,7 +1198,7 @@ image image_data_augmentation(mat_cv* mat, int w, int h, cv::Mat dst(sized.size(), sized.type()); if (blur == 1) { //cv::GaussianBlur(sized, dst, cv::Size(31, 31), 0); - cv::bilateralFilter(sized, dst, 31, 75, 75); + cv::bilateralFilter(sized, dst, 17, 75, 75); } else { int ksize = (blur / 2) * 2 + 1;