// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/coco.c
// Function: validate_coco_recall
void validate_coco_recall(char *cfgfile, char *weightfile)
{
    network *net = load_network(cfgfile, weightfile, 0);
    set_batch_network(net, 1);
    fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
    srand(time(0));

    char *base = "results/comp4_det_test_";
    list *plist = get_paths("/home/pjreddie/data/voc/test/2007_test.txt");
    char **paths = (char **)list_to_array(plist);

    layer l = net->layers[net->n-1];
    int classes = l.classes;
    int side = l.side;

    int j, k;
    FILE **fps = calloc(classes, sizeof(FILE *));
    for(j = 0; j < classes; ++j){
        char buff[1024];
        snprintf(buff, 1024, "%s%s.txt", base, coco_classes[j]);
        fps[j] = fopen(buff, "w");
    }

    int m = plist->size;
    int i=0;

    float thresh = .001;
    int nms = 0;
    float iou_thresh = .5;

    int total = 0;
    int correct = 0;
    int proposals = 0;
    float avg_iou = 0;

    for(i = 0; i < m; ++i){
        char *path = paths[i];
        image orig = load_image_color(path, 0, 0);
        image sized = resize_image(orig, net->w, net->h);
        char *id = basecfg(path);
        network_predict(net, sized.data);

        int nboxes = 0;
        detection *dets = get_network_boxes(net, orig.w, orig.h, thresh, 0, 0, 1, &nboxes);
        if (nms) do_nms_obj(dets, side*side*l.n, 1, nms);

        char labelpath[4096];
        find_replace(path, "images", "labels", labelpath);
        find_replace(labelpath, "JPEGImages", "labels", labelpath);
        find_replace(labelpath, ".jpg", ".txt", labelpath);
        find_replace(labelpath, ".JPEG", ".txt", labelpath);

        int num_labels = 0;
        box_label *truth = read_boxes(labelpath, &num_labels);
        for(k = 0; k < side*side*l.n; ++k){
            if(dets[k].objectness > thresh){
                ++proposals;
            }
        }
        for (j = 0; j < num_labels; ++j) {
            ++total;
            box t = {truth[j].x, truth[j].y, truth[j].w, truth[j].h};
            float best_iou = 0;
            for(k = 0; k < side*side*l.n; ++k){
                float iou = box_iou(dets[k].bbox, t);
                if(dets[k].objectness > thresh && iou > best_iou){
                    best_iou = iou;
                }
            }
            avg_iou += best_iou;
            if(best_iou > iou_thresh){
                ++correct;
            }
        }
        free_detections(dets, nboxes);
        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);
        free(id);
        free_image(orig);
        free_image(sized);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10d8, %rsp           # imm = 0x10D8
xorl %edx, %edx
callq 0x316bc
movq %rax, %rbx
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x320a7
movq 0x60449(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
cvtss2sd 0x34(%rbx), %xmm0
cvtss2sd 0x38(%rbx), %xmm1
cvtss2sd 0x3c(%rbx), %xmm2
leaq 0x4e408(%rip), %rsi     # 0x59fd0
movb $0x3, %al
callq 0x3270
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
leaq 0x4f4fc(%rip), %rdi     # 0x5b0e0
callq 0x2af38
movq %rax, 0x60(%rsp)
movq %rax, %rdi
callq 0x11928
movq %rax, 0x80(%rsp)
movq 0x20(%rbx), %rax
movq %rbx, 0x88(%rsp)
movslq (%rbx), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x41c(%rax,%rcx), %edx
movl %edx, 0x50(%rsp)
movl -0x40c(%rax,%rcx), %edx
movq %rdx, 0x30(%rsp)
movslq -0x3a4(%rax,%rcx), %rbx
testq %rbx, %rbx
jle 0xbc90
shlq $0x3, %rbx
leaq 0x4f6c3(%rip), %r15     # 0x5b306
leaq 0x4f47e(%rip), %r12     # 0x5b0c8
leaq 0xd0(%rsp), %r13
leaq 0x4f6ce(%rip), %rbp     # 0x5b327
xorl %r14d, %r14d
leaq 0x606cd(%rip), %rax     # 0x6c330
movq (%r14,%rax), %r8
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x3180
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3390
addq $0x8, %r14
cmpq %r14, %rbx
jne 0xbc5c
movq 0x60(%rsp), %rax
movslq (%rax), %rax
movq %rax, 0x78(%rsp)
testq %rax, %rax
jle 0xbff0
movq 0x30(%rsp), %rax
imull %eax, %eax
imull 0x50(%rsp), %eax
movq %rax, 0x30(%rsp)
imulq $0x30, %rax, %r13
xorps %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
xorl %ecx, %ecx
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %ebx, %ebx
movl %ebx, 0x24(%rsp)
movq 0x80(%rsp), %rax
movq %rcx, 0x98(%rsp)
movq (%rax,%rcx,8), %rbp
leaq 0x38(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x16ac9
movq 0x88(%rsp), %rbx
movl 0x90(%rbx), %edx
movl 0x94(%rbx), %esi
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x170fa
movq %rbp, %rdi
callq 0xef02
movq %rax, 0x90(%rsp)
movq 0xb8(%rsp), %rsi
movq %rbx, %rdi
callq 0x32690
andl $0x0, 0x2c(%rsp)
movl 0x38(%rsp), %esi
movl 0x3c(%rsp), %edx
xorps %xmm1, %xmm1
movq %rbx, %rdi
movss 0x4c8ed(%rip), %xmm0    # 0x58654
xorl %ecx, %ecx
pushq $0x1
popq %r8
leaq 0x2c(%rsp), %r9
callq 0x32a67
movq %rax, %r14
movq %rbp, %rdi
leaq 0x4cccb(%rip), %rsi     # 0x58a4f
leaq 0x4cccb(%rip), %rbx     # 0x58a56
movq %rbx, %rdx
leaq 0xd0(%rsp), %rbp
movq %rbp, %rcx
callq 0xf02d
movq %rbp, %rdi
leaq 0x4ccb5(%rip), %rsi     # 0x58a5d
movq %rbx, %rdx
movq %rbp, %rcx
callq 0xf02d
movq %rbp, %rdi
leaq 0x4ba6f(%rip), %rsi     # 0x5782c
leaq 0x4eb4d(%rip), %rbx     # 0x5a911
movq %rbx, %rdx
movq %rbp, %rcx
callq 0xf02d
movq %rbp, %rdi
leaq 0x4cc94(%rip), %rsi     # 0x58a6d
movq %rbx, %rdx
movq %rbp, %rcx
callq 0xf02d
andl $0x0, 0x28(%rsp)
movq %rbp, %rdi
leaq 0x28(%rsp), %rsi
callq 0x2b377
movq %rax, 0xa0(%rsp)
cmpl $0x0, 0x30(%rsp)
jle 0xbe35
xorl %eax, %eax
movss 0x20(%rsp), %xmm1
movss 0x4c83f(%rip), %xmm2    # 0x58654
movl 0x24(%rsp), %edx
movss 0x28(%r14,%rax), %xmm0
xorl %ecx, %ecx
ucomiss %xmm2, %xmm0
seta %cl
addl %ecx, %edx
addq $0x30, %rax
cmpq %rax, %r13
jne 0xbe19
jmp 0xbe3f
movss 0x20(%rsp), %xmm1
movl 0x24(%rsp), %edx
movl %edx, 0x24(%rsp)
movl 0x28(%rsp), %eax
testl %eax, %eax
jle 0xbf1d
xorl %ebp, %ebp
cmpl $0x0, 0x30(%rsp)
jle 0xbef5
movss %xmm1, 0x20(%rsp)
imulq $0x24, %rbp, %rax
movq 0xa0(%rsp), %rcx
movsd 0x4(%rcx,%rax), %xmm0
movaps %xmm0, 0x50(%rsp)
movsd 0xc(%rcx,%rax), %xmm0
movaps %xmm0, 0xc0(%rsp)
xorps %xmm1, %xmm1
xorl %ebx, %ebx
movaps %xmm1, 0x60(%rsp)
movsd (%r14,%rbx), %xmm0
movsd 0x8(%r14,%rbx), %xmm1
movaps 0x50(%rsp), %xmm2
movaps 0xc0(%rsp), %xmm3
callq 0x389b3
movaps 0x60(%rsp), %xmm4
movaps %xmm4, %xmm1
cmpltps %xmm0, %xmm1
movss 0x28(%r14,%rbx), %xmm2
movss 0x4c789(%rip), %xmm3    # 0x58654
cmpltps %xmm2, %xmm3
andps %xmm1, %xmm3
movd %xmm3, %eax
testb $0x1, %al
jne 0xbedd
movaps %xmm4, %xmm0
addq $0x30, %rbx
movaps %xmm0, %xmm1
cmpq %rbx, %r13
jne 0xbe8c
movl 0x28(%rsp), %eax
movss 0x20(%rsp), %xmm1
jmp 0xbef8
xorps %xmm0, %xmm0
incl %r15d
addss %xmm0, %xmm1
xorl %ecx, %ecx
ucomiss 0x4935c(%rip), %xmm0    # 0x55264
seta %cl
addl %ecx, %r12d
incq %rbp
movslq %eax, %rcx
cmpq %rcx, %rbp
jl 0xbe51
movss %xmm1, 0x20(%rsp)
movl 0x2c(%rsp), %esi
movq %r14, %rdi
callq 0x32ac9
movl 0x24(%rsp), %ebx
cvtsi2ss %ebx, %xmm0
movq 0x98(%rsp), %rdx
leaq 0x1(%rdx), %r14
cvtsi2ss %r14d, %xmm1
movq 0x600a9(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x20(%rsp), %xmm1
mulss 0x4930c(%rip), %xmm1    # 0x55274
cvtsi2ss %r15d, %xmm2
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
cvtsi2sd %r12d, %xmm2
mulsd 0x4e366(%rip), %xmm2    # 0x5a2e8
cvtsi2sd %r15d, %xmm3
divsd %xmm3, %xmm2
leaq 0x4f179(%rip), %rsi     # 0x5b10b
movl %r12d, %ecx
movl %r15d, %r8d
movb $0x3, %al
callq 0x3270
movq 0x90(%rsp), %rdi
callq 0x3040
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq 0xb8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xa8(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq %r14, %rcx
cmpq 0x78(%rsp), %r14
jne 0xbccf
addq $0x10d8, %rsp           # imm = 0x10D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq