def eval_correspondences_pointcloud(self, pcl_pred_files, pcl_tgt): ''' Calculates correspondence score for point clouds. Args: pcl_pred_files (list): list of point cloud prediction files pcl_tgt (list): list of target point clouds ''' # Detect NN for GT points pc_t0 = np.expand_dims(load_pointcloud(pcl_pred_files[0]), axis=0) ind, _ = get_nearest_neighbors_indices_batch( pc_t0, np.expand_dims(pcl_tgt[0], axis=0)) ind = ind[0] # Next time steps eval_dict = {} for i in range(len(pcl_tgt)): pc_t = load_pointcloud(pcl_pred_files[i]) pc_nn_t = pcl_tgt[i][ind] l2_loss = np.mean(np.linalg.norm(pc_t - pc_nn_t, axis=-1)).item() eval_dict['l2 %d (pcl)' % i] = l2_loss return eval_dict
if os.path.exists(mesh_file): mesh = trimesh.load(mesh_file, process=False) eval_dict_mesh = evaluator.eval_mesh(mesh, pointcloud_tgt, normals_tgt, points_tgt, occ_tgt) for k, v in eval_dict_mesh.items(): eval_dict[k + ' (mesh)'] = v else: print('Warning: mesh does not exist: %s' % mesh_file) # Evaluate point cloud if cfg['test']['eval_pointcloud']: pointcloud_file = os.path.join(pointcloud_dir, '%s.ply' % modelname) if os.path.exists(pointcloud_file): pointcloud = load_pointcloud(pointcloud_file) eval_dict_pcl = evaluator.eval_pointcloud(pointcloud, pointcloud_tgt) for k, v in eval_dict_pcl.items(): eval_dict[k + ' (pcl)'] = v else: print('Warning: pointcloud does not exist: %s' % pointcloud_file) # Create pandas dataframe and save eval_df = pd.DataFrame(eval_dicts) eval_df.set_index(['idx'], inplace=True) eval_df.to_pickle(out_file) # Create CSV file with main statistics eval_df_class = eval_df.groupby(by=['class name']).mean() eval_df_class.to_csv(out_file_class)
# Evaluate point cloud if cfg['test']['eval_pointcloud']: pointcloud_folder = os.path.join(pointcloud_dir, '%s' % modelname, '%05d' % start_idx) if os.path.exists(pointcloud_folder): ply_files = glob.glob(os.path.join(pointcloud_folder, '*.ply')) ply_files.sort() # Eval Pointcloud Correspondences if cfg['test']['eval_pointcloud_correspondences']: eval_dict_cor = evaluator.eval_correspondences_pointcloud( ply_files, pointcloud_tgt) for k, v in eval_dict_cor.items(): eval_dict[k] = v # Eval Point Cloud Chamfer distances for i, ply_file in enumerate(ply_files[:17]): pointcloud = load_pointcloud(ply_file) eval_dict_pcl = evaluator.eval_pointcloud( pointcloud, pointcloud_tgt[i]) for k, v in eval_dict_pcl.items(): eval_dict['%s %d (pcl)' % (k, i)] = v else: print('Warning: pointcloud does not exist: %s (%d)' % (modelname, start_idx)) if it > 0 and (it % 50) == 0: # Create pandas dataframe and save eval_df = pd.DataFrame(eval_dicts) eval_df.set_index(['idx'], inplace=True) eval_df.to_pickle(out_file_tmp) # Create CSV file with main statistics
if os.path.exists(mesh_file): mesh = trimesh.load(mesh_file) eval_dict_mesh = evaluator.eval_mesh( mesh, pointcloud_tgt) for k, v in eval_dict_mesh.items(): eval_dict[k + ' (mesh)'] = v else: print('Warning: mesh does not exist: %s' % mesh_file) if eval_pointcloud: pointcloud_file = os.path.join(output_dir, 'mesh_{}_{}_{}_{}_{}.ply'.format(split, data_completeness, data_sparsity, checkpoint, it)) if os.path.exists(pointcloud_file): pointcloud = load_pointcloud(pointcloud_file).astype(np.float32) eval_dict_pcl = evaluator.eval_pointcloud( pointcloud, pointcloud_tgt) for k, v in eval_dict_pcl.items(): eval_dict[k + ' (pcl)'] = v else: print('Warning: pointcloud does not exist: %s' % pointcloud_file) out_file = os.path.join(output_dir, 'result', 'eval_input_full_{}_{}_{}_{}.pkl'.format(split, data_completeness, data_sparsity, checkpoint)) out_file_class = os.path.join(output_dir, 'result', 'eval_input_{}_{}_{}_{}.csv'.format(split, data_completeness, data_sparsity, checkpoint)) # Create pandas dataframe and save eval_df = pd.DataFrame(eval_dicts) eval_df.set_index(['idx'], inplace=True)