From b5936b499abc94c0efffbcc99b5698574b59d860 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Sat, 05 Sep 2015 00:52:44 +0000
Subject: [PATCH] lots of stuff
---
src/darknet.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 103 insertions(+), 10 deletions(-)
diff --git a/src/darknet.c b/src/darknet.c
index 321b5a9..3709ed1 100644
--- a/src/darknet.c
+++ b/src/darknet.c
@@ -5,15 +5,20 @@
#include "parser.h"
#include "utils.h"
#include "cuda.h"
+#include "blas.h"
-#define _GNU_SOURCE
-#include <fenv.h>
+#ifdef OPENCV
+#include "opencv2/highgui/highgui_c.h"
+#endif
extern void run_imagenet(int argc, char **argv);
-extern void run_detection(int argc, char **argv);
+extern void run_yolo(int argc, char **argv);
+extern void run_coco(int argc, char **argv);
extern void run_writing(int argc, char **argv);
extern void run_captcha(int argc, char **argv);
extern void run_nightmare(int argc, char **argv);
+extern void run_dice(int argc, char **argv);
+extern void run_compare(int argc, char **argv);
void change_rate(char *filename, float scale, float add)
{
@@ -29,18 +34,93 @@
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);
}
- net.seen = 0;
+ *net.seen = 0;
save_weights_upto(net, outfile, max);
}
+void stacked(char *cfgfile, char *weightfile, char *outfile)
+{
+ gpu_index = -1;
+ network net = parse_network_cfg(cfgfile);
+ if(weightfile){
+ load_weights(&net, weightfile);
+ }
+ net.seen = 0;
+ save_weights_double(net, outfile);
+}
+
#include "convolutional_layer.h"
-void rgbgr_filters(convolutional_layer l);
+void rescale_net(char *cfgfile, char *weightfile, char *outfile)
+{
+ gpu_index = -1;
+ network net = parse_network_cfg(cfgfile);
+ if(weightfile){
+ load_weights(&net, weightfile);
+ }
+ int i;
+ for(i = 0; i < net.n; ++i){
+ layer l = net.layers[i];
+ if(l.type == CONVOLUTIONAL){
+ rescale_filters(l, 2, -.5);
+ break;
+ }
+ }
+ save_weights(net, outfile);
+}
+
void rgbgr_net(char *cfgfile, char *weightfile, char *outfile)
{
gpu_index = -1;
@@ -66,9 +146,9 @@
load_weights(&net, weightfile);
}
visualize_network(net);
- #ifdef OPENCV
+#ifdef OPENCV
cvWaitKey(0);
- #endif
+#endif
}
int main(int argc, char **argv)
@@ -87,14 +167,23 @@
gpu_index = -1;
#else
if(gpu_index >= 0){
- cudaSetDevice(gpu_index);
+ cudaError_t status = cudaSetDevice(gpu_index);
+ check_error(status);
}
#endif
if(0==strcmp(argv[1], "imagenet")){
run_imagenet(argc, argv);
- } else if (0 == strcmp(argv[1], "detection")){
- run_detection(argc, argv);
+ } else if (0 == strcmp(argv[1], "average")){
+ average(argc, argv);
+ } else if (0 == strcmp(argv[1], "yolo")){
+ run_yolo(argc, argv);
+ } else if (0 == strcmp(argv[1], "coco")){
+ run_coco(argc, argv);
+ } else if (0 == strcmp(argv[1], "compare")){
+ run_compare(argc, argv);
+ } else if (0 == strcmp(argv[1], "dice")){
+ run_dice(argc, argv);
} else if (0 == strcmp(argv[1], "writing")){
run_writing(argc, argv);
} else if (0 == strcmp(argv[1], "test")){
@@ -107,8 +196,12 @@
change_rate(argv[2], atof(argv[3]), (argc > 4) ? atof(argv[4]) : 0);
} else if (0 == strcmp(argv[1], "rgbgr")){
rgbgr_net(argv[2], argv[3], argv[4]);
+ } else if (0 == strcmp(argv[1], "rescale")){
+ rescale_net(argv[2], argv[3], argv[4]);
} else if (0 == strcmp(argv[1], "partial")){
partial(argv[2], argv[3], argv[4], atoi(argv[5]));
+ } else if (0 == strcmp(argv[1], "stacked")){
+ stacked(argv[2], argv[3], argv[4]);
} else if (0 == strcmp(argv[1], "visualize")){
visualize(argv[2], (argc > 3) ? argv[3] : 0);
} else if (0 == strcmp(argv[1], "imtest")){
--
Gitblit v1.10.0