hi
Joseph Redmon
2016-06-23 ae43c2bc32fbb838bfebeeaf2c2b058ccab5c83c
hi
101 files modified
2 files added
2 files deleted
644 ■■■■■ changed files
Makefile 4 ●●●● patch | view | raw | blame | history
cfg/yolo-coco.cfg 4 ●●●● patch | view | raw | blame | history
cfg/yolo.cfg 15 ●●●● patch | view | raw | blame | history
data/labels/aeroplane.png patch | view | raw | blame | history
data/labels/airplane.png patch | view | raw | blame | history
data/labels/apple.png patch | view | raw | blame | history
data/labels/backpack.png patch | view | raw | blame | history
data/labels/banana.png patch | view | raw | blame | history
data/labels/baseball bat.png patch | view | raw | blame | history
data/labels/baseball glove.png patch | view | raw | blame | history
data/labels/bear.png patch | view | raw | blame | history
data/labels/bed.png patch | view | raw | blame | history
data/labels/bench.png patch | view | raw | blame | history
data/labels/bicycle.png patch | view | raw | blame | history
data/labels/bird.png patch | view | raw | blame | history
data/labels/boat.png patch | view | raw | blame | history
data/labels/book.png patch | view | raw | blame | history
data/labels/bottle.png patch | view | raw | blame | history
data/labels/bowl.png patch | view | raw | blame | history
data/labels/broccoli.png patch | view | raw | blame | history
data/labels/bus.png patch | view | raw | blame | history
data/labels/cake.png patch | view | raw | blame | history
data/labels/car.png patch | view | raw | blame | history
data/labels/carrot.png patch | view | raw | blame | history
data/labels/cat.png patch | view | raw | blame | history
data/labels/cell phone.png patch | view | raw | blame | history
data/labels/chair.png patch | view | raw | blame | history
data/labels/clock.png patch | view | raw | blame | history
data/labels/couch.png patch | view | raw | blame | history
data/labels/cow.png patch | view | raw | blame | history
data/labels/cup.png patch | view | raw | blame | history
data/labels/dining table.png patch | view | raw | blame | history
data/labels/diningtable.png patch | view | raw | blame | history
data/labels/dog.png patch | view | raw | blame | history
data/labels/donut.png patch | view | raw | blame | history
data/labels/elephant.png patch | view | raw | blame | history
data/labels/fire hydrant.png patch | view | raw | blame | history
data/labels/fork.png patch | view | raw | blame | history
data/labels/frisbee.png patch | view | raw | blame | history
data/labels/giraffe.png patch | view | raw | blame | history
data/labels/hair drier.png patch | view | raw | blame | history
data/labels/handbag.png patch | view | raw | blame | history
data/labels/horse.png patch | view | raw | blame | history
data/labels/hot dog.png patch | view | raw | blame | history
data/labels/keyboard.png patch | view | raw | blame | history
data/labels/kite.png patch | view | raw | blame | history
data/labels/knife.png patch | view | raw | blame | history
data/labels/laptop.png patch | view | raw | blame | history
data/labels/microwave.png patch | view | raw | blame | history
data/labels/motorbike.png patch | view | raw | blame | history
data/labels/motorcycle.png patch | view | raw | blame | history
data/labels/mouse.png patch | view | raw | blame | history
data/labels/orange.png patch | view | raw | blame | history
data/labels/oven.png patch | view | raw | blame | history
data/labels/parking meter.png patch | view | raw | blame | history
data/labels/person.png patch | view | raw | blame | history
data/labels/pizza.png patch | view | raw | blame | history
data/labels/potted plant.png patch | view | raw | blame | history
data/labels/pottedplant.png patch | view | raw | blame | history
data/labels/refrigerator.png patch | view | raw | blame | history
data/labels/remote.png patch | view | raw | blame | history
data/labels/sandwich.png patch | view | raw | blame | history
data/labels/scissors.png patch | view | raw | blame | history
data/labels/sheep.png patch | view | raw | blame | history
data/labels/sink.png patch | view | raw | blame | history
data/labels/skateboard.png patch | view | raw | blame | history
data/labels/skis.png patch | view | raw | blame | history
data/labels/snowboard.png patch | view | raw | blame | history
data/labels/sofa.png patch | view | raw | blame | history
data/labels/spoon.png patch | view | raw | blame | history
data/labels/sports ball.png patch | view | raw | blame | history
data/labels/stop sign.png patch | view | raw | blame | history
data/labels/suitcase.png patch | view | raw | blame | history
data/labels/surfboard.png patch | view | raw | blame | history
data/labels/teddy bear.png patch | view | raw | blame | history
data/labels/tennis racket.png patch | view | raw | blame | history
data/labels/tie.png patch | view | raw | blame | history
data/labels/toaster.png patch | view | raw | blame | history
data/labels/toilet.png patch | view | raw | blame | history
data/labels/toothbrush.png patch | view | raw | blame | history
data/labels/traffic light.png patch | view | raw | blame | history
data/labels/train.png patch | view | raw | blame | history
data/labels/truck.png patch | view | raw | blame | history
data/labels/tv.png patch | view | raw | blame | history
data/labels/tvmonitor.png patch | view | raw | blame | history
data/labels/umbrella.png patch | view | raw | blame | history
data/labels/vase.png patch | view | raw | blame | history
data/labels/wine glass.png patch | view | raw | blame | history
data/labels/zebra.png patch | view | raw | blame | history
src/activation_kernels.cu 16 ●●●●● patch | view | raw | blame | history
src/activations.c 7 ●●●●● patch | view | raw | blame | history
src/activations.h 14 ●●●●● patch | view | raw | blame | history
src/coco.c 50 ●●●● patch | view | raw | blame | history
src/coco_demo.c 161 ●●●●● patch | view | raw | blame | history
src/convolutional_kernels.cu 3 ●●●● patch | view | raw | blame | history
src/demo.c 198 ●●●●● patch | view | raw | blame | history
src/demo.h 7 ●●●●● patch | view | raw | blame | history
src/detection_layer.c 11 ●●●● patch | view | raw | blame | history
src/image.c 1 ●●●● patch | view | raw | blame | history
src/layer.h 1 ●●●● patch | view | raw | blame | history
src/network.c 1 ●●●● patch | view | raw | blame | history
src/network.h 1 ●●●● patch | view | raw | blame | history
src/parser.c 2 ●●●●● patch | view | raw | blame | history
src/yolo.c 13 ●●●● patch | view | raw | blame | history
src/yolo_demo.c 135 ●●●●● patch | view | raw | blame | history
Makefile
@@ -1,4 +1,4 @@
GPU=0
GPU=1
OPENCV=1
CUDNN=0
DEBUG=0
@@ -41,7 +41,7 @@
LDFLAGS+= -lcudnn
endif
OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o imagenet.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o coco_demo.o tag.o cifar.o yolo_demo.o go.o batchnorm_layer.o art.o
OBJ=gemm.o utils.o cuda.o deconvolutional_layer.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o imagenet.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o
ifeq ($(GPU), 1) 
LDFLAGS+= -lstdc++ 
OBJ+=convolutional_kernels.o deconvolutional_kernels.o activation_kernels.o im2col_kernels.o col2im_kernels.o blas_kernels.o crop_layer_kernels.o dropout_layer_kernels.o maxpool_layer_kernels.o softmax_layer_kernels.o network_kernels.o avgpool_layer_kernels.o
cfg/yolo-coco.cfg
@@ -1,6 +1,6 @@
[net]
batch=64
subdivisions=4
batch=1
subdivisions=1
height=448
width=448
channels=3
cfg/yolo.cfg
@@ -1,6 +1,6 @@
[net]
batch=64
subdivisions=64
batch=1
subdivisions=1
height=448
width=448
channels=3
@@ -13,14 +13,6 @@
scales=2.5,2,2,.1,.1
max_batches = 40000
[crop]
crop_width=448
crop_height=448
flip=0
angle=0
saturation = 1.5
exposure = 1.5
[convolutional]
filters=64
size=7
@@ -211,9 +203,6 @@
output=4096
activation=leaky
[dropout]
probability=.5
[connected]
output= 1470
activation=linear
data/labels/aeroplane.png

data/labels/airplane.png

data/labels/apple.png

data/labels/backpack.png

data/labels/banana.png

data/labels/baseball bat.png

data/labels/baseball glove.png

data/labels/bear.png

data/labels/bed.png

data/labels/bench.png

data/labels/bicycle.png

data/labels/bird.png

data/labels/boat.png

data/labels/book.png

data/labels/bottle.png

data/labels/bowl.png

data/labels/broccoli.png

data/labels/bus.png

data/labels/cake.png

data/labels/car.png

data/labels/carrot.png

data/labels/cat.png

data/labels/cell phone.png

data/labels/chair.png

data/labels/clock.png

data/labels/couch.png

data/labels/cow.png

data/labels/cup.png

data/labels/dining table.png

data/labels/diningtable.png

data/labels/dog.png

data/labels/donut.png

data/labels/elephant.png

data/labels/fire hydrant.png

data/labels/fork.png

data/labels/frisbee.png

data/labels/giraffe.png

data/labels/hair drier.png

data/labels/handbag.png

data/labels/horse.png

data/labels/hot dog.png

data/labels/keyboard.png

data/labels/kite.png

data/labels/knife.png

data/labels/laptop.png

data/labels/microwave.png

data/labels/motorbike.png

data/labels/motorcycle.png

data/labels/mouse.png

data/labels/orange.png

data/labels/oven.png

data/labels/parking meter.png

data/labels/person.png

data/labels/pizza.png

data/labels/potted plant.png

data/labels/pottedplant.png

data/labels/refrigerator.png

data/labels/remote.png

data/labels/sandwich.png

data/labels/scissors.png

data/labels/sheep.png

data/labels/sink.png

data/labels/skateboard.png

data/labels/skis.png

data/labels/snowboard.png

data/labels/sofa.png

data/labels/spoon.png

data/labels/sports ball.png

data/labels/stop sign.png

data/labels/suitcase.png

data/labels/surfboard.png

data/labels/teddy bear.png

data/labels/tennis racket.png

data/labels/tie.png

data/labels/toaster.png

data/labels/toilet.png

data/labels/toothbrush.png

data/labels/traffic light.png

data/labels/train.png

data/labels/truck.png

data/labels/tv.png

data/labels/tvmonitor.png

data/labels/umbrella.png

data/labels/vase.png

data/labels/wine glass.png

data/labels/zebra.png

src/activation_kernels.cu
@@ -8,6 +8,18 @@
}
__device__ float lhtan_activate_kernel(float x)
{
    if(x < 0) return .001*x;
    if(x > 1) return .001*(x-1) + 1;
    return x;
}
__device__ float lhtan_gradient_kernel(float x)
{
    if(x > 0 && x < 1) return 1;
    return .001;
}
__device__ float hardtan_activate_kernel(float x)
{
    if (x < -1) return -1;
@@ -89,6 +101,8 @@
            return stair_activate_kernel(x);
        case HARDTAN:
            return hardtan_activate_kernel(x);
        case LHTAN:
            return lhtan_activate_kernel(x);
    }
    return 0;
}
@@ -120,6 +134,8 @@
            return stair_gradient_kernel(x);
        case HARDTAN:
            return hardtan_gradient_kernel(x);
        case LHTAN:
            return lhtan_gradient_kernel(x);
    }
    return 0;
}
src/activations.c
@@ -32,6 +32,8 @@
            return "stair";
        case HARDTAN:
            return "hardtan";
        case LHTAN:
            return "lhtan";
        default:
            break;
    }
@@ -47,6 +49,7 @@
    if (strcmp(s, "relie")==0) return RELIE;
    if (strcmp(s, "plse")==0) return PLSE;
    if (strcmp(s, "hardtan")==0) return HARDTAN;
    if (strcmp(s, "lhtan")==0) return LHTAN;
    if (strcmp(s, "linear")==0) return LINEAR;
    if (strcmp(s, "ramp")==0) return RAMP;
    if (strcmp(s, "leaky")==0) return LEAKY;
@@ -83,6 +86,8 @@
            return stair_activate(x);
        case HARDTAN:
            return hardtan_activate(x);
        case LHTAN:
            return lhtan_activate(x);
    }
    return 0;
}
@@ -122,6 +127,8 @@
            return stair_gradient(x);
        case HARDTAN:
            return hardtan_gradient(x);
        case LHTAN:
            return lhtan_gradient(x);
    }
    return 0;
}
src/activations.h
@@ -4,7 +4,7 @@
#include "math.h"
typedef enum{
    LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN
    LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN
}ACTIVATION;
ACTIVATION get_activation(char *s);
@@ -47,6 +47,18 @@
    return .125*x + .5;
}
static inline float lhtan_activate(float x)
{
    if(x < 0) return .001*x;
    if(x > 1) return .001*(x-1) + 1;
    return x;
}
static inline float lhtan_gradient(float x)
{
    if(x > 0 && x < 1) return 1;
    return .001;
}
static inline float hardtan_gradient(float x)
{
    if (x > -1 && x < 1) return 1;
src/coco.c
@@ -6,11 +6,14 @@
#include "utils.h"
#include "parser.h"
#include "box.h"
#include "demo.h"
#ifdef OPENCV
#include "opencv2/highgui/highgui_c.h"
#endif
void convert_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness);
char *coco_classes[] = {"person","bicycle","car","motorcycle","airplane","bus","train","truck","boat","traffic light","fire hydrant","stop sign","parking meter","bench","bird","cat","dog","horse","sheep","cow","elephant","bear","zebra","giraffe","backpack","umbrella","handbag","tie","suitcase","frisbee","skis","snowboard","sports ball","kite","baseball bat","baseball glove","skateboard","surfboard","tennis racket","bottle","wine glass","cup","fork","knife","spoon","bowl","banana","apple","sandwich","orange","broccoli","carrot","hot dog","pizza","donut","cake","chair","couch","potted plant","bed","dining table","toilet","tv","laptop","mouse","remote","keyboard","cell phone","microwave","oven","toaster","sink","refrigerator","book","clock","vase","scissors","teddy bear","hair drier","toothbrush"};
int coco_ids[] = {1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,70,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90};
@@ -98,34 +101,6 @@
    save_weights(net, buff);
}
void convert_coco_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness)
{
    int i,j,n;
    //int per_cell = 5*num+classes;
    for (i = 0; i < side*side; ++i){
        int row = i / side;
        int col = i % side;
        for(n = 0; n < num; ++n){
            int index = i*num + n;
            int p_index = side*side*classes + i*num + n;
            float scale = predictions[p_index];
            int box_index = side*side*(classes + num) + (i*num + n)*4;
            boxes[index].x = (predictions[box_index + 0] + col) / side * w;
            boxes[index].y = (predictions[box_index + 1] + row) / side * h;
            boxes[index].w = pow(predictions[box_index + 2], (square?2:1)) * w;
            boxes[index].h = pow(predictions[box_index + 3], (square?2:1)) * h;
            for(j = 0; j < classes; ++j){
                int class_index = i*classes;
                float prob = scale*predictions[class_index+j];
                probs[index][j] = (prob > thresh) ? prob : 0;
            }
            if(only_objectness){
                probs[index][0] = scale;
            }
        }
    }
}
void print_cocos(FILE *fp, int image_id, box *boxes, float **probs, int num_boxes, int classes, int w, int h)
{
    int i, j;
@@ -235,7 +210,7 @@
            float *predictions = network_predict(net, X);
            int w = val[t].w;
            int h = val[t].h;
            convert_coco_detections(predictions, classes, l.n, square, side, w, h, thresh, probs, boxes, 0);
            convert_detections(predictions, classes, l.n, square, side, w, h, thresh, probs, boxes, 0);
            if (nms) do_nms_sort(boxes, probs, side*side*l.n, classes, iou_thresh);
            print_cocos(fp, image_id, boxes, probs, side*side*l.n, classes, w, h);
            free_image(val[t]);
@@ -298,7 +273,7 @@
        image sized = resize_image(orig, net.w, net.h);
        char *id = basecfg(path);
        float *predictions = network_predict(net, sized.data);
        convert_coco_detections(predictions, classes, l.n, square, side, 1, 1, thresh, probs, boxes, 1);
        convert_detections(predictions, classes, l.n, square, side, 1, 1, thresh, probs, boxes, 1);
        if (nms) do_nms(boxes, probs, side*side*l.n, 1, nms_thresh);
        char *labelpath = find_replace(path, "images", "labels");
@@ -370,7 +345,7 @@
        time=clock();
        float *predictions = network_predict(net, X);
        printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
        convert_coco_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, thresh, probs, boxes, 0);
        convert_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, thresh, probs, boxes, 0);
        if (nms) do_nms_sort(boxes, probs, l.side*l.side*l.n, l.classes, nms);
        draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, coco_classes, coco_labels, 80);
        show_image(im, "predictions");
@@ -386,16 +361,6 @@
    }
}
void demo_coco(char *cfgfile, char *weightfile, float thresh, int cam_index, char *filename);
static void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, char* filename)
{
    #if defined(OPENCV)
        demo_coco(cfgfile, weightfile, thresh, cam_index, filename);
    #else
        fprintf(stderr, "Need to compile with OpenCV for demo.\n");
    #endif
}
void run_coco(int argc, char **argv)
{
    int i;
@@ -406,7 +371,6 @@
    }
    float thresh = find_float_arg(argc, argv, "-thresh", .2);
    int cam_index = find_int_arg(argc, argv, "-c", 0);
    char *file = find_char_arg(argc, argv, "-file", 0);
    if(argc < 4){
        fprintf(stderr, "usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]);
@@ -420,5 +384,5 @@
    else if(0==strcmp(argv[2], "train")) train_coco(cfg, weights);
    else if(0==strcmp(argv[2], "valid")) validate_coco(cfg, weights);
    else if(0==strcmp(argv[2], "recall")) validate_coco_recall(cfg, weights);
    else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, file);
    else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, coco_classes, coco_labels, 80);
}
src/coco_demo.c
File was deleted
src/convolutional_kernels.cu
@@ -71,8 +71,6 @@
void forward_convolutional_layer_gpu(convolutional_layer l, network_state state)
{
    int i;
    fill_ongpu(l.outputs*l.batch, 0, l.output_gpu, 1);
    if(l.binary){
        binarize_filters_gpu(l.filters_gpu, l.n, l.c*l.size*l.size, l.binary_filters_gpu);
@@ -103,6 +101,7 @@
                l.output_gpu);
#else
    int i;
    int m = l.n;
    int k = l.size*l.size*l.c;
    int n = l.out_w*l.out_h;
src/demo.c
New file
@@ -0,0 +1,198 @@
#include "network.h"
#include "detection_layer.h"
#include "cost_layer.h"
#include "utils.h"
#include "parser.h"
#include "box.h"
#include "image.h"
#include "demo.h"
#include <sys/time.h>
#define FRAMES 3
#ifdef OPENCV
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h"
void convert_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness);
#define DELAY 0
static int delay = DELAY;
static char **demo_names;
static image *demo_labels;
static int demo_classes;
static float **probs;
static box *boxes;
static network net;
static image in   ;
static image in_s ;
static image det  ;
static image det_s;
static image disp = {0};
static CvCapture * cap;
static float fps = 0;
static float demo_thresh = 0;
static float *predictions[FRAMES];
static int demo_index = 0;
static image images[FRAMES];
static float *avg;
void *fetch_in_thread(void *ptr)
{
    in = get_image_from_stream(cap);
    if(!in.data){
        in = disp;
        if(delay == DELAY) error("Stream closed.");
    }else{
        if(disp.data){
            free_image(disp);
        }
        in_s = resize_image(in, net.w, net.h);
    }
    return 0;
}
void *detect_in_thread(void *ptr)
{
    float nms = .4;
    detection_layer l = net.layers[net.n-1];
    float *X = det_s.data;
    float *prediction = network_predict(net, X);
    memcpy(predictions[demo_index], prediction, l.outputs*sizeof(float));
    if(delay == DELAY){
        mean_arrays(predictions, FRAMES, l.outputs, avg);
    }
    free_image(det_s);
    convert_detections(avg, l.classes, l.n, l.sqrt, l.side, 1, 1, demo_thresh, probs, boxes, 0);
    if (nms > 0) do_nms(boxes, probs, l.side*l.side*l.n, l.classes, nms);
    printf("\033[2J");
    printf("\033[1;1H");
    printf("\nFPS:%.1f\n",fps);
    printf("Objects:\n\n");
    images[demo_index] = det;
    det = images[(demo_index + FRAMES/2 + 1)%FRAMES];
    demo_index = (demo_index + 1)%FRAMES;
    draw_detections(det, l.side*l.side*l.n, demo_thresh, boxes, probs, demo_names, demo_labels, demo_classes);
    if(delay == 0){
        delay = DELAY;
    } else {
        --delay;
    }
    return 0;
}
double get_wall_time()
{
    struct timeval time;
    if (gettimeofday(&time,NULL)){
        return 0;
    }
    return (double)time.tv_sec + (double)time.tv_usec * .000001;
}
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, image *labels, int classes)
{
    demo_names = names;
    demo_labels = labels;
    demo_classes = classes;
    demo_thresh = thresh;
    printf("Demo\n");
    net = parse_network_cfg(cfgfile);
    if(weightfile){
        load_weights(&net, weightfile);
    }
    set_batch_network(&net, 1);
    srand(2222222);
    if(filename){
        cap = cvCaptureFromFile(filename);
    }else{
        cap = cvCaptureFromCAM(cam_index);
    }
    if(!cap) error("Couldn't connect to webcam.\n");
    detection_layer l = net.layers[net.n-1];
    int j;
    avg = (float *) calloc(l.outputs, sizeof(float));
    for(j = 0; j < FRAMES; ++j) predictions[j] = (float *) calloc(l.outputs, sizeof(float));
    for(j = 0; j < FRAMES; ++j) images[j] = make_image(1,1,3);
    boxes = (box *)calloc(l.side*l.side*l.n, sizeof(box));
    probs = (float **)calloc(l.side*l.side*l.n, sizeof(float *));
    for(j = 0; j < l.side*l.side*l.n; ++j) probs[j] = (float *)calloc(l.classes, sizeof(float *));
    pthread_t fetch_thread;
    pthread_t detect_thread;
    fetch_in_thread(0);
    det = in;
    det_s = in_s;
    fetch_in_thread(0);
    detect_in_thread(0);
    disp = det;
    det = in;
    det_s = in_s;
    for(j = 0; j < FRAMES/2; ++j){
        fetch_in_thread(0);
        detect_in_thread(0);
        disp = det;
        det = in;
        det_s = in_s;
    }
    int count = 0;
    cvNamedWindow("Demo", CV_WINDOW_NORMAL);
    cvMoveWindow("Demo", 0, 0);
    cvResizeWindow("Demo", 1352, 1013);
    double before = get_wall_time();
    while(1){
        ++count;
        if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed");
        if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed");
        //fetch_in_thread(0);
        //detect_in_thread(0);
        show_image(disp, "Demo");
        cvWaitKey(1);
        //char buff[256];
        //sprintf(buff, "coco/coco_%05d", count);
        //save_image(disp, buff);
        //free_image(disp);
        //cvWaitKey(10);
        pthread_join(fetch_thread, 0);
        pthread_join(detect_thread, 0);
        disp  = det;
        det   = in;
        det_s = in_s;
        if(delay == DELAY){
            double after = get_wall_time();
            float curr = 1./(after - before);
            fps = curr;
            before = after;
        }
    }
}
#else
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, image *labels, int classes)
{
    fprintf(stderr, "Demo needs OpenCV for webcam images.\n");
}
#endif
src/demo.h
New file
@@ -0,0 +1,7 @@
#ifndef DEMO
#define DEMO
#include "image.h"
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, image *labels, int classes);
#endif
src/detection_layer.c
@@ -53,8 +53,6 @@
                softmax_array(l.output + index + offset, l.classes, 1,
                        l.output + index + offset);
            }
            int offset = locations*l.classes;
            activate_array(l.output + index + offset, locations*l.n*(1+l.coords), LOGISTIC);
        }
    }
    if(state.train){
@@ -133,11 +131,9 @@
                        best_index = 0;
                    }
                }
                /*
                if(1 && *(state.net.seen) < 100000){
                if(l.random && *(state.net.seen) < 64000){
                    best_index = rand()%l.n;
                }
                */
                int box_index = index + locations*(l.classes + l.n) + (i*l.n + best_index) * l.coords;
                int tbox_index = truth_index + 1 + l.classes;
@@ -175,10 +171,6 @@
                avg_iou += iou;
                ++count;
            }
            if(l.softmax){
                gradient_array(l.output + index + locations*l.classes, locations*l.n*(1+l.coords),
                        LOGISTIC, l.delta + index + locations*l.classes);
            }
        }
        if(0){
@@ -208,6 +200,7 @@
        }
        *(l.cost) = pow(mag_array(l.delta, l.outputs * l.batch), 2);
        printf("Detection Avg IOU: %f, Pos Cat: %f, All Cat: %f, Pos Obj: %f, Any Obj: %f, count: %d\n", avg_iou/count, avg_cat/count, avg_allcat/(count*l.classes), avg_obj/count, avg_anyobj/(l.batch*locations*l.n), count);
src/image.c
@@ -365,6 +365,7 @@
    image get_image_from_stream(CvCapture *cap)
    {
        IplImage* src = cvQueryFrame(cap);
        if (!src) return make_empty_image(0,0,0);
        image im = ipl_to_image(src);
        rgbgr_image(im);
        return im;
src/layer.h
@@ -88,6 +88,7 @@
    float object_scale;
    float noobject_scale;
    float class_scale;
    int random;
    int dontload;
    int dontloadscales;
src/network.c
@@ -64,6 +64,7 @@
        case EXP:
            return net.learning_rate * pow(net.gamma, batch_num);
        case POLY:
            if (batch_num < net.burn_in) return net.learning_rate * pow((float)batch_num / net.burn_in, net.power);
            return net.learning_rate * pow(1 - (float)batch_num / net.max_batches, net.power);
        case RANDOM:
            return net.learning_rate * pow(rand_uniform(0,1), net.power);
src/network.h
@@ -34,6 +34,7 @@
    float *scales;
    int   *steps;
    int num_steps;
    int burn_in;
    int inputs;
    int h, w, c;
src/parser.c
@@ -264,6 +264,7 @@
    layer.noobject_scale = option_find_float(options, "noobject_scale", 1);
    layer.class_scale = option_find_float(options, "class_scale", 1);
    layer.jitter = option_find_float(options, "jitter", .2);
    layer.random = option_find_int_quiet(options, "random", 0);
    return layer;
}
@@ -467,6 +468,7 @@
    char *policy_s = option_find_str(options, "policy", "constant");
    net->policy = get_policy(policy_s);
    net->burn_in = option_find_int_quiet(options, "burn_in", 0);
    if(net->policy == STEP){
        net->step = option_find_int(options, "step", 1);
        net->scale = option_find_float(options, "scale", 1);
src/yolo.c
@@ -4,6 +4,7 @@
#include "utils.h"
#include "parser.h"
#include "box.h"
#include "demo.h"
#ifdef OPENCV
#include "opencv2/highgui/highgui_c.h"
@@ -83,7 +84,7 @@
    save_weights(net, buff);
}
void convert_yolo_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness)
void convert_detections(float *predictions, int classes, int num, int square, int side, int w, int h, float thresh, float **probs, box *boxes, int only_objectness)
{
    int i,j,n;
    //int per_cell = 5*num+classes;
@@ -211,7 +212,7 @@
            float *predictions = network_predict(net, X);
            int w = val[t].w;
            int h = val[t].h;
            convert_yolo_detections(predictions, classes, l.n, square, side, w, h, thresh, probs, boxes, 0);
            convert_detections(predictions, classes, l.n, square, side, w, h, thresh, probs, boxes, 0);
            if (nms) do_nms_sort(boxes, probs, side*side*l.n, classes, iou_thresh);
            print_yolo_detections(fps, id, boxes, probs, side*side*l.n, classes, w, h);
            free(id);
@@ -270,7 +271,7 @@
        image sized = resize_image(orig, net.w, net.h);
        char *id = basecfg(path);
        float *predictions = network_predict(net, sized.data);
        convert_yolo_detections(predictions, classes, l.n, square, side, 1, 1, thresh, probs, boxes, 1);
        convert_detections(predictions, classes, l.n, square, side, 1, 1, thresh, probs, boxes, 1);
        if (nms) do_nms(boxes, probs, side*side*l.n, 1, nms);
        char *labelpath = find_replace(path, "images", "labels");
@@ -342,7 +343,7 @@
        time=clock();
        float *predictions = network_predict(net, X);
        printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
        convert_yolo_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, thresh, probs, boxes, 0);
        convert_detections(predictions, l.classes, l.n, l.sqrt, l.side, 1, 1, thresh, probs, boxes, 0);
        if (nms) do_nms_sort(boxes, probs, l.side*l.side*l.n, l.classes, nms);
        //draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, voc_names, voc_labels, 20);
        draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, voc_names, voc_labels, 20);
@@ -360,8 +361,6 @@
    }
}
void demo_yolo(char *cfgfile, char *weightfile, float thresh, int cam_index, char *filename);
void run_yolo(int argc, char **argv)
{
    int i;
@@ -385,5 +384,5 @@
    else if(0==strcmp(argv[2], "train")) train_yolo(cfg, weights);
    else if(0==strcmp(argv[2], "valid")) validate_yolo(cfg, weights);
    else if(0==strcmp(argv[2], "recall")) validate_yolo_recall(cfg, weights);
    else if(0==strcmp(argv[2], "demo")) demo_yolo(cfg, weights, thresh, cam_index, filename);
    else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, voc_names, voc_labels, 20);
}
src/yolo_demo.c
File was deleted