def read_results()

in notebooks/utils.py [0:0]


def read_results(conf_path, run_id=0, results_dir='results/'):
    resdir = osp.join(OUTPUT_DIR, conf_path, str(run_id), results_dir)
    data = next(gen_load_resfiles(resdir))
    # TODO allow to read only certain keys, eg some times we only need logits
    # which would be faster to read
    res_per_layer = {
        key: OrderedDict()
        for key in data if key not in ['epoch']
    }
    if len(res_per_layer) == 0:
        raise ValueError('No logits found in the output. Note that code was '
                         'changed Aug 26 2020 that renames "output" to '
                         '"logits" etc. So might need to rerun testing.')
    logging.info('Reading from resfiles')
    for data in gen_load_resfiles(resdir):
        for i, idx in enumerate(data['idx']):
            idx = int(idx)
            for key in res_per_layer:
                if idx not in res_per_layer[key]:
                    res_per_layer[key][idx] = []
                res_per_layer[key][idx].append(data[key][i])
    # Mean over all the multiple predictions per key
    final_res = {}
    for key in res_per_layer:
        if len(res_per_layer[key]) == 0:
            continue
        max_idx = max(res_per_layer[key].keys())
        key_output = np.zeros([
            max_idx + 1,
        ] + list(res_per_layer[key][0][0].shape))
        for idx in res_per_layer[key]:
            key_output[idx] = np.mean(np.stack(res_per_layer[key][idx]),
                                      axis=0)
        final_res[key] = key_output
    return final_res