mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
hm......
This commit is contained in:
21
src/demo.c
21
src/demo.c
@@ -38,15 +38,6 @@ static int demo_done = 0;
|
||||
static float *avg;
|
||||
double demo_time;
|
||||
|
||||
double get_wall_time()
|
||||
{
|
||||
struct timeval time;
|
||||
if (gettimeofday(&time,NULL)){
|
||||
return 0;
|
||||
}
|
||||
return (double)time.tv_sec + (double)time.tv_usec * .000001;
|
||||
}
|
||||
|
||||
void *detect_in_thread(void *ptr)
|
||||
{
|
||||
running = 1;
|
||||
@@ -194,15 +185,15 @@ void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const ch
|
||||
}
|
||||
}
|
||||
|
||||
demo_time = get_wall_time();
|
||||
demo_time = what_time_is_it_now();
|
||||
|
||||
while(!demo_done){
|
||||
buff_index = (buff_index + 1) %3;
|
||||
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");
|
||||
if(!prefix){
|
||||
fps = 1./(get_wall_time() - demo_time);
|
||||
demo_time = get_wall_time();
|
||||
fps = 1./(what_time_is_it_now() - demo_time);
|
||||
demo_time = what_time_is_it_now();
|
||||
display_in_thread(0);
|
||||
}else{
|
||||
char name[256];
|
||||
@@ -282,15 +273,15 @@ void demo_compare(char *cfg1, char *weight1, char *cfg2, char *weight2, float th
|
||||
}
|
||||
}
|
||||
|
||||
demo_time = get_wall_time();
|
||||
demo_time = what_time_is_it_now();
|
||||
|
||||
while(!demo_done){
|
||||
buff_index = (buff_index + 1) %3;
|
||||
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");
|
||||
if(!prefix){
|
||||
fps = 1./(get_wall_time() - demo_time);
|
||||
demo_time = get_wall_time();
|
||||
fps = 1./(what_time_is_it_now() - demo_time);
|
||||
demo_time = what_time_is_it_now();
|
||||
display_in_thread(0);
|
||||
}else{
|
||||
char name[256];
|
||||
|
||||
33
src/image.c
33
src/image.c
@@ -237,21 +237,34 @@ image **load_alphabet()
|
||||
|
||||
void draw_detections(image im, int num, float thresh, box *boxes, float **probs, float **masks, char **names, image **alphabet, int classes)
|
||||
{
|
||||
int i;
|
||||
int i,j;
|
||||
|
||||
for(i = 0; i < num; ++i){
|
||||
int class = max_index(probs[i], classes);
|
||||
float prob = probs[i][class];
|
||||
if(prob > thresh){
|
||||
char labelstr[4096] = {0};
|
||||
int class = -1;
|
||||
for(j = 0; j < classes; ++j){
|
||||
if (probs[i][j] > thresh){
|
||||
if (class < 0) {
|
||||
strcat(labelstr, names[j]);
|
||||
class = j;
|
||||
} else {
|
||||
strcat(labelstr, ", ");
|
||||
strcat(labelstr, names[j]);
|
||||
}
|
||||
printf("%s: %.0f%%\n", names[j], probs[i][j]*100);
|
||||
}
|
||||
}
|
||||
if(class >= 0){
|
||||
int width = im.h * .006;
|
||||
|
||||
if(0){
|
||||
width = pow(prob, 1./2.)*10+1;
|
||||
alphabet = 0;
|
||||
}
|
||||
/*
|
||||
if(0){
|
||||
width = pow(prob, 1./2.)*10+1;
|
||||
alphabet = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
//printf("%d %s: %.0f%%\n", i, names[class], prob*100);
|
||||
printf("%s: %.0f%%\n", names[class], prob*100);
|
||||
int offset = class*123457 % classes;
|
||||
float red = get_color(2,offset,classes);
|
||||
float green = get_color(1,offset,classes);
|
||||
@@ -277,7 +290,7 @@ void draw_detections(image im, int num, float thresh, box *boxes, float **probs,
|
||||
|
||||
draw_box_width(im, left, top, right, bot, width, red, green, blue);
|
||||
if (alphabet) {
|
||||
image label = get_label(alphabet, names[class], (im.h*.03)/10);
|
||||
image label = get_label(alphabet, labelstr, (im.h*.03)/10);
|
||||
draw_label(im, top + width, left, label, rgb);
|
||||
free_image(label);
|
||||
}
|
||||
|
||||
@@ -127,6 +127,10 @@ void delta_region_class(float *output, float *delta, int index, int class, int c
|
||||
}
|
||||
*avg_cat += pred;
|
||||
} else {
|
||||
if (delta[index]){
|
||||
delta[index + stride*class] = scale * (1 - output[index + stride*class]);
|
||||
return;
|
||||
}
|
||||
for(n = 0; n < classes; ++n){
|
||||
delta[index + stride*n] = scale * (((n == class)?1 : 0) - output[index + stride*n]);
|
||||
if(n == class) *avg_cat += output[index + stride*n];
|
||||
@@ -163,6 +167,8 @@ void forward_region_layer(const layer l, network net)
|
||||
activate_array(l.output + index, 2*l.w*l.h, LOGISTIC);
|
||||
index = entry_index(l, b, n*l.w*l.h, l.coords);
|
||||
if(!l.background) activate_array(l.output + index, l.w*l.h, LOGISTIC);
|
||||
index = entry_index(l, b, n*l.w*l.h, l.coords + 1);
|
||||
if(!l.softmax && !l.softmax_tree) activate_array(l.output + index, l.classes*l.w*l.h, LOGISTIC);
|
||||
}
|
||||
}
|
||||
if (l.softmax_tree){
|
||||
@@ -466,6 +472,8 @@ void forward_region_layer_gpu(const layer l, network net)
|
||||
}
|
||||
index = entry_index(l, b, n*l.w*l.h, l.coords);
|
||||
if(!l.background) activate_array_gpu(l.output_gpu + index, l.w*l.h, LOGISTIC);
|
||||
index = entry_index(l, b, n*l.w*l.h, l.coords + 1);
|
||||
if(!l.softmax && !l.softmax_tree) activate_array_gpu(l.output_gpu + index, l.classes*l.w*l.h, LOGISTIC);
|
||||
}
|
||||
}
|
||||
if (l.softmax_tree){
|
||||
|
||||
28
src/utils.c
28
src/utils.c
@@ -10,6 +10,19 @@
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
/*
|
||||
// old timing. is it better? who knows!!
|
||||
double get_wall_time()
|
||||
{
|
||||
struct timeval time;
|
||||
if (gettimeofday(&time,NULL)){
|
||||
return 0;
|
||||
}
|
||||
return (double)time.tv_sec + (double)time.tv_usec * .000001;
|
||||
}
|
||||
*/
|
||||
|
||||
double what_time_is_it_now()
|
||||
{
|
||||
struct timespec now;
|
||||
@@ -225,6 +238,21 @@ void error(const char *s)
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
unsigned char *read_file(char *filename)
|
||||
{
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
size_t size;
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
unsigned char *text = calloc(size+1, sizeof(char));
|
||||
fread(text, 1, size, fp);
|
||||
fclose(fp);
|
||||
return text;
|
||||
}
|
||||
|
||||
void malloc_error()
|
||||
{
|
||||
fprintf(stderr, "Malloc error\n");
|
||||
|
||||
Reference in New Issue
Block a user