-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrender_results.py
78 lines (70 loc) · 3.61 KB
/
render_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import sys
sys.path.append('..')
from configuration.config import *
os.environ['PYOPENGL_PLATFORM'] = 'osmesa'
import smplx
import trimesh
import pickle
import numpy as np
import torch
from tqdm import tqdm
from interaction.viz_util import render_interaction_multview
from evaluation.load_results import synthesis_results_dict
scene_meshes = {}
for scene_name in scene_names:
mesh_path = Path.joinpath(scene_folder, scene_name + '.ply').__str__()
scene_meshes[scene_name] = trimesh.load_mesh(mesh_path)
body_model_dict = {
'male': smplx.create(smplx_model_folder, model_type='smplx',
gender='male', ext='npz',
num_pca_comps=num_pca_comps),
'female': smplx.create(smplx_model_folder, model_type='smplx',
gender='female', ext='npz',
num_pca_comps=num_pca_comps),
'neutral': smplx.create(smplx_model_folder, model_type='smplx',
gender='neutral', ext='npz',
num_pca_comps=num_pca_comps)
}
default_colors = np.ones((10475, 3)) * np.array([0.80, 0.80, 0.80])
"""
Input:
results: interaction frames
render_dir: directory to save rendering
max_render_num: maximum number of interaction samples per semantic to be rendered
num_view: number of rendering views for each sample
"""
def render_results(results, render_dir, max_render_num=10, num_view=2):
for inter_idx, interaction in enumerate(tqdm(results)):
interaction_dir = Path.joinpath(render_dir, interaction)
interaction_dir.mkdir(parents=True, exist_ok=True)
step_size = max(1, len(results[interaction]) // max_render_num)
for idx in range(0, len(results[interaction]), step_size):
interaction_params = results[interaction][idx]
scene_mesh = scene_meshes[interaction_params['scene']]
if 'gender' in interaction_params:
body_model = body_model_dict[interaction_params['gender']]
else:
body_model = body_model_dict['neutral']
for key in smplx_param_names:
if key in interaction_params:
interaction_params[key] = torch.tensor(interaction_params[key], dtype=torch.float32).cpu()
interaction_params['left_hand_pose'] = interaction_params['left_hand_pose'][:, :num_pca_comps]
interaction_params['right_hand_pose'] = interaction_params['right_hand_pose'][:, :num_pca_comps]
# print(interaction_params)
vertices = body_model(**interaction_params).vertices.detach().cpu().numpy()
body = trimesh.Trimesh(vertices[0], body_model.faces, vertex_colors=default_colors,
process=False)
img_collage = render_interaction_multview(body, scene_mesh, clothed_body=None,
body_center=True,
num_view=num_view,
collage_mode='grid' if num_view == 4 else 'vertical')
export_path = Path.joinpath(interaction_dir, interaction + '_' +interaction_params['scene'] + '_' + str(idx // step_size) + '.png')
print(export_path)
img_collage.save(export_path)
if __name__ == '__main__':
"""render using multiple views or interaction results from different sources"""
for method in synthesis_results_dict:
print('render for ', method)
render_results(synthesis_results_dict[method], Path.joinpath(render_folder, method + '_2view'),
max_render_num=16, num_view=2)