File: 01-detection-backend.patch

package info (click to toggle)
berrynet 3.10.2-2
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,572 kB
  • sloc: python: 6,286; javascript: 2,373; xml: 1,094; sh: 738; makefile: 33
file content (174 lines) | stat: -rw-r--r-- 7,397 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
diff --git a/Makefile b/Makefile
index 7ba6b25..31950ce 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 GPU=0
 CUDNN=0
-OPENCV=0
+OPENCV=1
 NNPACK=1
 ARM_NEON=1
 DEBUG=0
diff --git a/examples/coco.c b/examples/coco.c
index a07906e..170af71 100644
--- a/examples/coco.c
+++ b/examples/coco.c
@@ -342,7 +342,7 @@ void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh)
         printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
         get_detection_boxes(l, 1, 1, thresh, probs, boxes, 0);
         if (nms) do_nms_sort(boxes, probs, l.side*l.side*l.n, l.classes, nms);
-        draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, coco_classes, alphabet, 80);
+        draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, coco_classes, alphabet, 80, 0);
         save_image(im, "prediction");
         show_image(im, "predictions");
         free_image(im);
diff --git a/examples/detector.c b/examples/detector.c
index 3c4a107..f2de3cc 100644
--- a/examples/detector.c
+++ b/examples/detector.c
@@ -581,6 +581,9 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
     list *options = read_data_cfg(datacfg);
     char *name_list = option_find_str(options, "names", "data/names.list");
     char **names = get_labels(name_list);
+    char done[256];
+    FILE *done_signal = NULL;
+    memset(done, 0, 256);
 
     image **alphabet = load_alphabet();
     network net = parse_network_cfg(cfgfile);
@@ -621,6 +624,7 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
 		//resize_network(&net, sized.w, sized.h);
 #endif
 		layer l = net.layers[net.n-1];
+        sprintf(done, "%s.txt.done", input);
 
         box *boxes = calloc(l.w*l.h*l.n, sizeof(box));
         float **probs = calloc(l.w*l.h*l.n, sizeof(float *));
@@ -634,7 +638,7 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
         get_region_boxes(l, im.w, im.h, net.w, net.h, thresh, probs, boxes, 0, 0, hier_thresh, 1);
         if (nms) do_nms_obj(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, names, alphabet, l.classes);
+        draw_detections(im, l.w*l.h*l.n, thresh, boxes, probs, names, alphabet, l.classes, input);
         if(outfile){
             save_image(im, outfile);
         }
@@ -650,11 +654,13 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
             cvDestroyAllWindows();
 #endif
         }
+        done_signal = fopen(done, "w");
 
         free_image(im);
         free_image(sized);
         free(boxes);
         free_ptrs((void **)probs, l.w*l.h*l.n);
+        fclose(done_signal);
         if (filename) break;
     }
 #ifdef NNPACK
diff --git a/examples/yolo.c b/examples/yolo.c
index 5b3fd16..9e74736 100644
--- a/examples/yolo.c
+++ b/examples/yolo.c
@@ -309,7 +309,7 @@ void test_yolo(char *cfgfile, char *weightfile, char *filename, float thresh)
         get_detection_boxes(l, 1, 1, thresh, probs, boxes, 0);
         if (nms) do_nms_sort(boxes, probs, l.side*l.side*l.n, l.classes, nms);
         //draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, voc_names, alphabet, 20);
-        draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, voc_names, alphabet, 20);
+        draw_detections(im, l.side*l.side*l.n, thresh, boxes, probs, voc_names, alphabet, 20, 0);
         save_image(im, "predictions");
         show_image(im, "predictions");
 
diff --git a/include/darknet.h b/include/darknet.h
index b6b9402..2de7cc0 100644
--- a/include/darknet.h
+++ b/include/darknet.h
@@ -695,7 +695,7 @@ float box_iou(box a, box b);
 void do_nms(box *boxes, float **probs, int total, int classes, float thresh);
 data load_all_cifar10();
 box_label *read_boxes(char *filename, int *n);
-void draw_detections(image im, int num, float thresh, box *boxes, float **probs, char **names, image **labels, int classes);
+void draw_detections(image im, int num, float thresh, box *boxes, float **probs, char **names, image **labels, int classes, char* result_file);
 
 matrix network_predict_data(network net, data test);
 image **load_alphabet();
diff --git a/src/demo.c b/src/demo.c
index 9dc4946..0030d0d 100644
--- a/src/demo.c
+++ b/src/demo.c
@@ -77,7 +77,7 @@ void *detect_in_thread(void *ptr)
     printf("\nFPS:%.1f\n",fps);
     printf("Objects:\n\n");
     image display = buff[(buff_index+2) % 3];
-    draw_detections(display, demo_detections, demo_thresh, boxes, probs, demo_names, demo_alphabet, demo_classes);
+    draw_detections(display, demo_detections, demo_thresh, boxes, probs, demo_names, demo_alphabet, demo_classes, 0);
 
     demo_index = (demo_index + 1)%demo_frame;
     running = 0;
diff --git a/src/image.c b/src/image.c
index 83ed382..c1b5b2a 100644
--- a/src/image.c
+++ b/src/image.c
@@ -190,24 +190,33 @@ image **load_alphabet()
     return alphabets;
 }
 
-void draw_detections(image im, int num, float thresh, box *boxes, float **probs, char **names, image **alphabet, int classes)
+void draw_detections(image im, int num, float thresh, box *boxes, float **probs, char **names, image **alphabet, int classes, char* result_file)
 {
     int i;
-
+    FILE *predict_result = NULL;
+    char result_txt[256];
+    memset(result_txt, 0, 256);
+    if (result_file != NULL) {
+        sprintf(result_txt, "%s.txt", result_file);
+        predict_result = fopen(result_txt, "wa");
+        if (!predict_result) {
+            printf("%s: Predict result file opened error\n", result_txt);
+            return;
+        }
+    }
     for(i = 0; i < num; ++i){
         int class = max_index(probs[i], classes);
         float prob = probs[i][class];
         if(prob > thresh){
 
-            int width = im.h * .006;
+            int width = im.h * .012;
 
             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);
+            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);
@@ -232,6 +241,12 @@ void draw_detections(image im, int num, float thresh, box *boxes, float **probs,
             if(bot > im.h-1) bot = im.h-1;
 
             draw_box_width(im, left, top, right, bot, width, red, green, blue);
+            // output: label, accuracy, x, y, width, height
+            if (predict_result)
+                fprintf(predict_result, "%s %.2f %d %d %d %d\n",
+                        names[class], prob, left, top, right - left, bot - top);
+            printf("%s %.2f %d %d %d %d\n",
+                    names[class], prob, left, top, right - left, bot - top);
             if (alphabet) {
                 image label = get_label(alphabet, names[class], (im.h*.03)/10);
                 draw_label(im, top + width, left, label, rgb);
@@ -239,6 +254,8 @@ void draw_detections(image im, int num, float thresh, box *boxes, float **probs,
             }
         }
     }
+    if (predict_result)
+        fclose(predict_result);
 }
 
 void transpose_image(image im)