Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

visualization.py 3.4 KB

You have to be logged in to leave a comment. Sign In
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  1. import torch
  2. # import matplotlib
  3. # matplotlib.use('MACOSX')
  4. import matplotlib.pyplot as plt
  5. from smplx import SMPL
  6. from utils.renderer import Renderer
  7. from utils.cam_utils import perspective_project_torch
  8. from data.ssp3d_dataset import SSP3DDataset
  9. import config
  10. # SMPL models in torch
  11. smpl_male = SMPL(config.SMPL_MODEL_DIR, batch_size=1, gender='male')
  12. smpl_female = SMPL(config.SMPL_MODEL_DIR, batch_size=1, gender='female')
  13. # Pyrender renderer
  14. renderer = Renderer(faces=smpl_male.faces, img_res=512)
  15. # SSP-3D datset class
  16. ssp3d_dataset = SSP3DDataset(config.SSP_3D_PATH)
  17. indices_to_plot = [11, 60, 199] # Visualising 3 examples from SSP-3D
  18. for i in indices_to_plot:
  19. data = ssp3d_dataset.__getitem__(i)
  20. fname = data['fname']
  21. image = data['image']
  22. cropped_image = data['cropped_image']
  23. silhouette = data['silhouette']
  24. joints2D = data['joints2D']
  25. body_shape = data['shape']
  26. body_pose = data['pose']
  27. gender = data['gender']
  28. cam_trans = data['cam_trans']
  29. # Obtaining body vertex mesh from SMPL shape and pose
  30. body_shape = torch.from_numpy(body_shape[None, :]).float()
  31. body_pose = torch.from_numpy(body_pose[None, :]).float()
  32. cam_trans = torch.from_numpy(cam_trans[None, :]).float()
  33. if gender == 'm':
  34. smpl_output = smpl_male(body_pose=body_pose[:, 3:],
  35. global_orient=body_pose[:, :3], # First 3 axis-angle pose parameters are global body rotation
  36. betas=body_shape)
  37. elif gender == 'f':
  38. smpl_output = smpl_female(body_pose=body_pose[:, 3:],
  39. global_orient=body_pose[:, :3], # First 3 axis-angle pose parameters are global body rotation
  40. betas=body_shape)
  41. vertices = smpl_output.vertices
  42. projected_vertices = perspective_project_torch(vertices, cam_trans,
  43. focal_length=config.FOCAL_LENGTH,
  44. img_wh=512)
  45. vertices = vertices.cpu().detach().numpy()[0]
  46. projected_vertices = projected_vertices.cpu().detach().numpy()[0]
  47. cam_trans = cam_trans.cpu().detach().numpy()[0]
  48. # Rendering vertex mesh
  49. rend_img = renderer(vertices, cam_trans, img=image)
  50. # Visualise
  51. fig = plt.figure(figsize=(14, 8))
  52. fig.suptitle(fname)
  53. plt.tight_layout()
  54. plt.subplot(231)
  55. plt.gca().set_title('Image')
  56. plt.gca().set_axis_off()
  57. plt.imshow(image)
  58. plt.subplot(232)
  59. plt.gca().set_title('Cropped Image')
  60. plt.gca().set_axis_off()
  61. plt.imshow(cropped_image)
  62. plt.subplot(233)
  63. plt.gca().set_title('2D Joints')
  64. plt.gca().set_axis_off()
  65. plt.imshow(image)
  66. for j in range(joints2D.shape[0]):
  67. plt.scatter(joints2D[j, 0], joints2D[j, 1], s=2, c='r')
  68. plt.text(joints2D[j, 0], joints2D[j, 1], s=str(j))
  69. plt.subplot(234)
  70. plt.gca().set_title('Silhouette')
  71. plt.gca().set_axis_off()
  72. plt.imshow(image)
  73. plt.imshow(silhouette, alpha=0.4)
  74. plt.subplot(235)
  75. plt.gca().set_title('Projected Vertices')
  76. plt.gca().set_axis_off()
  77. plt.imshow(image)
  78. plt.scatter(projected_vertices[:, 0], projected_vertices[:, 1], s=1)
  79. plt.subplot(236)
  80. plt.gca().set_title('Body Render')
  81. plt.gca().set_axis_off()
  82. plt.imshow(rend_img)
  83. plt.subplots_adjust(top=0.93, bottom=0.0, right=1, left=0, hspace=0.13, wspace=0)
  84. plt.show()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...