|
|
@ -694,6 +694,22 @@ int num_detections(network *net, float thresh) |
|
|
|
return s; |
|
|
|
return s; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int num_detections_custom(network *net, float thresh, int b) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
int s = 0; |
|
|
|
|
|
|
|
for (i = 0; i < net->n; ++i) { |
|
|
|
|
|
|
|
layer l = net->layers[i]; |
|
|
|
|
|
|
|
if (l.type == YOLO) { |
|
|
|
|
|
|
|
s += yolo_num_detections_custom(l, thresh, b); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (l.type == DETECTION || l.type == REGION) { |
|
|
|
|
|
|
|
s += l.w*l.h*l.n; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return s; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
detection *make_network_boxes(network *net, float thresh, int *num) |
|
|
|
detection *make_network_boxes(network *net, float thresh, int *num) |
|
|
|
{ |
|
|
|
{ |
|
|
|
layer l = net->layers[net->n - 1]; |
|
|
|
layer l = net->layers[net->n - 1]; |
|
|
@ -710,6 +726,21 @@ detection *make_network_boxes(network *net, float thresh, int *num) |
|
|
|
return dets; |
|
|
|
return dets; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
detection *make_network_boxes_custom(network *net, float thresh, int *num, int batch) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
layer l = net->layers[net->n - 1]; |
|
|
|
|
|
|
|
int nboxes = num_detections_custom(net, thresh, batch); |
|
|
|
|
|
|
|
if (num) *num = nboxes; |
|
|
|
|
|
|
|
detection* dets = (detection*)calloc(nboxes, sizeof(detection)); |
|
|
|
|
|
|
|
for (i = 0; i < nboxes; ++i) { |
|
|
|
|
|
|
|
dets[i].prob = (float*)calloc(l.classes, sizeof(float)); |
|
|
|
|
|
|
|
if (l.coords > 4) { |
|
|
|
|
|
|
|
dets[i].mask = (float*)calloc(l.coords - 4, sizeof(float)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return dets; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void custom_get_region_detections(layer l, int w, int h, int net_w, int net_h, float thresh, int *map, float hier, int relative, detection *dets, int letter) |
|
|
|
void custom_get_region_detections(layer l, int w, int h, int net_w, int net_h, float thresh, int *map, float hier, int relative, detection *dets, int letter) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -761,6 +792,33 @@ void fill_network_boxes(network *net, int w, int h, float thresh, float hier, in |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void fill_network_boxes_custom(network *net, int w, int h, float thresh, float hier, int *map, int relative, detection *dets, int letter, int batch) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int prev_classes = -1; |
|
|
|
|
|
|
|
int j; |
|
|
|
|
|
|
|
for (j = 0; j < net->n; ++j) { |
|
|
|
|
|
|
|
layer l = net->layers[j]; |
|
|
|
|
|
|
|
if (l.type == YOLO) { |
|
|
|
|
|
|
|
int count = get_yolo_detections_custom(l, w, h, net->w, net->h, thresh, map, relative, dets, letter, batch); |
|
|
|
|
|
|
|
dets += count; |
|
|
|
|
|
|
|
if (prev_classes < 0) prev_classes = l.classes; |
|
|
|
|
|
|
|
else if (prev_classes != l.classes) { |
|
|
|
|
|
|
|
printf(" Error: Different [yolo] layers have different number of classes = %d and %d - check your cfg-file! \n", |
|
|
|
|
|
|
|
prev_classes, l.classes); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (l.type == REGION) { |
|
|
|
|
|
|
|
custom_get_region_detections(l, w, h, net->w, net->h, thresh, map, hier, relative, dets, letter); |
|
|
|
|
|
|
|
//get_region_detections(l, w, h, net->w, net->h, thresh, map, hier, relative, dets);
|
|
|
|
|
|
|
|
dets += l.w*l.h*l.n; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (l.type == DETECTION) { |
|
|
|
|
|
|
|
get_detection_detections(l, w, h, thresh, dets); |
|
|
|
|
|
|
|
dets += l.w*l.h*l.n; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num, int letter) |
|
|
|
detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num, int letter) |
|
|
|
{ |
|
|
|
{ |
|
|
|
detection *dets = make_network_boxes(net, thresh, num); |
|
|
|
detection *dets = make_network_boxes(net, thresh, num); |
|
|
@ -778,6 +836,14 @@ void free_detections(detection *dets, int n) |
|
|
|
free(dets); |
|
|
|
free(dets); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void free_batch_detections(detNumPair *detNumPairs, int n) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
for(i=0; i<n; ++i) |
|
|
|
|
|
|
|
free_detections(detNumPairs[i].dets,detNumPairs[i].num); |
|
|
|
|
|
|
|
free(detNumPairs); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// JSON format:
|
|
|
|
// JSON format:
|
|
|
|
//{
|
|
|
|
//{
|
|
|
|
// "frame_id":8990,
|
|
|
|
// "frame_id":8990,
|
|
|
@ -849,6 +915,21 @@ float *network_predict_image(network *net, image im) |
|
|
|
return p; |
|
|
|
return p; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
detNumPair* network_predict_custom(network *net, image im, int batch, int w, int h, float thresh, float hier, int *map, int relative, int letter) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
set_batch_network(net, batch); |
|
|
|
|
|
|
|
network_predict(*net, im.data); |
|
|
|
|
|
|
|
detNumPair *pdets = malloc(batch*sizeof(detNumPair)); |
|
|
|
|
|
|
|
int num; |
|
|
|
|
|
|
|
for(int b=0;b<batch;b++){ |
|
|
|
|
|
|
|
detection *dets = make_network_boxes_custom(net, thresh, &num, b); |
|
|
|
|
|
|
|
fill_network_boxes_custom(net, w, h, thresh, hier, map, relative, dets, letter,b);
|
|
|
|
|
|
|
|
pdets[b].num = num; |
|
|
|
|
|
|
|
pdets[b].dets = dets; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return pdets; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float *network_predict_image_letterbox(network *net, image im) |
|
|
|
float *network_predict_image_letterbox(network *net, image im) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//image imr = letterbox_image(im, net->w, net->h);
|
|
|
|
//image imr = letterbox_image(im, net->w, net->h);
|
|
|
|