def save_result(result, result_dir, filename, remove_duplicate=''):
    """Saving predictions as json file for evaluation."""

    # combine results from all processes
    result_new = []

    if remove_duplicate:
        result_new = []
        id_list = []
        for res in track_iter_progress(result):
            if res[remove_duplicate] not in id_list:
                id_list.append(res[remove_duplicate])
                result_new.append(res)
        result = result_new

    final_result_file_url = os.path.join(result_dir, '%s.json' % filename)
    print(f'result file saved to {final_result_file_url}')
    json.dump(result, open(final_result_file_url, 'w'))

    return final_result_file_url
Saving predictions as json file for evaluation.
mmpretrain/evaluation/metrics/caption.py