data augmentation horizontal flip
shimhyeonwoo opened this issue · comments
I found there is a parameter 'mirror' in data augmentation layer.
I guess it's about horizontal flip of image and flow data.
( I hope to add horizontal flip augmenting input data, during training)
However, I can't use it properly.
I tried to understand the source code several days, but i couldn't.
If I want add horizontal flip augmentation during training, how can i edit the augmentation layer parameter?
Thank you.
Hi,
to use the horizontal flip augmentation, add this to your augmentation layer's prototxt, in the augmentation_param
section:
mirror {
rand_type: "uniform_bernoulli"
exp: false
mean: XXX
spread: XXX
prob: 1.0
}
You might also need to add it to the GenerateAugmentationParameters
layer. Note that you need to specify the "XXX" parameters which determine when this augmentation triggers.
I really appreciate for your help!
About adjusting "XXX" parameters...
refering to "message AugmentationCoeff" in "caffe.proto", the default value of "float mirror" is zero:
message AugmentationCoeff {
// Spatial
optional float mirror = 1 [default = 0];
optional float dx = 2 [default = 0];
optional float dy = 3 [default = 0];
optional float angle = 4 [default = 0];
optional float zoom_x = 5 [default = 1];
optional float zoom_y = 6 [default = 1];
And line 138, in "augmentation_layer_base.cpp", it seems I can use mirror augmentation when "float mirror" is not zero. maybe it means, when the "mirror" is not zero it always flip data :
// move the origin and mirror
if (coeff.mirror()) {
x1 = - static_cast<Dtype>(x) + .5 * static_cast<Dtype>(cropped_width);
y1 = static_cast<Dtype>(y) - .5 * static_cast<Dtype>(cropped_height);
} else {
x1 = static_cast<Dtype>(x) - .5 * static_cast<Dtype>(cropped_width);
y1 = static_cast<Dtype>(y) - .5 * static_cast<Dtype>(cropped_height);
}
If my opinion were right, and I want use horizontal flip with only, for example, 30%, how about use the parameter like this?
mirror {
rand_type: "uniform_bernoulli"
exp: false
mean: 1
spread: 0
prob: 0.3
}
or
mirror {
rand_type: "uniform_bernoulli"
exp: false
mean: 0
spread: 0
prob: 0.7
}
I want use horizontal flip with only, for example, 30%
You can choose from different distributions; check rng.cpp for a list and the implementations. If you want a fixed 30% probability for a binary decision, you might want to use the bernoulli
variant with the prob
parameter set to 0.3.
Oh, there is more appropriate distribution.
mirror {
rand_type: "bernoulli"
prob: 0.3
}
Thank you.