// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/classifier.c
// Function: validate_classifier_single
void validate_classifier_single(char *datacfg, char *filename, char *weightfile)
{
    int i, j;
    network *net = load_network(filename, weightfile, 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 *leaf_list = option_find_str(options, "leaves", 0);
    if(leaf_list) change_leaves(net->hierarchy, leaf_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);

    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;
            }
        }
        image im = load_image_color(paths[i], 0, 0);
        image crop = center_crop_image(im, net->w, net->h);
        //grayscale_image_3c(crop);
        //show_image(im, "orig");
        //show_image(crop, "cropped");
        //cvWaitKey(0);
        float *pred = network_predict(net, crop.data);
        if(net->hierarchy) hierarchy_predictions(pred, net->outputs, net->hierarchy, 1, 1);

        free_image(im);
        free_image(crop);
        top_k(pred, classes, topk, indexes);

        if(indexes[0] == class) avg_acc += 1;
        for(j = 0; j < topk; ++j){
            if(indexes[j] == class) avg_topk += 1;
        }

        printf("%s, %d, %f, %f, \n", paths[i], class, pred[0], pred[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 $0x88, %rsp
movq %rdi, %rbx
movq %rsi, %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x22658
movq %rax, %r14
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x22f00
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
movq %rbx, %rdi
callq 0x29598
movq %rax, %rbx
leaq 0xe3e3(%rip), %rsi      # 0x4f9a6
leaq 0x105ba(%rip), %rdx     # 0x51b84
movq %rax, %rdi
callq 0x29737
movq %rax, %r15
leaq 0x10629(%rip), %rsi     # 0x51c05
movq %rbx, %rdi
xorl %edx, %edx
callq 0x29737
testq %rax, %rax
je 0x415fa
movq 0xd0(%r14), %rdi
movq %rax, %rsi
callq 0x323e4
movq %r14, 0x38(%rsp)
leaq 0xd97e(%rip), %rsi      # 0x4ef84
leaq 0x10523(%rip), %rdx     # 0x51b30
movq %rbx, %rdi
callq 0x29737
movq %rax, %r12
leaq 0xebcc(%rip), %rsi      # 0x501eb
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x2977d
movl %eax, %r14d
leaq 0x10858(%rip), %rsi     # 0x51e8c
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x2977d
movl %eax, %ebp
movq %r15, %rdi
callq 0x1e673
movq %rax, 0x50(%rsp)
movq %r12, %rdi
callq 0x1c8c8
movq %rax, %rbx
movq %rax, %rdi
callq 0x72f5
movq %rax, 0x30(%rsp)
movl (%rbx), %r15d
movq %rbx, %rdi
callq 0x72c6
movl %ebp, 0x28(%rsp)
movslq %ebp, %rbp
pushq $0x4
popq %rsi
movq %rbp, %rdi
callq 0x3250
testl %r14d, %r14d
movl %r14d, 0x2c(%rsp)
movl $0x0, %ebx
cmovlel %ebx, %r14d
testl %ebp, %ebp
cmovlel %ebx, %ebp
movq %rax, %r12
testl %r15d, %r15d
cmovlel %ebx, %r15d
movq %r15, 0x40(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
movss %xmm0, 0x20(%rsp)
cmpq 0x40(%rsp), %rbx
je 0x4186c
movq %rbx, 0x48(%rsp)
movq 0x30(%rsp), %rax
movq (%rax,%rbx,8), %rbx
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x416f3
movq 0x50(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq %rbx, %rdi
callq 0x34b0
testq %rax, %rax
jne 0x416f9
incq %r15
jmp 0x416d3
pushq $-0x1
popq %rax
movl %eax, %r15d
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xbf36
movq 0x38(%rsp), %rbx
movl 0x90(%rbx), %edx
movl 0x94(%rbx), %esi
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x58(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x70(%rsp), %rdi
callq 0xdb19
movq 0x80(%rsp), %rsi
movq %rbx, %rdi
callq 0x233e2
movq %rax, %r13
movq 0xd0(%rbx), %rdx
testq %rdx, %rdx
je 0x4176b
movl 0x84(%rbx), %esi
movq %r13, %rdi
pushq $0x1
popq %rcx
movl %ecx, %r8d
callq 0x324ad
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x58(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x70(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq %r13, %rdi
movl 0x2c(%rsp), %esi
movl 0x28(%rsp), %edx
movq %r12, %rcx
callq 0x438a
movl (%r12), %eax
movss 0x20(%rsp), %xmm2
addss 0xa845(%rip), %xmm2     # 0x4c008
xorl %ecx, %ecx
movss 0x24(%rsp), %xmm1
movq %r13, %rdx
cmpq %rcx, %rbp
je 0x417ef
movaps %xmm1, %xmm0
addss 0xa82a(%rip), %xmm0     # 0x4c008
cmpl %r15d, (%r12,%rcx,4)
je 0x417e7
movaps %xmm1, %xmm0
incq %rcx
movaps %xmm0, %xmm1
jmp 0x417ce
movss %xmm1, 0x24(%rsp)
cmpl %r15d, %eax
je 0x41800
movss 0x20(%rsp), %xmm2
movss %xmm2, 0x20(%rsp)
movq 0x48(%rsp), %r13
movq 0x30(%rsp), %rax
movq (%rax,%r13,8), %rsi
cvtss2sd (%rdx), %xmm0
cvtss2sd 0x4(%rdx), %xmm1
leaq 0x103e8(%rip), %rdi     # 0x51c0c
movl %r15d, %edx
movb $0x2, %al
callq 0x3160
leaq 0x1(%r13), %rbx
cvtsi2ss %ebx, %xmm1
movss 0x20(%rsp), %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x24(%rsp), %xmm2
divss %xmm1, %xmm2
cvtss2sd %xmm2, %xmm1
leaq 0x10391(%rip), %rdi     # 0x51bea
movl %r13d, %esi
movl 0x28(%rsp), %edx
movb $0x2, %al
callq 0x3160
jmp 0x416b7
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq