// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/detector.c
// Function: validate_detector_recall
void validate_detector_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));

    list *plist = get_paths("data/coco_val_5k.list");
    char **paths = (char **)list_to_array(plist);

    layer l = net->layers[net->n-1];

    int j, k;

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

    float thresh = .001;
    float iou_thresh = .5;
    float nms = .4;

    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, sized.w, sized.h, thresh, .5, 0, 1, &nboxes);
        if (nms) do_nms_obj(dets, nboxes, 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 < nboxes; ++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 < l.w*l.h*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;
            }
        }

        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 %ebx, %ebx
xorl %edx, %edx
callq 0x316bc
movq %rax, %r14
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x320a7
movq 0x5e3ba(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
cvtss2sd 0x34(%r14), %xmm0
cvtss2sd 0x38(%r14), %xmm1
cvtss2sd 0x3c(%r14), %xmm2
leaq 0x4c376(%rip), %rsi     # 0x59fd0
movb $0x3, %al
callq 0x3270
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
leaq 0x4d3fe(%rip), %rdi     # 0x5b074
callq 0x2af38
movq %rax, %r15
movq %rax, %rdi
callq 0x11928
movq %rax, 0x40(%rsp)
movslq (%r15), %rax
movq %rax, 0x38(%rsp)
testq %rax, %rax
jle 0xe00f
movq %r14, %r15
movq 0x20(%r14), %rax
movslq (%r14), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x430(%rax,%rcx), %edx
imull -0x434(%rax,%rcx), %edx
imull -0x41c(%rax,%rcx), %edx
movq %rdx, 0x60(%rsp)
imulq $0x30, %rdx, %rbp
xorps %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
xorl %ecx, %ecx
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %r15, 0x30(%rsp)
movq 0x40(%rsp), %rax
movq %rcx, 0x50(%rsp)
movq (%rax,%rcx,8), %r13
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x16ac9
movl 0x90(%r15), %edx
movl 0x94(%r15), %esi
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x70(%rsp), %rdi
callq 0x170fa
movq %r13, %rdi
callq 0xef02
movq %rax, 0x48(%rsp)
movq 0x80(%rsp), %rsi
movq %r15, %rdi
callq 0x32690
andl $0x0, 0x2c(%rsp)
movl 0x70(%rsp), %esi
movl 0x74(%rsp), %edx
movq %r15, %rdi
movss 0x4a8e9(%rip), %xmm0    # 0x58654
movss 0x474f1(%rip), %xmm1    # 0x55264
xorl %ecx, %ecx
pushq $0x1
popq %r8
leaq 0x2c(%rsp), %r9
callq 0x32a67
movq %rax, %r15
movl 0x2c(%rsp), %esi
movq %rax, %rdi
pushq $0x1
popq %rdx
movss 0x4d07c(%rip), %xmm0    # 0x5ae14
callq 0x386c0
movq %r13, %rdi
leaq 0x4aca8(%rip), %rsi     # 0x58a4f
leaq 0x4aca8(%rip), %rdx     # 0x58a56
leaq 0xd0(%rsp), %r13
movq %r13, %rcx
callq 0xf02d
movq %r13, %rdi
leaq 0x4ac95(%rip), %rsi     # 0x58a5d
leaq 0x4ac87(%rip), %rdx     # 0x58a56
movq %r13, %rcx
callq 0xf02d
movq %r13, %rdi
leaq 0x49a4b(%rip), %rsi     # 0x5782c
leaq 0x4cb29(%rip), %rdx     # 0x5a911
movq %r13, %rcx
callq 0xf02d
movq %r13, %rdi
leaq 0x4ac73(%rip), %rsi     # 0x58a6d
leaq 0x4cb10(%rip), %rdx     # 0x5a911
movq %r13, %rcx
callq 0xf02d
andl $0x0, 0x28(%rsp)
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0x2b377
movq %rax, 0x58(%rsp)
movslq 0x2c(%rsp), %rax
testq %rax, %rax
jle 0xde5b
imulq $0x30, %rax, %rax
xorl %ecx, %ecx
movss 0x24(%rsp), %xmm2
movss 0x4a816(%rip), %xmm1    # 0x58654
movss 0x28(%r15,%rcx), %xmm0
xorl %edx, %edx
ucomiss %xmm1, %xmm0
seta %dl
addl %edx, %r14d
addq $0x30, %rcx
cmpq %rcx, %rax
jne 0xde3e
jmp 0xde61
movss 0x24(%rsp), %xmm2
movl 0x28(%rsp), %eax
testl %eax, %eax
jle 0xdf4e
xorl %r13d, %r13d
cmpl $0x0, 0x60(%rsp)
jle 0xdf27
movss %xmm2, 0x24(%rsp)
movq %rbx, 0x68(%rsp)
imulq $0x24, %r13, %rax
movq 0x58(%rsp), %rcx
movsd 0x4(%rcx,%rax), %xmm0
movaps %xmm0, 0xb0(%rsp)
movsd 0xc(%rcx,%rax), %xmm0
movaps %xmm0, 0xa0(%rsp)
xorps %xmm1, %xmm1
xorl %ebx, %ebx
movaps %xmm1, 0xc0(%rsp)
movsd (%r15,%rbx), %xmm0
movsd 0x8(%r15,%rbx), %xmm1
movaps 0xb0(%rsp), %xmm2
movaps 0xa0(%rsp), %xmm3
callq 0x389b3
movaps 0xc0(%rsp), %xmm4
movaps %xmm4, %xmm1
cmpltps %xmm0, %xmm1
movss 0x28(%r15,%rbx), %xmm2
movss 0x4a75c(%rip), %xmm3    # 0x58654
cmpltps %xmm2, %xmm3
andps %xmm1, %xmm3
movd %xmm3, %eax
testb $0x1, %al
jne 0xdf0a
movaps %xmm4, %xmm0
addq $0x30, %rbx
movaps %xmm0, %xmm1
cmpq %rbx, %rbp
jne 0xdeb0
movl 0x28(%rsp), %eax
movq 0x68(%rsp), %rbx
movss 0x24(%rsp), %xmm2
jmp 0xdf2a
xorps %xmm0, %xmm0
incl %ebx
addss %xmm0, %xmm2
xorl %ecx, %ecx
ucomiss 0x4732b(%rip), %xmm0    # 0x55264
seta %cl
addl %ecx, %r12d
incq %r13
movslq %eax, %rcx
cmpq %rcx, %r13
jl 0xde70
cvtsi2ss %r14d, %xmm0
movq 0x50(%rsp), %rdx
leaq 0x1(%rdx), %r15
cvtsi2ss %r15d, %xmm1
movq 0x5e090(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movss %xmm2, 0x24(%rsp)
movaps %xmm2, %xmm1
mulss 0x472f0(%rip), %xmm1    # 0x55274
cvtsi2ss %ebx, %xmm2
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
cvtsi2sd %r12d, %xmm2
mulsd 0x4c34b(%rip), %xmm2    # 0x5a2e8
cvtsi2sd %ebx, %xmm3
divsd %xmm3, %xmm2
leaq 0x4d15f(%rip), %rsi     # 0x5b10b
movl %r12d, %ecx
movl %ebx, %r8d
movb $0x3, %al
callq 0x3270
movq 0x48(%rsp), %rdi
callq 0x3040
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x70(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq %r15, %rcx
cmpq 0x38(%rsp), %r15
movq 0x30(%rsp), %r15
jne 0xdce3
addq $0x10d8, %rsp           # imm = 0x10D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq