【darknet学习笔记】修改训练图像分类加载数据类型

修改darknet源代码,使其能够直接训练二进制图像数据

目录

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_data_augment源代码解析


classifier.c文件中数据类型为CLASSIFICATION_DATA

 args.type = CLASSIFICATION_DATA;

data.c文件中的load_thread()函数中调用load_data_augment()函数:

void *load_thread(void *ptr)
{
    //srand(time(0));
    //printf("Loading data: %d\n", random_gen());
    load_args a = *(struct load_args*)ptr;
    if(a.exposure == 0) a.exposure = 1;
    if(a.saturation == 0) a.saturation = 1;
    if(a.aspect == 0) a.aspect = 1;

    if (a.type == OLD_CLASSIFICATION_DATA){
        *a.d = load_data_old(a.paths, a.n, a.m, a.labels, a.classes, a.w, a.h);
    } else if (a.type == CLASSIFICATION_DATA){
        *a.d = 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);
    } else if (a.type == SUPER_DATA){

load_data_augment()调用参数说明

 args.paths = paths;
 args.n = imgs;
 args.m = train_images_num;
 args.labels = labels;

 args.classes = classes;
 args.hierarchy = net.hierarchy;
 
 args.flip = net.flip;
 args.min = net.min_crop;
 args.max = net.max_crop;

 args.size = net.w > net.h ? net.w : net.h;

 args.angle = net.angle;
 args.aspect = net.aspect;
 args.hue = net.hue; 
 args.saturation = net.saturation;
 args.exposure = net.exposure;

a.paths,

list *options = read_data_cfg(datacfg);
char *train_list = option_find_str(options, "train", "data/train.list");
list *plist = get_paths(train_list);
char **paths = (char **)list_to_array(plist);
args.paths = paths;

train_classifier()函数调用参数说明已经知道,datacfg,数据说明文件路径,图像分类数据说明文件一般命名为meta.data。

paths字符串数组,是meta.data文件夹下train后面对应list文件所包含所有图片路径,train默认值为“data/train.list”。

a.n,

int subdivs = option_find_int(options, "subdivisions",1);
net->subdivisions = subdivs;
net->batch = option_find_int(options, "batch",1);
int imgs = net.batch * net.subdivisions * ngpus;
args.n = imgs;

ngpus由train指令的-ngpus命令指定,如果没有指定该命令,ngpus默认为1。

batch,subdivisions为cfg文件指定batch和subdivisions。cfg文件中batch和subdivisions代表的含义,参看以前的博文:

a.m,

list *options = read_data_cfg(datacfg);
char *train_list = option_find_str(options, "train", "data/train.list");
list *plist = get_paths(train_list);
int train_images_num = plist->size; 
args.m = train_images_num;

用于分类的图像张数,该值等于datacfg路径所指文件meta.data文件中train字段对应list中的图片张数。

a.labels,

 list *options = read_data_cfg(datacfg);
 char *label_list = option_find_str(options, "labels", "data/labels.list");
 char **labels = get_labels(label_list);
 args.labels = labels;

a.classes,

  list *options = read_data_cfg(datacfg);
  int classes = option_find_int(options, "classes", 2);
  args.classes = classes;

分类任务的类别个数,例如二分类任务,此处classes=2。

a.hierarchy,

 }else if(lt == SOFTMAX){
            l = parse_softmax(options, params);
            net.hierarchy = l.softmax_tree;
。。。。。。
args.hierarchy = net.hierarchy;

cfg文件中每一层结构前有一个[]标记起来的层名,例如sofmax网络层参数最前面会有一行[softmax]

部分cfg文件参数如下:

[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky

[convolutional]
filters=2
size=1
stride=1
pad=1
activation=linear

[avgpool]

[softmax]
groups=1

每一段代表一个网络层,每一段第一行类似[convolutional]标识该网络层的类别,紧接着是该网络层的参数。[convolutional]标识下面这一段为一个卷积层参数。

回归到net.hierarchy,hirerarchy中文意思为层次关系,那么net.hierarchy表示如果此前网络层为softmax层,hirerarchy指向一个softmax_tree。

a.flip,

  net->flip = option_find_int_quiet(options, "flip", 1);
  args.flip = net.flip;

flip就是cfg网络结构文件中flip参数,flip中文意思翻转开关

a.min,

net->min_crop = option_find_int_quiet(options, "min_crop",net->w);
args.min = net.min_crop;

a.max,

 net->max_crop = option_find_int_quiet(options, "max_crop",net->w*2);
 args.max = net.max_crop;

a.size,

 net->h = option_find_int_quiet(options, "height",0);
 net->w = option_find_int_quiet(options, "width",0);
 args.size = net.w > net.h ? net.w : net.h;

a.angle,

net->angle = option_find_float_quiet(options, "angle", 0);
args.angle = net.angle;

角度

a.aspect,

 net->aspect = option_find_float_quiet(options, "aspect", 1);
 args.aspect = net.aspect;

方位

a.hue,

net->hue = option_find_float_quiet(options, "hue", 0);
args.hue = net.hue;

色调

a.saturation,

 net->saturation = option_find_float_quiet(options, "saturation", 1);
 args.saturation = net.saturation;

饱和度

a.exposure

 net->exposure = option_find_float_quiet(options, "exposure", 1);
 args.exposure = net.exposure;

 曝光时间

总结

参数名

含义

相关文件

文件中变量

默认值

a.paths

tain变量对应list中包含所有图片路径

Metal.data

train

a.n

a.n=batch * subdivisions * ngpus

*.cfg

batch和subdivisions

a.m

tain变量对应list中包含所有图片总数

metal.data

train

a.labels

分类任务涉及类别

label

a.classes

分类任务的类别个数

classes

a.hierarchy

如果此前网络层为softmax层,hirerarchy指向一个softmax_tree。

*.cfg

softmax

a.flip

 

flip

1

a.min

还看不出来

min_crop,width

Net.w即width

a.max

还看不出来

max_crop,width

Net.w*2

a.size

a.size = net.w > net.h ? net.w : net.h

Width,height

0

a.angle

还看不出来

angle

0

a.aspect

还看不出来

aspect

1

a.hue

还看不出来

hue

0

a.saturation

还看不出来

saturation

1

a.exposure

还看不出来

exposure

1

load_data_augment源代码解析

data.c中的load_data_augment()代码:

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;
}

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

haimianjie2012

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值