mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
hm......
This commit is contained in:
parent
fbd48ab606
commit
532c6e1481
@ -621,7 +621,7 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
|
|||||||
network_predict(net, X);
|
network_predict(net, X);
|
||||||
printf("%s: Predicted in %f seconds.\n", input, what_time_is_it_now()-time);
|
printf("%s: Predicted in %f seconds.\n", input, what_time_is_it_now()-time);
|
||||||
get_region_boxes(l, im.w, im.h, net.w, net.h, thresh, probs, boxes, masks, 0, 0, hier_thresh, 1);
|
get_region_boxes(l, im.w, im.h, net.w, net.h, thresh, probs, boxes, masks, 0, 0, hier_thresh, 1);
|
||||||
if (nms) do_nms_obj(boxes, probs, l.w*l.h*l.n, l.classes, nms);
|
if (nms) do_nms_sort(boxes, probs, l.w*l.h*l.n, l.classes, nms);
|
||||||
//else if (nms) do_nms_sort(boxes, probs, l.w*l.h*l.n, l.classes, nms);
|
//else if (nms) do_nms_sort(boxes, probs, l.w*l.h*l.n, l.classes, nms);
|
||||||
draw_detections(im, l.w*l.h*l.n, thresh, boxes, probs, masks, names, alphabet, l.classes);
|
draw_detections(im, l.w*l.h*l.n, thresh, boxes, probs, masks, names, alphabet, l.classes);
|
||||||
if(outfile){
|
if(outfile){
|
||||||
|
@ -7,6 +7,20 @@ typedef struct {
|
|||||||
float *y;
|
float *y;
|
||||||
} float_pair;
|
} float_pair;
|
||||||
|
|
||||||
|
unsigned char **load_files(char *filename, int *n)
|
||||||
|
{
|
||||||
|
list *paths = get_paths(filename);
|
||||||
|
*n = paths->size;
|
||||||
|
unsigned char **contents = calloc(*n, sizeof(char *));
|
||||||
|
int i;
|
||||||
|
node *x = paths->front;
|
||||||
|
for(i = 0; i < *n; ++i){
|
||||||
|
contents[i] = read_file((char *)x->val);
|
||||||
|
x = x->next;
|
||||||
|
}
|
||||||
|
return contents;
|
||||||
|
}
|
||||||
|
|
||||||
int *read_tokenized_data(char *filename, size_t *read)
|
int *read_tokenized_data(char *filename, size_t *read)
|
||||||
{
|
{
|
||||||
size_t size = 512;
|
size_t size = 512;
|
||||||
@ -86,6 +100,8 @@ float_pair get_seq2seq_data(char **source, char **dest, int n, int characters, s
|
|||||||
float *y = calloc(batch * steps * characters, sizeof(float));
|
float *y = calloc(batch * steps * characters, sizeof(float));
|
||||||
for(i = 0; i < batch; ++i){
|
for(i = 0; i < batch; ++i){
|
||||||
int index = rand()%n;
|
int index = rand()%n;
|
||||||
|
int slen = strlen(source[index]);
|
||||||
|
int dlen = strlen(dest[index]);
|
||||||
for(j = 0; j < steps; ++j){
|
for(j = 0; j < steps; ++j){
|
||||||
unsigned char curr = source[index][j];
|
unsigned char curr = source[index][j];
|
||||||
unsigned char next = dest[index][j];
|
unsigned char next = dest[index][j];
|
||||||
@ -147,15 +163,8 @@ void train_char_rnn(char *cfgfile, char *weightfile, char *filename, int clear,
|
|||||||
if(tokenized){
|
if(tokenized){
|
||||||
tokens = read_tokenized_data(filename, &size);
|
tokens = read_tokenized_data(filename, &size);
|
||||||
} else {
|
} else {
|
||||||
FILE *fp = fopen(filename, "rb");
|
text = read_file(filename);
|
||||||
|
size = strlen((const char*)text);
|
||||||
fseek(fp, 0, SEEK_END);
|
|
||||||
size = ftell(fp);
|
|
||||||
fseek(fp, 0, SEEK_SET);
|
|
||||||
|
|
||||||
text = calloc(size+1, sizeof(char));
|
|
||||||
fread(text, 1, size, fp);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *backup_directory = "/home/pjreddie/backup/";
|
char *backup_directory = "/home/pjreddie/backup/";
|
||||||
|
@ -574,6 +574,7 @@ typedef struct list{
|
|||||||
pthread_t load_data(load_args args);
|
pthread_t load_data(load_args args);
|
||||||
list *read_data_cfg(char *filename);
|
list *read_data_cfg(char *filename);
|
||||||
list *read_cfg(char *filename);
|
list *read_cfg(char *filename);
|
||||||
|
unsigned char *read_file(char *filename);
|
||||||
|
|
||||||
void forward_network(network net);
|
void forward_network(network net);
|
||||||
void backward_network(network net);
|
void backward_network(network net);
|
||||||
|
21
src/demo.c
21
src/demo.c
@ -38,15 +38,6 @@ static int demo_done = 0;
|
|||||||
static float *avg;
|
static float *avg;
|
||||||
double demo_time;
|
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)
|
void *detect_in_thread(void *ptr)
|
||||||
{
|
{
|
||||||
running = 1;
|
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){
|
while(!demo_done){
|
||||||
buff_index = (buff_index + 1) %3;
|
buff_index = (buff_index + 1) %3;
|
||||||
if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed");
|
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(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed");
|
||||||
if(!prefix){
|
if(!prefix){
|
||||||
fps = 1./(get_wall_time() - demo_time);
|
fps = 1./(what_time_is_it_now() - demo_time);
|
||||||
demo_time = get_wall_time();
|
demo_time = what_time_is_it_now();
|
||||||
display_in_thread(0);
|
display_in_thread(0);
|
||||||
}else{
|
}else{
|
||||||
char name[256];
|
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){
|
while(!demo_done){
|
||||||
buff_index = (buff_index + 1) %3;
|
buff_index = (buff_index + 1) %3;
|
||||||
if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed");
|
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(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed");
|
||||||
if(!prefix){
|
if(!prefix){
|
||||||
fps = 1./(get_wall_time() - demo_time);
|
fps = 1./(what_time_is_it_now() - demo_time);
|
||||||
demo_time = get_wall_time();
|
demo_time = what_time_is_it_now();
|
||||||
display_in_thread(0);
|
display_in_thread(0);
|
||||||
}else{
|
}else{
|
||||||
char name[256];
|
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)
|
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){
|
for(i = 0; i < num; ++i){
|
||||||
int class = max_index(probs[i], classes);
|
char labelstr[4096] = {0};
|
||||||
float prob = probs[i][class];
|
int class = -1;
|
||||||
if(prob > thresh){
|
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;
|
int width = im.h * .006;
|
||||||
|
|
||||||
if(0){
|
/*
|
||||||
width = pow(prob, 1./2.)*10+1;
|
if(0){
|
||||||
alphabet = 0;
|
width = pow(prob, 1./2.)*10+1;
|
||||||
}
|
alphabet = 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
//printf("%d %s: %.0f%%\n", i, names[class], prob*100);
|
//printf("%d %s: %.0f%%\n", i, names[class], prob*100);
|
||||||
printf("%s: %.0f%%\n", names[class], prob*100);
|
|
||||||
int offset = class*123457 % classes;
|
int offset = class*123457 % classes;
|
||||||
float red = get_color(2,offset,classes);
|
float red = get_color(2,offset,classes);
|
||||||
float green = get_color(1,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);
|
draw_box_width(im, left, top, right, bot, width, red, green, blue);
|
||||||
if (alphabet) {
|
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);
|
draw_label(im, top + width, left, label, rgb);
|
||||||
free_image(label);
|
free_image(label);
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,10 @@ void delta_region_class(float *output, float *delta, int index, int class, int c
|
|||||||
}
|
}
|
||||||
*avg_cat += pred;
|
*avg_cat += pred;
|
||||||
} else {
|
} else {
|
||||||
|
if (delta[index]){
|
||||||
|
delta[index + stride*class] = scale * (1 - output[index + stride*class]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
for(n = 0; n < classes; ++n){
|
for(n = 0; n < classes; ++n){
|
||||||
delta[index + stride*n] = scale * (((n == class)?1 : 0) - output[index + stride*n]);
|
delta[index + stride*n] = scale * (((n == class)?1 : 0) - output[index + stride*n]);
|
||||||
if(n == class) *avg_cat += 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);
|
activate_array(l.output + index, 2*l.w*l.h, LOGISTIC);
|
||||||
index = entry_index(l, b, n*l.w*l.h, l.coords);
|
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);
|
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){
|
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);
|
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);
|
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){
|
if (l.softmax_tree){
|
||||||
|
28
src/utils.c
28
src/utils.c
@ -10,6 +10,19 @@
|
|||||||
|
|
||||||
#include "utils.h"
|
#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()
|
double what_time_is_it_now()
|
||||||
{
|
{
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
@ -225,6 +238,21 @@ void error(const char *s)
|
|||||||
exit(-1);
|
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()
|
void malloc_error()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Malloc error\n");
|
fprintf(stderr, "Malloc error\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user