29 l.
cost = calloc(1,
sizeof(
float));
44 fprintf(stderr,
"Detection Layer\n");
58 for(b = 0; b < l.
batch; ++b){
60 for (i = 0; i < locations; ++i) {
63 l.
output + index + offset);
76 memset(l.
delta, 0, size *
sizeof(
float));
77 for (b = 0; b < l.
batch; ++b){
79 for (i = 0; i < locations; ++i) {
81 int is_obj = net.
truth[truth_index];
82 for (j = 0; j < l.
n; ++j) {
83 int p_index = index + locations*l.
classes + i*l.
n + j;
86 avg_anyobj += l.
output[p_index];
97 int class_index = index + i*l.
classes;
98 for(j = 0; j < l.
classes; ++j) {
101 if(net.
truth[truth_index + 1 + j]) avg_cat += l.
output[class_index+j];
102 avg_allcat += l.
output[class_index+j];
109 for(j = 0; j < l.
n; ++j){
110 int box_index = index + locations*(l.
classes + l.
n) + (i*l.
n + j) * l.
coords;
120 float iou =
box_iou(out, truth);
123 if(best_iou > 0 || iou > 0){
129 if(rmse < best_rmse){
137 if(truth.
w*truth.
h < .1){
144 best_index = rand()%l.
n;
147 int box_index = index + locations*(l.
classes + l.
n) + (i*l.
n + best_index) * l.
coords;
148 int tbox_index = truth_index + 1 + l.
classes;
157 float iou =
box_iou(out, truth);
160 int p_index = index + locations*l.
classes + i*l.
n + best_index;
163 avg_obj += l.
output[p_index];
179 *(l.
cost) += pow(1-iou, 2);
186 float *costs = calloc(l.
batch*locations*l.
n,
sizeof(
float));
187 for (b = 0; b < l.
batch; ++b) {
189 for (i = 0; i < locations; ++i) {
190 for (j = 0; j < l.
n; ++j) {
191 int p_index = index + locations*l.
classes + i*l.
n + j;
192 costs[b*locations*l.
n + i*l.
n + j] = l.
delta[p_index]*l.
delta[p_index];
198 float cutoff = costs[indexes[99]];
199 for (b = 0; b < l.
batch; ++b) {
201 for (i = 0; i < locations; ++i) {
202 for (j = 0; j < l.
n; ++j) {
203 int p_index = index + locations*l.
classes + i*l.
n + j;
215 printf(
"Detection Avg IOU: %f, Pos Cat: %f, All Cat: %f, Pos Obj: %f, Any Obj: %f, count: %d\n", avg_iou/count, avg_cat/count, avg_allcat/(count*l.
classes), avg_obj/count, avg_anyobj/(l.
batch*locations*l.
n), count);
228 float *predictions = l.
output;
230 for (i = 0; i < l.
side*l.
side; ++i){
231 int row = i / l.
side;
232 int col = i % l.
side;
233 for(n = 0; n < l.
n; ++n){
234 int index = i*l.
n + n;
236 float scale = predictions[p_index];
239 b.
x = (predictions[box_index + 0] + col) / l.
side * w;
240 b.
y = (predictions[box_index + 1] + row) / l.
side * h;
241 b.
w = pow(predictions[box_index + 2], (l.
sqrt?2:1)) * w;
242 b.
h = pow(predictions[box_index + 3], (l.
sqrt?2:1)) * h;
243 dets[index].
bbox = b;
245 for(j = 0; j < l.
classes; ++j){
247 float prob = scale*predictions[class_index+j];
248 dets[index].
prob[j] = (prob > thresh) ? prob : 0;
detection_layer make_detection_layer(int batch, int inputs, int n, int side, int classes, int coords, int rescore)
void(* forward_gpu)(struct layer, struct network)
void(* backward_gpu)(struct layer, struct network)
void top_k(float *a, int n, int k, int *index)
void axpy_gpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY)
void backward_detection_layer(const detection_layer l, network net)
void(* forward)(struct layer, struct network)
void forward_detection_layer(const detection_layer l, network net)
void softmax(float *input, int n, float temp, int stride, float *output)
void get_detection_detections(layer l, int w, int h, float thresh, detection *dets)
float box_rmse(box a, box b)
void axpy_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY)
void(* backward)(struct layer, struct network)
void copy_gpu(int N, float *X, int INCX, float *Y, int INCY)
float box_iou(box a, box b)
box float_to_box(float *f, int stride)
float mag_array(float *a, int n)