|
如何在caffe中增加实时数据增强?
数据层type: "ImageData"
网络结构的prototxt
transform_param {
mean_value: 127.5
mean_value: 127.5
mean_value: 127.5
scale: 0.0078125
mirror: true # 代表随机的左右翻转
contrast_brightness_adjustment: true # 对比度调节
min_contrast: 0.8 # 最小的对比度乘子(min alpha),默认0.8
max_contrast: 1.2 # 最大对比度乘子(max alpha),默认1.2
max_color_shift: 20
smooth_filtering: true
max_smooth: 6 # 最大平滑乘子,默认6 进行高斯平滑
apply_probability: 0.5
}
报错:"caffe.TransformationParameter" has no field named "contrast_brightness_adjustment".
在MY_caffe_root/src/caffe/proto/caffe.proto 修改:
// Message that stores parameters used to apply transformation
// to the data layer's data
message TransformationParameter {
// For data pre-processing, we can do simple scaling and subtracting the
// data mean, if provided. Note that the mean subtraction is always carried
// out before scaling.
optional float scale = 1 [default = 1];
// Specify if we want to randomly mirror data.
optional bool mirror = 2 [default = false];
// Specify if we would like to randomly crop an image.
optional uint32 crop_size = 3 [default = 0];
// mean_file and mean_value cannot be specified at the same time
optional string mean_file = 4;
// if specified can be repeated once (would subtract it from all the channels)
// or can be repeated the same number of times as channels
// (would subtract them from the corresponding channel)
repeated float mean_value = 5;
// Force the decoded image to have 3 color channels.
optional bool force_color = 6 [default = false];
// Force the decoded image to have 1 color channels.
optional bool force_gray = 7 [default = false];
// Image augmentation dfy加的 数据增强的
// Specify the range of scaling factor for doing resizing
optional float min_scaling_factor = 8 [default = 0.75];
optional float max_scaling_factor = 9 [default = 1.50];
// Specify the angle for doing rotation
optional uint32 max_rotation_angle = 10 [default = 0];
// Specify the contrast, brightness, smooth and color shift for augmentation
optional bool contrast_brightness_adjustment = 11 [default = false];
optional bool smooth_filtering = 12 [default = false];
optional float min_contrast = 14 [default = 0.8];
optional float max_contrast = 15 [default = 1.2];
optional uint32 max_brightness_shift = 16 [default = 5];
optional float max_smooth = 17 [default = 6];
optional uint32 max_color_shift = 20 [default = 0];
// Min side resizing, keep aspect ratio
optional uint32 min_side_min = 13 [default = 0];
optional uint32 min_side_max = 21 [default = 0];
optional uint32 min_side = 22 [default = 0];
optional float apply_probability = 18 [default = 0.5];
optional bool debug_params = 19 [default = false];
}
修改源码:
MY_caffe_root/src/caffe/data_transformer.cpp
阅读源码“data_transformer.cpp”可知,执行顺序是mean(file)、mean(value)、crop、mirror、scale。
如有其它特殊的预处理可在此添加代码
之后 make clean
make all -j8
make test -j8
make pycaffe -j8
第七步:拷贝编译后的libcaffe.so至caffe的虚拟环境
在caffe源码项目下/python目录下 打开终端:
cp -rf caffe/ ~/miniconda3/envs/py2_caffe_source/lib/python2.7/
cp -rf ../.build_release/lib/* ~/miniconda3/envs/py2_caffe_source/lib/
|
|