AlexeyAB
2018-03-31 bf738fb0e3ae4f7a21d36037d7f0666a583873a7
Sort anchors
2 files modified
27 ■■■■ changed files
src/detector.c 26 ●●●● patch | view | raw | blame | history
src/yolo_layer.c 1 ●●●● patch | view | raw | blame | history
src/detector.c
@@ -820,6 +820,20 @@
}
#ifdef OPENCV
typedef struct {
    float w, h;
} anchors_t;
int anchors_comparator(const void *pa, const void *pb)
{
    anchors_t a = *(anchors_t *)pa;
    anchors_t b = *(anchors_t *)pb;
    float diff = b.w - a.w;
    if (diff < 0) return 1;
    else if (diff > 0) return -1;
    return 0;
}
void calc_anchors(char *datacfg, int num_of_clusters, int width, int height, int show)
{
    printf("\n num_of_clusters = %d, width = %d, height = %d \n", num_of_clusters, width, height);
@@ -886,7 +900,10 @@
        cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10000, 0), attemps, 
        0, KMEANS_PP_CENTERS,
        centers, &compactness);
    // sort anchors
    qsort(centers->data.fl, num_of_clusters, 2*sizeof(float), anchors_comparator);
    //orig 2.0 anchors = 1.08,1.19,  3.42,4.41,  6.63,11.38,  9.42,5.11,  16.62,10.52
    //float orig_anch[] = { 1.08,1.19,  3.42,4.41,  6.63,11.38,  9.42,5.11,  16.62,10.52 };
    // worse than ours (even for 19x19 final size - for input size 608x608)
@@ -943,9 +960,12 @@
    printf("anchors = ");
    for (i = 0; i < num_of_clusters; ++i) {
        sprintf(buff, "%2.4f,%2.4f", centers->data.fl[i * 2], centers->data.fl[i * 2 + 1]);
        printf("%s, ", buff);
        printf("%s", buff);
        fwrite(buff, sizeof(char), strlen(buff), fw);
        if (i + 1 < num_of_clusters) fwrite(", ", sizeof(char), 2, fw);;
        if (i + 1 < num_of_clusters) {
            fwrite(", ", sizeof(char), 2, fw);
            printf(", ");
        }
    }
    printf("\n");
    fclose(fw);
src/yolo_layer.c
@@ -39,7 +39,6 @@
    l.outputs = h*w*n*(classes + 4 + 1);
    l.inputs = l.outputs;
    l.max_boxes = max_boxes;
    printf(" l.max_boxes = %d \n", l.max_boxes);
    l.truths = l.max_boxes*(4 + 1); // 90*(4 + 1);
    l.delta = calloc(batch*l.outputs, sizeof(float));
    l.output = calloc(batch*l.outputs, sizeof(float));