训练图像分类加载图片流程
load_data_augment()实现框架:
load_data_augment()函数做了三件事情:获取图片路径;加载图片;获取图片标签。
加载图片load_image_augment_paths又包括:load_image_color(),random_augment_image(),flip_image(),random_distort_image().
data load_data_augment(char **paths, int n, int m, char **labels, int k, tree *hierarchy, int use_flip, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure)
{
if(m) paths = get_random_paths(paths, n, m);
data d = {0};
d.shallow = 0;
d.X = load_image_augment_paths(paths, n, use_flip, min, max, size, angle, aspect, hue, saturation, exposure);
d.y = load_labels_paths(paths, n, labels, k, hierarchy);
if(m) free(paths);
return d;
}
load_data_augment()参数说明:
data.c中load_thread()调用load_data_augment的代码:
void *load_thread(void *ptr)
{
load_args a = *(struct load_args*)ptr;
load_data_augment(a.paths, a.n, a.m, a.labels, a.classes, a.hierarchy, a.flip, a.min, a.max, a.size, a.angle, a.aspect, a.hue, a.saturation, a.exposure);
。。。。。
}
load_image_color()
load_image_color()中的图像处理函数是resize_image():关于resize_image(),参见darknet预测分类性能提升2.2:GPU加速resize_image()
resize_image()函数的本质,就是按照宽和高的比例进行缩放。
random_augment_image()
random_augment_image()调用说明:
image crop = random_augment_image(im, angle, aspect, min, max, size);
flip_image()
翻转图片
调用:
flip_image(crop);
实现:
void flip_image(image a)
{
int i,j,k;
for(k = 0; k < a.c; ++k){
for(i = 0; i < a.h; ++i){
for(j = 0; j < a.w/2; ++j){
int index = j + a.w*(i + a.h*(k));
int flip = (a.w - j - 1) + a.w*(i + a.h*(k));
float swap = a.data[flip];
a.data[flip] = a.data[index];
a.data[index] = swap;
}
}
}
}
random_distort_image()
调用:
random_distort_image(crop, hue, saturation, exposure);
实现: