18
18
from __future__ import print_function
19
19
from __future__ import division
20
20
21
+ from typing import Tuple , List
21
22
import numpy as np
22
23
23
24
import torch
24
25
import torch .nn .functional as F
25
26
26
- from .utils import rot_mat_to_euler
27
+ from .utils import rot_mat_to_euler , Tensor
27
28
28
29
29
- def find_dynamic_lmk_idx_and_bcoords (vertices , pose , dynamic_lmk_faces_idx ,
30
- dynamic_lmk_b_coords ,
31
- neck_kin_chain , dtype = torch .float32 ):
30
+ def find_dynamic_lmk_idx_and_bcoords (
31
+ vertices : Tensor ,
32
+ pose : Tensor ,
33
+ dynamic_lmk_faces_idx : Tensor ,
34
+ dynamic_lmk_b_coords : Tensor ,
35
+ neck_kin_chain : List [int ],
36
+ dtype = torch .float32
37
+ ) -> Tuple [Tensor , Tensor ]:
32
38
''' Compute the faces, barycentric coordinates for the dynamic landmarks
33
39
34
40
@@ -94,7 +100,12 @@ def find_dynamic_lmk_idx_and_bcoords(vertices, pose, dynamic_lmk_faces_idx,
94
100
return dyn_lmk_faces_idx , dyn_lmk_b_coords
95
101
96
102
97
- def vertices2landmarks (vertices , faces , lmk_faces_idx , lmk_bary_coords ):
103
+ def vertices2landmarks (
104
+ vertices : Tensor ,
105
+ faces : Tensor ,
106
+ lmk_faces_idx : Tensor ,
107
+ lmk_bary_coords : Tensor
108
+ ) -> Tensor :
98
109
''' Calculates landmarks by barycentric interpolation
99
110
100
111
Parameters
@@ -133,8 +144,18 @@ def vertices2landmarks(vertices, faces, lmk_faces_idx, lmk_bary_coords):
133
144
return landmarks
134
145
135
146
136
- def lbs (betas , pose , v_template , shapedirs , posedirs , J_regressor , parents ,
137
- lbs_weights , pose2rot = True , dtype = torch .float32 ):
147
+ def lbs (
148
+ betas : Tensor ,
149
+ pose : Tensor ,
150
+ v_template : Tensor ,
151
+ shapedirs : Tensor ,
152
+ posedirs : Tensor ,
153
+ J_regressor : Tensor ,
154
+ parents : Tensor ,
155
+ lbs_weights : Tensor ,
156
+ pose2rot : bool = True ,
157
+ dtype = torch .float32
158
+ ) -> Tuple [Tensor , Tensor ]:
138
159
''' Performs Linear Blend Skinning with the given shape and pose parameters
139
160
140
161
Parameters
@@ -223,7 +244,7 @@ def lbs(betas, pose, v_template, shapedirs, posedirs, J_regressor, parents,
223
244
return verts , J_transformed
224
245
225
246
226
- def vertices2joints (J_regressor , vertices ) :
247
+ def vertices2joints (J_regressor : Tensor , vertices : Tensor ) -> Tensor :
227
248
''' Calculates the 3D joint locations from the vertices
228
249
229
250
Parameters
@@ -243,7 +264,7 @@ def vertices2joints(J_regressor, vertices):
243
264
return torch .einsum ('bik,ji->bjk' , [vertices , J_regressor ])
244
265
245
266
246
- def blend_shapes (betas , shape_disps ) :
267
+ def blend_shapes (betas : Tensor , shape_disps : Tensor ) -> Tensor :
247
268
''' Calculates the per vertex displacement due to the blend shapes
248
269
249
270
@@ -267,7 +288,11 @@ def blend_shapes(betas, shape_disps):
267
288
return blend_shape
268
289
269
290
270
- def batch_rodrigues (rot_vecs , epsilon = 1e-8 , dtype = torch .float32 ):
291
+ def batch_rodrigues (
292
+ rot_vecs : Tensor ,
293
+ epsilon : float = 1e-8 ,
294
+ dtype = torch .float32
295
+ ) -> Tensor :
271
296
''' Calculates the rotation matrices for a batch of rotation vectors
272
297
Parameters
273
298
----------
@@ -301,7 +326,7 @@ def batch_rodrigues(rot_vecs, epsilon=1e-8, dtype=torch.float32):
301
326
return rot_mat
302
327
303
328
304
- def transform_mat (R , t ) :
329
+ def transform_mat (R : Tensor , t : Tensor ) -> Tensor :
305
330
''' Creates a batch of transformation matrices
306
331
Args:
307
332
- R: Bx3x3 array of a batch of rotation matrices
@@ -314,7 +339,12 @@ def transform_mat(R, t):
314
339
F .pad (t , [0 , 0 , 0 , 1 ], value = 1 )], dim = 2 )
315
340
316
341
317
- def batch_rigid_transform (rot_mats , joints , parents , dtype = torch .float32 ):
342
+ def batch_rigid_transform (
343
+ rot_mats : Tensor ,
344
+ joints : Tensor ,
345
+ parents : Tensor ,
346
+ dtype = torch .float32
347
+ ) -> Tensor :
318
348
"""
319
349
Applies a batch of rigid transformations to the joints
320
350
0 commit comments