5 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"};
7 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};
13 char *train_images =
"data/coco.trainval.txt";
15 char *backup_directory =
"/home/pjreddie/backup/";
23 int i = *net->
seen/imgs;
60 pthread_join(load_thread, 0);
64 printf(
"Loaded: %lf seconds\n",
sec(clock()-time));
76 if (avg_loss < 0) avg_loss = loss;
77 avg_loss = avg_loss*.9 + loss*.1;
79 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);
80 if(i%1000==0 || (i < 1000 && i%100 == 0)){
82 sprintf(buff,
"%s/%s_%d.weights", backup_directory, base, i);
87 sprintf(buff,
"%s/%s.backup", backup_directory, base);
93 sprintf(buff,
"%s/%s_final.weights", backup_directory, base);
97 static void print_cocos(FILE *fp,
int image_id,
detection *dets,
int num_boxes,
int classes,
int w,
int h)
100 for(i = 0; i < num_boxes; ++i){
101 float xmin = dets[i].
bbox.
x - dets[i].
bbox.
w/2.;
102 float xmax = dets[i].
bbox.
x + dets[i].
bbox.
w/2.;
103 float ymin = dets[i].
bbox.
y - dets[i].
bbox.
h/2.;
104 float ymax = dets[i].
bbox.
y + dets[i].
bbox.
h/2.;
106 if (xmin < 0) xmin = 0;
107 if (ymin < 0) ymin = 0;
108 if (xmax > w) xmax = w;
109 if (ymax > h) ymax = h;
113 float bw = xmax - xmin;
114 float bh = ymax - ymin;
117 if (dets[i].prob[j]) fprintf(fp,
"{\"image_id\":%d, \"category_id\":%d, \"bbox\":[%f, %f, %f, %f], \"score\":%f},\n", image_id,
coco_ids[j], bx, by, bw, bh, dets[i].prob[j]);
124 char *p = strrchr(filename,
'_');
135 char *base =
"results/";
145 snprintf(buff, 1024,
"%s/coco_results.json", base);
146 FILE *fp = fopen(buff,
"w");
155 float iou_thresh = .5;
159 image *val_resized = calloc(nthreads,
sizeof(
image));
161 image *buf_resized = calloc(nthreads,
sizeof(
image));
162 pthread_t *thr = calloc(nthreads,
sizeof(pthread_t));
169 for(t = 0; t < nthreads; ++
t){
170 args.
path = paths[i+
t];
175 time_t start = time(0);
176 for(i = nthreads; i < m+nthreads; i += nthreads){
177 fprintf(stderr,
"%d\n", i);
178 for(t = 0; t < nthreads && i+t-nthreads < m; ++
t){
179 pthread_join(thr[t], 0);
181 val_resized[
t] = buf_resized[
t];
183 for(t = 0; t < nthreads && i+t < m; ++
t){
184 args.
path = paths[i+
t];
189 for(t = 0; t < nthreads && i+t-nthreads < m; ++
t){
190 char *path = paths[i+t-nthreads];
192 float *X = val_resized[
t].
data;
199 print_cocos(fp, image_id, dets, l.
side*l.
side*l.
n, classes, w, h);
205 fseek(fp, -2, SEEK_CUR);
206 fprintf(fp,
"\n]\n");
209 fprintf(stderr,
"Total Detection Time: %f Seconds\n", (
double)(time(0) - start));
219 char *base =
"results/comp4_det_test_";
220 list *plist =
get_paths(
"/home/pjreddie/data/voc/test/2007_test.txt");
228 FILE **fps = calloc(classes,
sizeof(FILE *));
231 snprintf(buff, 1024,
"%s%s.txt", base,
coco_classes[j]);
232 fps[j] = fopen(buff,
"w");
240 float iou_thresh = .5;
247 for(i = 0; i < m; ++i){
248 char *path = paths[i];
258 char labelpath[4096];
260 find_replace(labelpath,
"JPEGImages",
"labels", labelpath);
266 for(k = 0; k < side*side*l.
n; ++k){
267 if(dets[k].objectness > thresh){
271 for (j = 0; j < num_labels; ++j) {
273 box t = {truth[j].
x, truth[j].
y, truth[j].
w, truth[j].
h};
275 for(k = 0; k < side*side*l.
n; ++k){
276 float iou =
box_iou(dets[k].bbox, t);
277 if(dets[k].objectness > thresh && iou > best_iou){
282 if(best_iou > iou_thresh){
287 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);
294 void test_coco(
char *cfgfile,
char *weightfile,
char *filename,
float thresh)
307 strncpy(input, filename, 256);
309 printf(
"Enter Image Path: ");
311 input = fgets(input, 256, stdin);
317 float *X = sized.
data;
320 printf(
"%s: Predicted in %f seconds.\n", input,
sec(clock()-time));
344 fprintf(stderr,
"usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]);
349 char *weights = (argc > 4) ? argv[4] : 0;
350 char *filename = (argc > 5) ? argv[5]: 0;
352 if(0==strcmp(argv[2],
"test"))
test_coco(cfg, weights, filename, thresh);
353 else if(0==strcmp(argv[2],
"train"))
train_coco(cfg, weights);
354 else if(0==strcmp(argv[2],
"valid"))
validate_coco(cfg, weights);
356 else if(0==strcmp(argv[2],
"demo"))
demo(cfg, weights, thresh, cam_index, filename,
coco_classes, 80, frame_skip, prefix, avg, .5, 0,0,0,0);
void run_coco(int argc, char **argv)
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)
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)
int get_coco_image_id(char *filename)
void validate_coco(char *cfg, char *weights)
void save_weights(network *net, char *filename)
image load_image_color(char *filename, int w, int h)
float find_float_arg(int argc, char **argv, char *arg, float def)
void train_coco(char *cfgfile, char *weightfile)
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)
void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh)
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)
void validate_coco_recall(char *cfgfile, char *weightfile)