def get_result(result_path, label_path):
    'calculate the result'
    files = os.listdir(result_path)
    with open(label_path, 'r') as label:
        labels = json.load(label)
    top1 = 0
    top5 = 0
    total_data = len(files)
    for file in files:
        img_ids_name = file.split('_0.')[0]
        data_path = os.path.join(result_path, (img_ids_name + '_0.bin'))
        result = np.fromfile(data_path, dtype=np.float16).reshape(batch_size, num_classes)
        for batch in range(batch_size):
            predict = np.argsort((- result[batch]), axis=(- 1))
            if (labels[(img_ids_name + '.JPEG')] == predict[0]):
                top1 += 1
            if (labels[(img_ids_name + '.JPEG')] in predict[:5]):
                top5 += 1
    print(f'Total data: {total_data}, top1 accuracy: {(top1 / total_data)}, top5 accuracy: {(top5 / total_data)}.')
calculate the result
def get_result(result_path, label_path):
    
    files = os.listdir(result_path)
    with open(label_path, 'r') as label:
        labels = json.load(label)
    top1 = 0
    top5 = 0
    total_data = len(files)
    for file in files:
        img_ids_name = file.split('_0.')[0]
        data_path = os.path.join(result_path, (img_ids_name + '_0.bin'))
        result = np.fromfile(data_path, dtype=np.float16).reshape(batch_size, num_classes)
        for batch in range(batch_size):
            predict = np.argsort((- result[batch]), axis=(- 1))
            if (labels[(img_ids_name + '.JPEG')] == predict[0]):
                top1 += 1
            if (labels[(img_ids_name + '.JPEG')] in predict[:5]):
                top5 += 1
    print(f'Total data: {total_data}, top1 accuracy: {(top1 / total_data)}, top5 accuracy: {(top5 / total_data)}.')