// File: /workspace/github_c_makefile_star2_O2/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 $0x10c8, %rsp           # imm = 0x10C8
xorl %ebx, %ebx
xorl %edx, %edx
callq 0x22658
movq %rax, %r15
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x22f00
movq 0x1cac1(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
cvtss2sd 0x34(%r15), %xmm0
cvtss2sd 0x38(%r15), %xmm1
cvtss2sd 0x3c(%r15), %xmm2
leaq 0x997d(%rip), %rsi      # 0x50ed0
movb $0x3, %al
callq 0x3270
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
leaq 0xa9c5(%rip), %rdi      # 0x51f34
callq 0x1c8c8
movq %rax, %r14
movq %rax, %rdi
callq 0x72f5
movq 0x20(%r15), %rcx
movq %r15, 0x48(%rsp)
movslq (%r15), %rdx
imulq $0x4a0, %rdx, %rdx      # imm = 0x4A0
movl -0x430(%rcx,%rdx), %esi
imull -0x434(%rcx,%rdx), %esi
imull -0x41c(%rcx,%rdx), %esi
movq %rax, 0x40(%rsp)
testl %esi, %esi
cmovlel %ebx, %esi
movl (%r14), %eax
testl %eax, %eax
cmovlel %ebx, %eax
imulq $0x30, %rsi, %rbx
xorps %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
movl $0x0, 0x2c(%rsp)
xorl %r12d, %r12d
movq %rax, 0x38(%rsp)
cmpq %rax, %r14
je 0x478d9
movq 0x40(%rsp), %rax
movq %r14, 0x58(%rsp)
movq (%rax,%r14,8), %r13
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xbf36
movq 0x48(%rsp), %r14
movl 0x90(%r14), %edx
movl 0x94(%r14), %esi
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x78(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x60(%rsp), %rdi
callq 0xc3ee
movq %r13, %rdi
callq 0x41c8
movq %rax, 0x50(%rsp)
movq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x233e2
andl $0x0, 0x28(%rsp)
movl 0x60(%rsp), %esi
movl 0x64(%rsp), %edx
movq %r14, %rdi
movss 0x7f39(%rip), %xmm0     # 0x4f5a4
movss 0x4bc1(%rip), %xmm1     # 0x4c234
xorl %ecx, %ecx
pushq $0x1
popq %rbp
movl %ebp, %r8d
leaq 0x28(%rsp), %r9
callq 0x2379c
movq %rax, %r14
movl 0x28(%rsp), %esi
movq %rax, %rdi
movl %ebp, %edx
movss 0xa63b(%rip), %xmm0     # 0x51cd4
callq 0x2b02e
movq %r13, %rdi
leaq 0x82f7(%rip), %rsi      # 0x4f99f
movl %r15d, %ebp
leaq 0x82f4(%rip), %r15      # 0x4f9a6
movq %r15, %rdx
leaq 0xc0(%rsp), %r13
movq %r13, %rcx
callq 0x42ea
movq %r13, %rdi
leaq 0x82de(%rip), %rsi      # 0x4f9ad
movq %r15, %rdx
movq %r13, %rcx
callq 0x42ea
movq %r13, %rdi
leaq 0x7068(%rip), %rsi      # 0x4e74c
leaq 0xa0de(%rip), %r15      # 0x517c9
movq %r15, %rdx
movq %r13, %rcx
callq 0x42ea
movq %r13, %rdi
leaq 0x82bd(%rip), %rsi      # 0x4f9bd
movq %r15, %rdx
movq %r13, %rcx
callq 0x42ea
andl $0x0, 0x30(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
callq 0x1cd0d
movq %rax, %r13
movl 0x28(%rsp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
imulq $0x30, %rax, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x47754
movss 0x28(%r14,%rcx), %xmm0
xorl %edx, %edx
ucomiss 0x7e5b(%rip), %xmm0     # 0x4f5a4
seta %dl
addl %edx, %ebp
addq $0x30, %rcx
jmp 0x47734
movl %ebp, 0x34(%rsp)
xorl %r15d, %r15d
movslq 0x30(%rsp), %rax
cmpq %rax, %r15
jge 0x47823
imulq $0x24, %r15, %rax
movsd 0x4(%r13,%rax), %xmm0
movaps %xmm0, 0xa0(%rsp)
movsd 0xc(%r13,%rax), %xmm0
movaps %xmm0, 0x90(%rsp)
xorps %xmm4, %xmm4
xorl %ebp, %ebp
cmpq %rbp, %rbx
je 0x477f8
movsd (%r14,%rbp), %xmm0
movsd 0x8(%r14,%rbp), %xmm1
movaps 0xa0(%rsp), %xmm2
movaps 0x90(%rsp), %xmm3
movaps %xmm4, 0xb0(%rsp)
callq 0x2b1cb
movaps 0xb0(%rsp), %xmm4
movaps %xmm4, %xmm1
cmpltps %xmm0, %xmm1
movss 0x28(%r14,%rbp), %xmm2
movss 0x7dc7(%rip), %xmm3     # 0x4f5a4
cmpltps %xmm2, %xmm3
andps %xmm1, %xmm3
movd %xmm3, %eax
testb $0x1, %al
jne 0x477ef
movaps %xmm4, %xmm0
addq $0x30, %rbp
movaps %xmm0, %xmm4
jmp 0x47790
incl %r12d
movss 0x24(%rsp), %xmm0
addss %xmm4, %xmm0
movss %xmm0, 0x24(%rsp)
xorl %eax, %eax
ucomiss 0x4a20(%rip), %xmm4     # 0x4c234
seta %al
addl %eax, 0x2c(%rsp)
incq %r15
jmp 0x4775b
movl 0x34(%rsp), %r15d
cvtsi2ss %r15d, %xmm0
movq 0x58(%rsp), %rdx
leaq 0x1(%rdx), %r14
cvtsi2ss %r14d, %xmm1
movq 0x1c7b6(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x24(%rsp), %xmm1
mulss 0x49e9(%rip), %xmm1     # 0x4c244
cvtsi2ss %r12d, %xmm2
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
movl 0x2c(%rsp), %ecx
cvtsi2sd %ecx, %xmm2
mulsd 0x9970(%rip), %xmm2     # 0x511e8
cvtsi2sd %r12d, %xmm3
divsd %xmm3, %xmm2
leaq 0xa743(%rip), %rsi      # 0x51fcb
movl %r12d, %r8d
movb $0x3, %al
callq 0x3270
movq 0x50(%rsp), %rdi
callq 0x3040
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x78(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x38(%rsp), %rax
jmp 0x475de
addq $0x10c8, %rsp           # imm = 0x10C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq