110 lines
3.5 KiB
Python
110 lines
3.5 KiB
Python
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='')
|
|
parser.add_argument('-g', '--gpu', type=str)
|
|
parser.add_argument('-n', '--normal', action='store_true')
|
|
parser.add_argument('-e', '--edge', action='store_true')
|
|
parser.add_argument('-cr', '--collision_ratio', action='store_true')
|
|
parser.add_argument('-a', '--all', action='store_true')
|
|
args = vars(parser.parse_args())
|
|
|
|
if args['debug']:
|
|
from configs.iccvw.pyr_64_128_256_512_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(type=''):
|
|
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}{type}.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[level].keys():
|
|
errors[level][category] = []
|
|
errors[level][category].append(float(line[4]))
|
|
else:
|
|
if category not in errors.keys():
|
|
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} error{type}: {errors_mean[i]}')
|
|
|
|
mean = np.mean(list(errors_mean[i].values()))
|
|
print(f'Final error{type} level {i}: {mean}')
|
|
pass
|
|
else:
|
|
for category in errors:
|
|
errors_mean[category] = round(np.mean(errors[category]), 5)
|
|
print(errors_mean)
|
|
|
|
mean = round(np.mean(list(errors_mean.values())), 5)
|
|
print(f'Final error{type}: {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}'
|
|
|
|
if args['normal']:
|
|
calculate('_normal')
|
|
if args['edge']:
|
|
calculate('_edge')
|
|
if args['collision_ratio']:
|
|
calculate('_collision_ratio')
|
|
calculate() |