8
8
#include < opencv2/opencv.hpp>
9
9
#include < omp.h>
10
10
// For Original Header
11
- #include " preprocess .hpp"
11
+ #include " augmentation .hpp"
12
12
#include " transforms.hpp"
13
13
14
14
15
15
// ------------------------------------------------------------------
16
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> constructor
16
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> constructor
17
17
// ------------------------------------------------------------------
18
- YOLOPreprocessImpl::YOLOPreprocessImpl (const double flip_rate_, const double scale_rate_, const double blur_rate_, const double brightness_rate_, const double hue_rate_, const double saturation_rate_, const double shift_rate_, const double crop_rate_){
18
+ YOLOAugmentationImpl::YOLOAugmentationImpl (const double jitter_, const double flip_rate_, const double scale_rate_, const double blur_rate_, const double brightness_rate_, const double hue_rate_, const double saturation_rate_, const double shift_rate_, const double crop_rate_){
19
+ this ->jitter = jitter_;
19
20
this ->flip_rate = flip_rate_;
20
21
this ->scale_rate = scale_rate_;
21
22
this ->blur_rate = blur_rate_;
@@ -29,9 +30,9 @@ YOLOPreprocessImpl::YOLOPreprocessImpl(const double flip_rate_, const double sca
29
30
30
31
31
32
// --------------------------------------------------------------------------
32
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> function{deepcopy}
33
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> function{deepcopy}
33
34
// --------------------------------------------------------------------------
34
- void YOLOPreprocessImpl ::deepcopy (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
35
+ void YOLOAugmentationImpl ::deepcopy (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
35
36
data_in1.copyTo (data_out1);
36
37
if (std::get<0 >(data_in2).numel () > 0 ){
37
38
data_out2 = {std::get<0 >(data_in2).clone (), std::get<1 >(data_in2).clone ()};
@@ -44,9 +45,9 @@ void YOLOPreprocessImpl::deepcopy(cv::Mat &data_in1, std::tuple<torch::Tensor, t
44
45
45
46
46
47
// --------------------------------------------------------------------------
47
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> function{random_flip}
48
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> function{random_flip}
48
49
// --------------------------------------------------------------------------
49
- void YOLOPreprocessImpl ::random_flip (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
50
+ void YOLOAugmentationImpl ::random_flip (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
50
51
51
52
size_t i, j, k;
52
53
size_t i_flip;
@@ -88,9 +89,9 @@ void YOLOPreprocessImpl::random_flip(cv::Mat &data_in1, std::tuple<torch::Tensor
88
89
89
90
90
91
// --------------------------------------------------------------------------
91
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> function{random_scale}
92
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> function{random_scale}
92
93
// --------------------------------------------------------------------------
93
- void YOLOPreprocessImpl ::random_scale (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
94
+ void YOLOAugmentationImpl ::random_scale (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
94
95
95
96
size_t width, height;
96
97
std::uniform_real_distribution<double > urand (0.8 , 1.2 );
@@ -115,9 +116,9 @@ void YOLOPreprocessImpl::random_scale(cv::Mat &data_in1, std::tuple<torch::Tenso
115
116
116
117
117
118
// --------------------------------------------------------------------------
118
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> function{random_blur}
119
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> function{random_blur}
119
120
// --------------------------------------------------------------------------
120
- void YOLOPreprocessImpl ::random_blur (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
121
+ void YOLOAugmentationImpl ::random_blur (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
121
122
122
123
size_t ksize;
123
124
std::uniform_int_distribution<int > urand (2 , 5 );
@@ -141,9 +142,9 @@ void YOLOPreprocessImpl::random_blur(cv::Mat &data_in1, std::tuple<torch::Tensor
141
142
142
143
143
144
// --------------------------------------------------------------------------
144
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> function{random_brightness}
145
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> function{random_brightness}
145
146
// --------------------------------------------------------------------------
146
- void YOLOPreprocessImpl ::random_brightness (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
147
+ void YOLOAugmentationImpl ::random_brightness (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
147
148
148
149
cv::Mat data_mid1, HSV, V;
149
150
std::vector<cv::Mat> HSV_vec;
@@ -173,9 +174,9 @@ void YOLOPreprocessImpl::random_brightness(cv::Mat &data_in1, std::tuple<torch::
173
174
174
175
175
176
// --------------------------------------------------------------------------
176
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> function{random_hue}
177
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> function{random_hue}
177
178
// --------------------------------------------------------------------------
178
- void YOLOPreprocessImpl ::random_hue (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
179
+ void YOLOAugmentationImpl ::random_hue (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
179
180
180
181
cv::Mat data_mid1, HSV, H;
181
182
std::vector<cv::Mat> HSV_vec;
@@ -205,9 +206,9 @@ void YOLOPreprocessImpl::random_hue(cv::Mat &data_in1, std::tuple<torch::Tensor,
205
206
206
207
207
208
// --------------------------------------------------------------------------
208
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> function{random_saturation}
209
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> function{random_saturation}
209
210
// --------------------------------------------------------------------------
210
- void YOLOPreprocessImpl ::random_saturation (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
211
+ void YOLOAugmentationImpl ::random_saturation (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
211
212
212
213
cv::Mat data_mid1, HSV, S;
213
214
std::vector<cv::Mat> HSV_vec;
@@ -237,9 +238,9 @@ void YOLOPreprocessImpl::random_saturation(cv::Mat &data_in1, std::tuple<torch::
237
238
238
239
239
240
// --------------------------------------------------------------------------
240
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> function{random_shift}
241
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> function{random_shift}
241
242
// --------------------------------------------------------------------------
242
- void YOLOPreprocessImpl ::random_shift (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
243
+ void YOLOAugmentationImpl ::random_shift (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
243
244
244
245
int i, j, k, i_in, j_in;
245
246
int dx, dy;
@@ -259,8 +260,8 @@ void YOLOPreprocessImpl::random_shift(cv::Mat &data_in1, std::tuple<torch::Tenso
259
260
width = data_in1.cols ;
260
261
height = data_in1.rows ;
261
262
channels = data_in1.channels ();
262
- dx = (int )(urand1 (this ->mt .at (thread_num)) * (double )width * 0.2 );
263
- dy = (int )(urand1 (this ->mt .at (thread_num)) * (double )height * 0.2 );
263
+ dx = (int )(urand1 (this ->mt .at (thread_num)) * (double )width * this -> jitter );
264
+ dy = (int )(urand1 (this ->mt .at (thread_num)) * (double )height * this -> jitter );
264
265
265
266
// (1) Shifting of Image
266
267
data_out1 = cv::Mat (cv::Size (width, height), data_in1.type ());
@@ -343,9 +344,9 @@ void YOLOPreprocessImpl::random_shift(cv::Mat &data_in1, std::tuple<torch::Tenso
343
344
344
345
345
346
// --------------------------------------------------------------------------
346
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> function{random_crop}
347
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> function{random_crop}
347
348
// --------------------------------------------------------------------------
348
- void YOLOPreprocessImpl ::random_crop (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
349
+ void YOLOAugmentationImpl ::random_crop (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
349
350
350
351
int i, j, k, i_in, j_in;
351
352
int dx, dy;
@@ -447,9 +448,9 @@ void YOLOPreprocessImpl::random_crop(cv::Mat &data_in1, std::tuple<torch::Tensor
447
448
448
449
449
450
// -----------------------------------------------------------------
450
- // class{YOLOPreprocessImpl }(transforms::ComposeImpl) -> function{forward}
451
+ // class{YOLOAugmentationImpl }(transforms::ComposeImpl) -> function{forward}
451
452
// -----------------------------------------------------------------
452
- void YOLOPreprocessImpl ::forward (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
453
+ void YOLOAugmentationImpl ::forward (cv::Mat &data_in1, std::tuple<torch::Tensor, torch::Tensor> &data_in2, cv::Mat &data_out1, std::tuple<torch::Tensor, torch::Tensor> &data_out2){
453
454
454
455
// --------------------------------------
455
456
// 1. Parallel Processing Settings
@@ -468,7 +469,7 @@ void YOLOPreprocessImpl::forward(cv::Mat &data_in1, std::tuple<torch::Tensor, to
468
469
size_t thread_num = omp_get_thread_num ();
469
470
470
471
// --------------------------------------
471
- // 2. Pre-processing ( Data Augmentation)
472
+ // 2. Data Augmentation
472
473
// --------------------------------------
473
474
474
475
cv::Mat data_mid1;
0 commit comments