// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/classifier.c
// Function: validate_classifier_multi
void validate_classifier_multi(char *datacfg, char *cfg, char *weights)
{
    int i, j;
    network *net = load_network(cfg, weights, 0);
    set_batch_network(net, 1);
    srand(time(0));

    list *options = read_data_cfg(datacfg);

    char *label_list = option_find_str(options, "labels", "data/labels.list");
    char *valid_list = option_find_str(options, "valid", "data/train.list");
    int classes = option_find_int(options, "classes", 2);
    int topk = option_find_int(options, "top", 1);

    char **labels = get_labels(label_list);
    list *plist = get_paths(valid_list);
    //int scales[] = {224, 288, 320, 352, 384};
    int scales[] = {224, 256, 288, 320};
    int nscales = sizeof(scales)/sizeof(scales[0]);

    char **paths = (char **)list_to_array(plist);
    int m = plist->size;
    free_list(plist);

    float avg_acc = 0;
    float avg_topk = 0;
    int *indexes = calloc(topk, sizeof(int));

    for(i = 0; i < m; ++i){
        int class = -1;
        char *path = paths[i];
        for(j = 0; j < classes; ++j){
            if(strstr(path, labels[j])){
                class = j;
                break;
            }
        }
        float *pred = calloc(classes, sizeof(float));
        image im = load_image_color(paths[i], 0, 0);
        for(j = 0; j < nscales; ++j){
            image r = resize_max(im, scales[j]);
            resize_network(net, r.w, r.h);
            float *p = network_predict(net, r.data);
            if(net->hierarchy) hierarchy_predictions(p, net->outputs, net->hierarchy, 1 , 1);
            axpy_cpu(classes, 1, p, 1, pred, 1);
            flip_image(r);
            p = network_predict(net, r.data);
            axpy_cpu(classes, 1, p, 1, pred, 1);
            if(r.data != im.data) free_image(r);
        }
        free_image(im);
        top_k(pred, classes, topk, indexes);
        free(pred);
        if(indexes[0] == class) avg_acc += 1;
        for(j = 0; j < topk; ++j){
            if(indexes[j] == class) avg_topk += 1;
        }

        printf("%d: top 1: %f, top %d: %f\n", i, avg_acc/(i+1), topk, avg_topk/(i+1));
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %r14
xorl %r15d, %r15d
movq %rsi, %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x22658
movq %rax, %rbx
pushq $0x1
popq %rbp
movq %rax, %rdi
movl %ebp, %esi
callq 0x22f00
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
movq %r14, %rdi
callq 0x29598
movq %rax, %r14
leaq 0xe0d4(%rip), %rsi      # 0x4f9a6
leaq 0x102ab(%rip), %rdx     # 0x51b84
movq %rax, %rdi
callq 0x29737
movq %rax, %r12
leaq 0xd699(%rip), %rsi      # 0x4ef84
leaq 0x1023e(%rip), %rdx     # 0x51b30
movq %r14, %rdi
callq 0x29737
movq %rax, 0x20(%rsp)
leaq 0xe8e5(%rip), %rsi      # 0x501eb
pushq $0x2
popq %rdx
movq %r14, %rdi
callq 0x2977d
movl %eax, 0x1c(%rsp)
leaq 0x10570(%rip), %rsi     # 0x51e8c
movq %r14, %rdi
movl %ebp, %edx
callq 0x2977d
movl %eax, %r13d
movq %r12, %rdi
callq 0x1e673
movq %rax, 0x80(%rsp)
movq 0x20(%rsp), %rdi
callq 0x1c8c8
movq %rax, %r14
movq %rax, %rdi
callq 0x72f5
movq %rax, 0x68(%rsp)
movl (%r14), %r12d
movq %r14, %rdi
callq 0x72c6
movl %r13d, 0x2c(%rsp)
movslq %r13d, %r14
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x3250
movl 0x1c(%rsp), %edx
movslq %edx, %rcx
movq %rcx, 0x58(%rsp)
testl %ecx, %ecx
movl $0x0, %ecx
cmovgl %edx, %ecx
movq %rcx, 0x88(%rsp)
testl %r14d, %r14d
cmovlel %r15d, %r14d
movq %r14, 0x60(%rsp)
movq %rax, 0x50(%rsp)
testl %r12d, %r12d
cmovlel %r15d, %r12d
movq %r12, 0x70(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x28(%rsp)
movss %xmm0, 0x18(%rsp)
movl 0x1c(%rsp), %r13d
cmpq 0x70(%rsp), %r15
je 0x41c2d
movq 0x68(%rsp), %rax
movq (%rax,%r15,8), %r12
xorl %r14d, %r14d
movq %r15, 0x78(%rsp)
cmpq %r14, 0x88(%rsp)
je 0x41a04
movq 0x80(%rsp), %rax
movq (%rax,%r14,8), %rsi
movq %r12, %rdi
callq 0x34b0
testq %rax, %rax
jne 0x41a0e
incq %r14
jmp 0x419dc
pushq $-0x1
popq %rax
movq %rax, 0x48(%rsp)
jmp 0x41a13
movq %r14, 0x48(%rsp)
movq 0x58(%rsp), %rdi
pushq $0x4
popq %rsi
callq 0x3250
movq %rax, 0x20(%rsp)
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xbf36
xorl %r15d, %r15d
cmpq $0x10, %r15
je 0x41b49
leaq 0x10123(%rip), %rax     # 0x51b70
movl (%r15,%rax), %esi
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x90(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x30(%rsp), %rdi
callq 0xe8f9
movl 0x30(%rsp), %esi
movl 0x34(%rsp), %edx
movq %rbx, %rdi
callq 0x22f25
movq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x233e2
movq %rax, %r12
movq 0xd0(%rbx), %rdx
testq %rdx, %rdx
je 0x41ab3
movl 0x84(%rbx), %esi
movq %r12, %rdi
movl %ebp, %ecx
movl %ebp, %r8d
callq 0x324ad
movl %r13d, %edi
movss 0xa54a(%rip), %xmm0     # 0x4c008
movq %r12, %rsi
movl %ebp, %edx
movq 0x20(%rsp), %r14
movq %r14, %rcx
movl %ebp, %r8d
callq 0x1b3ed
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xcb93
movq 0x40(%rsp), %rsi
movq %rbx, %r12
movq %rbx, %rdi
callq 0x233e2
movl %r13d, %edi
movss 0xa502(%rip), %xmm0     # 0x4c008
movq %rax, %rsi
movl %ebp, %edx
movq %r14, %rcx
movl %ebp, %r8d
callq 0x1b3ed
movq 0x40(%rsp), %rax
cmpq 0xa0(%rsp), %rax
je 0x41b3d
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
addq $0x4, %r15
movq %r12, %rbx
jmp 0x41a3c
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x90(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x20(%rsp), %r14
movq %r14, %rdi
movl 0x1c(%rsp), %esi
movl 0x2c(%rsp), %edx
movq 0x50(%rsp), %r15
movq %r15, %rcx
callq 0x438a
movq %r14, %rdi
callq 0x3040
movl (%r15), %eax
movss 0x18(%rsp), %xmm3
addss 0xa46b(%rip), %xmm3     # 0x4c008
xorl %ecx, %ecx
movq 0x78(%rsp), %rsi
movq 0x60(%rsp), %rdx
movss 0x28(%rsp), %xmm2
movq 0x48(%rsp), %rdi
cmpq %rcx, %rdx
je 0x41bd5
movaps %xmm2, %xmm0
addss 0xa444(%rip), %xmm0     # 0x4c008
cmpl %edi, (%r15,%rcx,4)
je 0x41bcd
movaps %xmm2, %xmm0
incq %rcx
movaps %xmm0, %xmm2
jmp 0x41bb4
cmpl %edi, %eax
je 0x41bdf
movss 0x18(%rsp), %xmm3
movss %xmm3, 0x20(%rsp)
leaq 0x1(%rsi), %r14
cvtsi2ss %r14d, %xmm1
movaps %xmm3, %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movss %xmm2, 0x28(%rsp)
divss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm1
leaq 0xffdc(%rip), %rdi      # 0x51bea
movl 0x2c(%rsp), %edx
movb $0x2, %al
callq 0x3160
movq %r14, %r15
movss 0x20(%rsp), %xmm0
movss %xmm0, 0x18(%rsp)
jmp 0x419c0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq