3 char *
voc_names[] = {
"aeroplane",
"bicycle",
"bird",
"boat",
"bottle",
"bus",
"car",
"cat",
"chair",
"cow",
"diningtable",
"dog",
"horse",
"motorbike",
"person",
"pottedplant",
"sheep",
"sofa",
"train",
"tvmonitor"};
7 char *train_images =
"/data/voc/train.txt";
8 char *backup_directory =
"/home/pjreddie/backup/";
16 int i = *net->
seen/imgs;
53 pthread_join(load_thread, 0);
57 printf(
"Loaded: %lf seconds\n",
sec(clock()-time));
61 if (avg_loss < 0) avg_loss = loss;
62 avg_loss = avg_loss*.9 + loss*.1;
64 printf(
"%d: %f, %f avg, %f rate, %lf seconds, %d images\n", i, loss, avg_loss,
get_current_rate(net),
sec(clock()-time), i*imgs);
65 if(i%1000==0 || (i < 1000 && i%100 == 0)){
67 sprintf(buff,
"%s/%s_%d.weights", backup_directory, base, i);
73 sprintf(buff,
"%s/%s_final.weights", backup_directory, base);
80 for(i = 0; i < total; ++i){
81 float xmin = dets[i].
bbox.
x - dets[i].
bbox.
w/2.;
82 float xmax = dets[i].
bbox.
x + dets[i].
bbox.
w/2.;
83 float ymin = dets[i].
bbox.
y - dets[i].
bbox.
h/2.;
84 float ymax = dets[i].
bbox.
y + dets[i].
bbox.
h/2.;
86 if (xmin < 0) xmin = 0;
87 if (ymin < 0) ymin = 0;
88 if (xmax > w) xmax = w;
89 if (ymax > h) ymax = h;
92 if (dets[i].prob[j]) fprintf(fps[j],
"%s %f %f %f %f %f\n",
id, dets[i].prob[j],
93 xmin, ymin, xmax, ymax);
105 char *base =
"results/comp4_det_test_";
107 list *plist =
get_paths(
"/home/pjreddie/data/voc/2007_test.txt");
115 FILE **fps = calloc(classes,
sizeof(FILE *));
118 snprintf(buff, 1024,
"%s%s.txt", base,
voc_names[j]);
119 fps[j] = fopen(buff,
"w");
128 float iou_thresh = .5;
132 image *val_resized = calloc(nthreads,
sizeof(
image));
134 image *buf_resized = calloc(nthreads,
sizeof(
image));
135 pthread_t *thr = calloc(nthreads,
sizeof(pthread_t));
142 for(t = 0; t < nthreads; ++
t){
143 args.
path = paths[i+
t];
148 time_t start = time(0);
149 for(i = nthreads; i < m+nthreads; i += nthreads){
150 fprintf(stderr,
"%d\n", i);
151 for(t = 0; t < nthreads && i+t-nthreads < m; ++
t){
152 pthread_join(thr[t], 0);
154 val_resized[
t] = buf_resized[
t];
156 for(t = 0; t < nthreads && i+t < m; ++
t){
157 args.
path = paths[i+
t];
162 for(t = 0; t < nthreads && i+t-nthreads < m; ++
t){
163 char *path = paths[i+t-nthreads];
165 float *X = val_resized[
t].
data;
179 fprintf(stderr,
"Total Detection Time: %f Seconds\n", (
double)(time(0) - start));
189 char *base =
"results/comp4_det_test_";
198 FILE **fps = calloc(classes,
sizeof(FILE *));
201 snprintf(buff, 1024,
"%s%s.txt", base,
voc_names[j]);
202 fps[j] = fopen(buff,
"w");
209 float iou_thresh = .5;
217 for(i = 0; i < m; ++i){
218 char *path = paths[i];
228 char labelpath[4096];
230 find_replace(labelpath,
"JPEGImages",
"labels", labelpath);
236 for(k = 0; k < side*side*l.
n; ++k){
237 if(dets[k].objectness > thresh){
241 for (j = 0; j < num_labels; ++j) {
243 box t = {truth[j].
x, truth[j].
y, truth[j].
w, truth[j].
h};
245 for(k = 0; k < side*side*l.
n; ++k){
246 float iou =
box_iou(dets[k].bbox, t);
247 if(dets[k].objectness > thresh && iou > best_iou){
252 if(best_iou > iou_thresh){
257 fprintf(stderr,
"%5d %5d %5d\tRPs/Img: %.2f\tIOU: %.2f%%\tRecall:%.2f%%\n", i, correct, total, (
float)proposals/(i+1), avg_iou*100/total, 100.*correct/total);
265 void test_yolo(
char *cfgfile,
char *weightfile,
char *filename,
float thresh)
278 strncpy(input, filename, 256);
280 printf(
"Enter Image Path: ");
282 input = fgets(input, 256, stdin);
288 float *X = sized.
data;
291 printf(
"%s: Predicted in %f seconds.\n", input,
sec(clock()-time));
314 fprintf(stderr,
"usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]);
320 char *weights = (argc > 4) ? argv[4] : 0;
321 char *filename = (argc > 5) ? argv[5]: 0;
322 if(0==strcmp(argv[2],
"test"))
test_yolo(cfg, weights, filename, thresh);
323 else if(0==strcmp(argv[2],
"train"))
train_yolo(cfg, weights);
324 else if(0==strcmp(argv[2],
"valid"))
validate_yolo(cfg, weights);
326 else if(0==strcmp(argv[2],
"demo"))
demo(cfg, weights, thresh, cam_index, filename,
voc_names, 20, frame_skip, prefix, avg, .5, 0,0,0,0);
void train_yolo(char *cfgfile, char *weightfile)
image resize_image(image im, int w, int h)
pthread_t load_data_in_thread(load_args args)
void set_batch_network(network *net, int b)
void test_yolo(char *cfgfile, char *weightfile, char *filename, float thresh)
box_label * read_boxes(char *filename, int *n)
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, int avg, float hier_thresh, int w, int h, int fps, int fullscreen)
int show_image(image p, const char *name, int ms)
char * find_char_arg(int argc, char **argv, char *arg, char *def)
char * basecfg(char *cfgfile)
void ** list_to_array(list *l)
float train_network(network *net, data d)
void save_image(image p, const char *name)
void validate_yolo(char *cfg, char *weights)
void save_weights(network *net, char *filename)
void run_yolo(int argc, char **argv)
void validate_yolo_recall(char *cfg, char *weights)
void print_yolo_detections(FILE **fps, char *id, int total, int classes, int w, int h, detection *dets)
image load_image_color(char *filename, int w, int h)
float find_float_arg(int argc, char **argv, char *arg, float def)
float get_current_rate(network *net)
float sec(clock_t clocks)
int find_int_arg(int argc, char **argv, char *arg, int def)
network * load_network(char *cfg, char *weights, int clear)
void * load_thread(void *ptr)
float box_iou(box a, box b)
size_t get_current_batch(network *net)
void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes)
void find_replace(char *str, char *orig, char *rep, char *output)
list * get_paths(char *filename)