// File: /workspace/github_c_makefile_star2_O2/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 $0x10c8, %rsp           # imm = 0x10C8
xorl %ebx, %ebx
xorl %edx, %edx
callq 0x22658
movq %rax, %r14
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x22f00
movq 0x20466(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
cvtss2sd 0x34(%r14), %xmm0
cvtss2sd 0x38(%r14), %xmm1
cvtss2sd 0x3c(%r14), %xmm2
leaq 0xd322(%rip), %rsi      # 0x50ed0
movb $0x3, %al
callq 0x3270
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
leaq 0xe3d6(%rip), %rdi      # 0x51fa0
callq 0x1c8c8
movq %rax, 0x70(%rsp)
movq %rax, %rdi
callq 0x72f5
movq %rax, 0x88(%rsp)
movq 0x20(%r14), %rax
movq %r14, 0x90(%rsp)
movslq (%r14), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x41c(%rax,%rcx), %edx
movl %edx, 0x50(%rsp)
movl -0x3a4(%rax,%rcx), %r14d
testl %r14d, %r14d
cmovlel %ebx, %r14d
movl -0x40c(%rax,%rcx), %eax
movq %rax, 0x60(%rsp)
shlq $0x3, %r14
leaq 0xe59b(%rip), %r15      # 0x521c6
leaq 0xe356(%rip), %r12      # 0x51f88
leaq 0xc0(%rsp), %r13
leaq 0xe5a6(%rip), %rbp      # 0x521e7
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x43c79
leaq 0x206f1(%rip), %rax     # 0x64340
movq (%rbx,%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, %rbx
jmp 0x43c43
movq 0x60(%rsp), %rcx
imull %ecx, %ecx
imull 0x50(%rsp), %ecx
xorl %r15d, %r15d
testl %ecx, %ecx
cmovlel %r15d, %ecx
movq 0x70(%rsp), %rax
movl (%rax), %eax
testl %eax, %eax
cmovlel %r15d, %eax
imulq $0x30, %rcx, %rbx
xorps %xmm0, %xmm0
movss %xmm0, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl $0x0, 0x2c(%rsp)
xorl %r12d, %r12d
movq %rax, 0x80(%rsp)
cmpq %rax, %r15
je 0x43fa2
movq 0x88(%rsp), %rax
movq %r15, 0xa0(%rsp)
movq (%rax,%r15,8), %rbp
leaq 0x38(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xbf36
movq 0x90(%rsp), %r14
movl 0x90(%r14), %edx
movl 0x94(%r14), %esi
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xc3ee
movq %rbp, %rdi
callq 0x41c8
movq %rax, 0x98(%rsp)
movq 0xb8(%rsp), %rsi
movq %r14, %rdi
callq 0x233e2
andl $0x0, 0x34(%rsp)
movl 0x38(%rsp), %esi
movl 0x3c(%rsp), %edx
xorps %xmm1, %xmm1
movq %r14, %rdi
movss 0xb841(%rip), %xmm0     # 0x4f5a4
xorl %ecx, %ecx
pushq $0x1
popq %r8
leaq 0x34(%rsp), %r9
callq 0x2379c
movq %rax, %r13
movq %rbp, %rdi
leaq 0xbc1f(%rip), %rsi      # 0x4f99f
leaq 0xbc1f(%rip), %r14      # 0x4f9a6
movq %r14, %rdx
leaq 0xc0(%rsp), %r15
movq %r15, %rcx
callq 0x42ea
movq %r15, %rdi
leaq 0xbc09(%rip), %rsi      # 0x4f9ad
movq %r14, %rdx
movq %r15, %rcx
callq 0x42ea
movq %r15, %rdi
leaq 0xa993(%rip), %rsi      # 0x4e74c
leaq 0xda09(%rip), %r14      # 0x517c9
movq %r14, %rdx
movq %r15, %rcx
callq 0x42ea
movq %r15, %rdi
leaq 0xbbe8(%rip), %rsi      # 0x4f9bd
movq %r14, %rdx
movq %r15, %rcx
callq 0x42ea
andl $0x0, 0x30(%rsp)
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
callq 0x1cd0d
movq %rax, %rbp
xorl %eax, %eax
movl 0x24(%rsp), %edx
cmpq %rax, %rbx
je 0x43e1b
movss 0x28(%r13,%rax), %xmm0
xorl %ecx, %ecx
ucomiss 0xb794(%rip), %xmm0     # 0x4f5a4
seta %cl
addl %ecx, %edx
addq $0x30, %rax
jmp 0x43dfb
movl %edx, 0x24(%rsp)
xorl %r15d, %r15d
movslq 0x30(%rsp), %rax
cmpq %rax, %r15
jge 0x43ed8
imulq $0x24, %r15, %rax
movsd 0x4(%rbp,%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
movsd 0xc(%rbp,%rax), %xmm0
movaps %xmm0, 0x50(%rsp)
xorps %xmm4, %xmm4
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x43ead
movsd (%r13,%r14), %xmm0
movsd 0x8(%r13,%r14), %xmm1
movaps 0x60(%rsp), %xmm2
movaps 0x50(%rsp), %xmm3
movaps %xmm4, 0x70(%rsp)
callq 0x2b1cb
movaps 0x70(%rsp), %xmm4
movaps %xmm4, %xmm1
cmpltps %xmm0, %xmm1
movss 0x28(%r13,%r14), %xmm2
movss 0xb712(%rip), %xmm3     # 0x4f5a4
cmpltps %xmm2, %xmm3
andps %xmm1, %xmm3
movd %xmm3, %eax
testb $0x1, %al
jne 0x43ea4
movaps %xmm4, %xmm0
addq $0x30, %r14
movaps %xmm0, %xmm4
jmp 0x43e50
incl %r12d
movss 0x28(%rsp), %xmm0
addss %xmm4, %xmm0
movss %xmm0, 0x28(%rsp)
xorl %eax, %eax
ucomiss 0x836b(%rip), %xmm4     # 0x4c234
seta %al
addl %eax, 0x2c(%rsp)
incq %r15
jmp 0x43e22
movl 0x34(%rsp), %esi
movq %r13, %rdi
callq 0x237fe
cvtsi2ssl 0x24(%rsp), %xmm0
movq 0xa0(%rsp), %rdx
leaq 0x1(%rdx), %r15
cvtsi2ss %r15d, %xmm1
movq 0x200f6(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x28(%rsp), %xmm1
mulss 0x8329(%rip), %xmm1     # 0x4c244
cvtsi2ss %r12d, %xmm2
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
movl 0x2c(%rsp), %ecx
cvtsi2sd %ecx, %xmm2
mulsd 0xd2b0(%rip), %xmm2     # 0x511e8
cvtsi2sd %r12d, %xmm3
divsd %xmm3, %xmm2
leaq 0xe083(%rip), %rsi      # 0x51fcb
movl %r12d, %r8d
movb $0x3, %al
callq 0x3270
movq 0x98(%rsp), %rdi
callq 0x3040
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0xb8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xa8(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x80(%rsp), %rax
jmp 0x43cc4
addq $0x10c8, %rsp           # imm = 0x10C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq