text
stringlengths
1
93.6k
# Init the test dataloader.
test_dataloader = torch.utils.data.DataLoader(
test_dataset,
batch_size=1,
shuffle=True,
num_workers=4,
collate_fn=collate_fn,
)
dataset_name = '{}_sem_seg_{}'.format(cfg.data.dataset_name, cfg.test.split)
metadata = MetadataCatalog.get(dataset_name)
result_dir = os.path.join(output_dir, '{:0>4}_eval_on_{}'.format(stats.epoch, cfg.data.dataset_name))
print(result_dir)
evaluator = SemSegEvaluator(dataset_name, output_dir=result_dir)
evaluator.reset()
pth_list = os.listdir(result_dir)
conf_matrix_list = []
predictions = []
depth_metrics = {
'absolute': [],
'absrel': [],
'thres 1.25': [],
'thres 1.25^2': [],
'thres 1.25^3': [],
}
print("loading results...")
for result_fname in tqdm(pth_list):
if not result_fname.startswith('results_'):
continue
f = open(os.path.join(result_dir, result_fname), 'rb')
gpu_results = pickle.load(f)
conf_matrix_list.append(gpu_results['conf_matrix'])
predictions.append(gpu_results['predictions'])
gpu_depth_metrics = gpu_results['depth_metrics']
print("aggregating...")
evaluator._predictions = list(itertools.chain(*predictions))
conf_matrix = np.zeros_like(conf_matrix_list[0])
for gpu_conf_matrix in conf_matrix_list:
conf_matrix += gpu_conf_matrix
evaluator._conf_matrix = conf_matrix
print("[detectron2 evaluation]")
results = evaluator.evaluate()
print("treating objects as a single class")
print("[object and stuff evaluation]")
# build a new conf matrix
# stuff object
# -----------------
# stuff | | |
# | ------|-------|
# object | | |
# -----------------
conf_matrix_os = np.zeros_like(conf_matrix[:-1, :-1])
stuff_list = [0, 1, 21]
for gt_idx in range(conf_matrix_os.shape[0]):
for pred_idx in range(conf_matrix_os.shape[1]):
if gt_idx in stuff_list and pred_idx in stuff_list: # stuff tp
conf_matrix_os[0][0] += conf_matrix[gt_idx][pred_idx]
elif gt_idx in stuff_list and pred_idx not in stuff_list:
conf_matrix_os[0][1] += conf_matrix[gt_idx][pred_idx]
elif gt_idx not in stuff_list and pred_idx not in stuff_list:
conf_matrix_os[1][1] += conf_matrix[gt_idx][pred_idx]
elif gt_idx not in stuff_list and pred_idx in stuff_list:
conf_matrix_os[1][0] += conf_matrix[gt_idx][pred_idx]
else:
raise ValueError("should not reach this point")
evaluator._conf_matrix[:-1, :-1] = conf_matrix_os
results = evaluator.evaluate()
print(results)
print("[depth metrics]")
depth_metrics = {
'all': {
'absolute': {'cnt': 0, 'total': 0},
'absrel': {'cnt': 0, 'total': 0},
'thres 1.25': {'cnt': 0, 'total': 0},
'thres 1.25^2': {'cnt': 0, 'total': 0},
'thres 1.25^3': {'cnt': 0, 'total': 0},
},
'stuff': {
'absolute': {'cnt': 0, 'total': 0},
'absrel': {'cnt': 0, 'total': 0},
'thres 1.25': {'cnt': 0, 'total': 0},
'thres 1.25^2': {'cnt': 0, 'total': 0},
'thres 1.25^3': {'cnt': 0, 'total': 0},
},
'object': {
'absolute': {'cnt': 0, 'total': 0},
'absrel': {'cnt': 0, 'total': 0},
'thres 1.25': {'cnt': 0, 'total': 0},
'thres 1.25^2': {'cnt': 0, 'total': 0},
'thres 1.25^3': {'cnt': 0, 'total': 0},
},