Added Darknet reference model

This commit is contained in:
Joseph Redmon 2015-08-17 09:00:12 -07:00
parent 2afa376bb3
commit 741ada451c
2 changed files with 206 additions and 2 deletions

154
cfg/darknet.cfg Normal file
View File

@ -0,0 +1,154 @@
[net]
batch=128
subdivisions=1
height=256
width=256
channels=3
learning_rate=0.01
momentum=0.9
decay=0.0005
[crop]
crop_height=224
crop_width=224
flip=1
angle=0
saturation=1
exposure=1
[convolutional]
filters=16
size=3
stride=1
pad=1
activation=leaky
#[convolutional]
#filters=16
#size=3
#stride=1
#pad=1
#activation=leaky
[maxpool]
stride=2
size=2
[convolutional]
filters=32
size=3
stride=1
pad=1
activation=leaky
#[convolutional]
#filters=32
#size=3
#stride=1
#pad=1
#activation=leaky
[maxpool]
stride=2
size=2
[convolutional]
filters=64
size=3
stride=1
pad=1
activation=leaky
#[convolutional]
#filters=64
#size=3
#stride=1
#pad=1
#activation=leaky
[maxpool]
stride=2
size=2
[convolutional]
filters=128
size=3
stride=1
pad=1
activation=leaky
#[convolutional]
#filters=128
#size=3
#stride=1
#pad=1
#activation=leaky
[maxpool]
stride=2
size=2
[convolutional]
filters=256
size=3
stride=1
pad=1
activation=leaky
#[convolutional]
#filters=256
#size=3
#stride=1
#pad=1
#activation=leaky
[maxpool]
stride=2
size=2
[convolutional]
filters=512
size=3
stride=1
pad=1
activation=leaky
#[convolutional]
#filters=512
#size=3
#stride=1
#pad=1
#activation=leaky
[maxpool]
stride=2
size=2
[convolutional]
filters=1024
size=3
stride=1
pad=1
activation=leaky
#[convolutional]
#filters=1024
#size=3
#stride=1
#pad=1
#activation=leaky
[avgpool]
[dropout]
probability=.5
[connected]
output=1000
activation=leaky
[softmax]
[cost]
type=sse

View File

@ -5,6 +5,7 @@
#include "parser.h"
#include "utils.h"
#include "cuda.h"
#include "blas.h"
#ifdef OPENCV
#include "opencv2/highgui/highgui_c.h"
@ -33,8 +34,55 @@ void change_rate(char *filename, float scale, float add)
fclose(fp);
}
void average(int argc, char *argv[])
{
char *cfgfile = argv[2];
char *outfile = argv[3];
gpu_index = -1;
network net = parse_network_cfg(cfgfile);
network sum = parse_network_cfg(cfgfile);
char *weightfile = argv[4];
load_weights(&sum, weightfile);
int i, j;
int n = argc - 5;
for(i = 0; i < n; ++i){
weightfile = argv[i+5];
load_weights(&net, weightfile);
for(j = 0; j < net.n; ++j){
layer l = net.layers[j];
layer out = sum.layers[j];
if(l.type == CONVOLUTIONAL){
int num = l.n*l.c*l.size*l.size;
axpy_cpu(l.n, 1, l.biases, 1, out.biases, 1);
axpy_cpu(num, 1, l.filters, 1, out.filters, 1);
}
if(l.type == CONNECTED){
axpy_cpu(l.outputs, 1, l.biases, 1, out.biases, 1);
axpy_cpu(l.outputs*l.inputs, 1, l.weights, 1, out.weights, 1);
}
}
}
n = n+1;
for(j = 0; j < net.n; ++j){
layer l = sum.layers[j];
if(l.type == CONVOLUTIONAL){
int num = l.n*l.c*l.size*l.size;
scal_cpu(l.n, 1./n, l.biases, 1);
scal_cpu(num, 1./n, l.filters, 1);
}
if(l.type == CONNECTED){
scal_cpu(l.outputs, 1./n, l.biases, 1);
scal_cpu(l.outputs*l.inputs, 1./n, l.weights, 1);
}
}
save_weights(sum, outfile);
}
void partial(char *cfgfile, char *weightfile, char *outfile, int max)
{
gpu_index = -1;
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights_upto(&net, weightfile, max);
@ -114,6 +162,8 @@ int main(int argc, char **argv)
if(0==strcmp(argv[1], "imagenet")){
run_imagenet(argc, argv);
} else if (0 == strcmp(argv[1], "average")){
average(argc, argv);
} else if (0 == strcmp(argv[1], "detection")){
run_detection(argc, argv);
} else if (0 == strcmp(argv[1], "yolo")){