import os import sys sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..') import importlib import argparse parser = argparse.ArgumentParser(description='') parser.add_argument('--name', type=str) parser.add_argument('--config', type=str) parser.add_argument('--debug', action='store_true') parser.add_argument('--iteration', type=str, default='190000') parser.add_argument('-g', '--gpu', type=str) parser.add_argument('-a', '--all', action='store_true') args = vars(parser.parse_args()) if args['debug']: from configs.iccvw.pyr_64_128_256_512_cape_f_e2e import config as config_1 else: config_module = importlib.import_module(args['config']) config_1 = config_module.config import time import argparse import tqdm import random import numpy as np import plotly.graph_objects as go import plotly.express as ex from data.utils import Frame def calculate(): all_levels = args['all'] if all_levels: errors = {0: dict(), 1: dict(), 2: dict(), 3: dict()} errors_mean = {0: dict(), 1: dict(), 2: dict(), 3: dict()} else: errors = dict() errors_mean = dict() with open(f'{results_folder}/errors/{name}.csv', 'r') as f: lines = f.readlines() for line in lines: line = line.split(',') category = line[2] if all_levels: level = int(line[3][-1]) if category not in errors: errors[level][category] = [] errors[level][category].append(float(line[4])) else: if category not in errors: errors[category] = [] errors[category].append(float(line[3])) if all_levels: for i in range(4): for category in errors[i]: errors_mean[i][category] = round(np.mean(errors[i][category]), 5) print(f'Level {i}: {errors_mean[i]}') mean = np.mean(list(errors_mean[i].values())) print(f'Final error level {i}: {mean}') else: for category in errors: errors_mean[category] = round(np.mean(errors[category]), 5) print(errors_mean) mean = np.mean(list(errors_mean.values())) print(f'Final error: {mean}') if __name__ == '__main__': skirt_modifier = '_skirt' if config_1['is_skirt'] else '' name = config_1['name'] if not config_1['is_cape']: frames_file = config_1['test_frames'] with open(os.path.join(config_1['test_dir'], frames_file), 'r') as f: frames = f.readlines() frames = [Frame(frames.split()[0], int(frames.split()[1]), frames.split()[2]) for frames in frames] else: from data.dataset_cape import read_frames frames = read_frames(config_1['test_dir'], shuffle=False, is_cape=True) results_folder = '/data-local/127_2/results' if args['iteration'] == '': folders = [f for f in os.listdir(results_folder) if os.path.isdir(os.path.join(results_folder, f)) and f.startswith(config_1['name'])] assert len(folders) == 1 name = folders[0] else: name = f'{name}_{args["iteration"]}' out_folder = f'{results_folder}/{name}' calculate()