From 81751b47dd5d2e63f571f048bdd0a6a2a45617b0 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Mon, 30 Mar 2015 19:04:03 +0000
Subject: [PATCH] ..... and back to coords
---
src/detection.c | 75 +++++++++++++++++++------------------
1 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/src/detection.c b/src/detection.c
index fa8b38c..bdced37 100644
--- a/src/detection.c
+++ b/src/detection.c
@@ -3,11 +3,11 @@
#include "parser.h"
-char *class_names[] = {"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"};
+char *class_names[] = {"bg", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"};
#define AMNT 3
void draw_detection(image im, float *box, int side)
{
- int classes = 20;
+ int classes = 21;
int elems = 4+classes;
int j;
int r, c;
@@ -27,12 +27,11 @@
float blue = get_color(2,class,classes);
j += classes;
- int d = im.w/side;
- int y = r*d+box[j]*d;
- int x = c*d+box[j+1]*d;
- int h = box[j+2]*im.h;
- int w = box[j+3]*im.w;
- draw_box(im, x-w/2, y-h/2, x+w/2, y+h/2,red,green,blue);
+ int left = box[j] *im.w;
+ int right = box[j+1]*im.w;
+ int top = box[j+2]*im.h;
+ int bot = box[j+3]*im.h;
+ draw_box(im, left, top, right, bot, red, green, blue);
}
}
}
@@ -45,11 +44,12 @@
{
char *base = basecfg(cfgfile);
printf("%s\n", base);
- float avg_loss = 1;
+ float avg_loss = -1;
network net = parse_network_cfg(cfgfile);
if(weightfile){
load_weights(&net, weightfile);
}
+ //net.seen = 0;
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net.learning_rate, net.momentum, net.decay);
int imgs = 128;
srand(time(0));
@@ -61,27 +61,29 @@
data train, buffer;
int im_dim = 512;
int jitter = 64;
- int classes = 21;
- pthread_t load_thread = load_data_detection_thread(imgs, paths, plist->size, classes, im_dim, im_dim, 7, 7, jitter, &buffer);
+ int classes = 20;
+ int background = 1;
+ pthread_t load_thread = load_data_detection_thread(imgs, paths, plist->size, classes, im_dim, im_dim, 7, 7, jitter, background, &buffer);
clock_t time;
while(1){
i += 1;
time=clock();
pthread_join(load_thread, 0);
train = buffer;
- load_thread = load_data_detection_thread(imgs, paths, plist->size, classes, im_dim, im_dim, 7, 7, jitter, &buffer);
+ load_thread = load_data_detection_thread(imgs, paths, plist->size, classes, im_dim, im_dim, 7, 7, jitter, background, &buffer);
- /*
- image im = float_to_image(im_dim - jitter, im_dim-jitter, 3, train.X.vals[0]);
- draw_detection(im, train.y.vals[0], 7);
+/*
+ image im = float_to_image(im_dim - jitter, im_dim-jitter, 3, train.X.vals[114]);
+ draw_detection(im, train.y.vals[114], 7);
show_image(im, "truth");
cvWaitKey(0);
- */
+*/
printf("Loaded: %lf seconds\n", sec(clock()-time));
time=clock();
float loss = train_network(net, train);
net.seen += imgs;
+ if (avg_loss < 0) avg_loss = loss;
avg_loss = avg_loss*.9 + loss*.1;
printf("%d: %f, %f avg, %lf seconds, %d images\n", i, loss, avg_loss, sec(clock()-time), i*imgs);
if(i%100==0){
@@ -103,10 +105,15 @@
srand(time(0));
list *plist = get_paths("/home/pjreddie/data/voc/val.txt");
+ //list *plist = get_paths("/home/pjreddie/data/voc/train.txt");
char **paths = (char **)list_to_array(plist);
- int num_output = 1225;
int im_size = 448;
- int classes = 21;
+ int classes = 20;
+ int background = 0;
+ int nuisance = 1;
+ int num_boxes = 7;
+ int per_box = 4+classes+background+nuisance;
+ int num_output = num_boxes*num_boxes*per_box;
int m = plist->size;
int i = 0;
@@ -130,26 +137,20 @@
matrix pred = network_predict_data(net, val);
int j, k, class;
for(j = 0; j < pred.rows; ++j){
- for(k = 0; k < pred.cols; k += classes+4){
-
- /*
- int z;
- for(z = 0; z < 25; ++z) printf("%f, ", pred.vals[j][k+z]);
- printf("\n");
- */
-
- //if (pred.vals[j][k] > .001){
- for(class = 0; class < classes-1; ++class){
- int index = (k)/(classes+4);
- int r = index/7;
- int c = index%7;
- float y = (r + pred.vals[j][k+0+classes])/7.;
- float x = (c + pred.vals[j][k+1+classes])/7.;
- float h = pred.vals[j][k+2+classes];
- float w = pred.vals[j][k+3+classes];
- printf("%d %d %f %f %f %f %f\n", (i-1)*m/splits + j, class, pred.vals[j][k+class], y, x, h, w);
+ for(k = 0; k < pred.cols; k += per_box){
+ float scale = 1.;
+ int index = k/per_box;
+ int row = index / num_boxes;
+ int col = index % num_boxes;
+ if (nuisance) scale = 1.-pred.vals[j][k];
+ for (class = 0; class < classes; ++class){
+ int ci = k+classes+background+nuisance;
+ float y = (pred.vals[j][ci + 0] + row)/num_boxes;
+ float x = (pred.vals[j][ci + 1] + col)/num_boxes;
+ float h = pred.vals[j][ci + 2];
+ float w = pred.vals[j][ci + 3];
+ printf("%d %d %f %f %f %f %f\n", (i-1)*m/splits + j, class, scale*pred.vals[j][k+class+background+nuisance], y, x, h, w);
}
- //}
}
}
--
Gitblit v1.10.0