mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
fixed demo thing
This commit is contained in:
parent
d3828827e7
commit
f444f25e91
66
src/demo.c
66
src/demo.c
@ -30,13 +30,59 @@ static int running = 0;
|
||||
|
||||
static int demo_frame = 3;
|
||||
static int demo_index = 0;
|
||||
//static float **predictions;
|
||||
//static float *avg;
|
||||
static float **predictions;
|
||||
static float *avg;
|
||||
static int demo_done = 0;
|
||||
static int demo_total = 0;
|
||||
double demo_time;
|
||||
|
||||
detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num);
|
||||
|
||||
int size_network(network *net)
|
||||
{
|
||||
int i;
|
||||
int count = 0;
|
||||
for(i = 0; i < net->n; ++i){
|
||||
layer l = net->layers[i];
|
||||
if(l.type == YOLO || l.type == REGION || l.type == DETECTION){
|
||||
count += l.outputs;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void remember_network(network *net)
|
||||
{
|
||||
int i;
|
||||
int count = 0;
|
||||
for(i = 0; i < net->n; ++i){
|
||||
layer l = net->layers[i];
|
||||
if(l.type == YOLO || l.type == REGION || l.type == DETECTION){
|
||||
memcpy(predictions[demo_index] + count, net->layers[i].output, sizeof(float) * l.outputs);
|
||||
count += l.outputs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
detection *avg_predictions(network *net, int *nboxes)
|
||||
{
|
||||
int i, j;
|
||||
int count = 0;
|
||||
fill_cpu(demo_total, 0, avg, 1);
|
||||
for(j = 0; j < demo_frame; ++j){
|
||||
axpy_cpu(demo_total, 1./demo_frame, predictions[j], 1, avg, 1);
|
||||
}
|
||||
for(i = 0; i < net->n; ++i){
|
||||
layer l = net->layers[i];
|
||||
if(l.type == YOLO || l.type == REGION || l.type == DETECTION){
|
||||
memcpy(l.output, avg + count, sizeof(float) * l.outputs);
|
||||
count += l.outputs;
|
||||
}
|
||||
}
|
||||
detection *dets = get_network_boxes(net, buff[0].w, buff[0].h, demo_thresh, demo_hier, 0, 1, nboxes);
|
||||
return dets;
|
||||
}
|
||||
|
||||
void *detect_in_thread(void *ptr)
|
||||
{
|
||||
running = 1;
|
||||
@ -50,13 +96,11 @@ void *detect_in_thread(void *ptr)
|
||||
if(l.type == DETECTION){
|
||||
get_detection_boxes(l, 1, 1, demo_thresh, probs, boxes, 0);
|
||||
} else */
|
||||
remember_network(net);
|
||||
detection *dets = 0;
|
||||
int nboxes = 0;
|
||||
if (l.type == REGION){
|
||||
dets = get_network_boxes(net, buff[0].w, buff[0].h, demo_thresh, demo_hier, 0, 1, &nboxes);
|
||||
} else {
|
||||
error("Last layer must produce detections\n");
|
||||
}
|
||||
dets = avg_predictions(net, &nboxes);
|
||||
|
||||
|
||||
/*
|
||||
int i,j;
|
||||
@ -155,6 +199,14 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch
|
||||
|
||||
srand(2222222);
|
||||
|
||||
int i;
|
||||
demo_total = size_network(net);
|
||||
predictions = calloc(demo_frame, sizeof(float*));
|
||||
for (i = 0; i < demo_frame; ++i){
|
||||
predictions[i] = calloc(demo_total, sizeof(float));
|
||||
}
|
||||
avg = calloc(demo_total, sizeof(float));
|
||||
|
||||
if(filename){
|
||||
printf("video file: %s\n", filename);
|
||||
cap = cvCaptureFromFile(filename);
|
||||
|
Loading…
Reference in New Issue
Block a user