在YOLO fastest的readme里面,有下面一个这样的命令,开始运行这个:
./darknet partial yolo-fastest.cfg yolo-fastest.weights yolo-fastest.conv.109 109
开始没太在意,就照着流程做,后面在看代码的时候对这个地方有了更多认识。这个地方是提取yolo-fastest.weights中0-108层的权重,并保存为文件。
void partial(char *cfgfile, char *weightfile, char *outfile, int max)
{
gpu_index = -1;
network net = parse_network_cfg_custom(cfgfile, 1, 1);
if(weightfile){
load_weights_upto(&net, weightfile, max);
}
*net.seen = 0;
*net.cur_iteration = 0;
save_weights_upto(net, outfile, max);
}
void save_weights_upto(network net, char *filename, int cutoff)
{
......
for(i = 0; i < net.n && i < cutoff; ++i){
layer l = net.layers[i];
......
}
}
后续训练的时候,通过加载这个权重文件,在此基础之上进行训练。