1
1
from itertools import chain
2
- from typing import List , BinaryIO , Dict , Type , Tuple
2
+ from typing import BinaryIO , Dict , List , Tuple , Type
3
3
4
4
import numpy as np
5
5
import numpy .ma as ma
6
6
7
7
from pose_format .numpy import NumPyPoseBody
8
8
from pose_format .pose_body import PoseBody
9
- from pose_format .pose_header import PoseHeader , PoseHeaderDimensions , PoseNormalizationInfo , PoseHeaderComponent
9
+ from pose_format .pose_header import (PoseHeader , PoseHeaderComponent ,
10
+ PoseHeaderDimensions ,
11
+ PoseNormalizationInfo )
10
12
from pose_format .utils .fast_math import distance_batch
11
13
from pose_format .utils .reader import BufferReader
12
14
13
15
14
16
class Pose :
15
- """File IO for '.pose' file format, including the header and body.
17
+ """
18
+ File IO for '.pose' file format, including the header and body.
16
19
17
20
Parameters
18
21
----------
@@ -28,7 +31,8 @@ def __init__(self, header: PoseHeader, body: PoseBody):
28
31
29
32
@staticmethod
30
33
def read (buffer : bytes , pose_body : Type [PoseBody ] = NumPyPoseBody , ** kwargs ):
31
- """Read Pose object from buffer.
34
+ """
35
+ Read Pose object from buffer.
32
36
33
37
Parameters
34
38
----------
@@ -49,7 +53,8 @@ def read(buffer: bytes, pose_body: Type[PoseBody] = NumPyPoseBody, **kwargs):
49
53
return Pose (header , body )
50
54
51
55
def write (self , buffer : BinaryIO ):
52
- """Write Pose object to buffer.
56
+ """
57
+ Write Pose object to buffer.
53
58
54
59
Parameters
55
60
----------
@@ -60,7 +65,8 @@ def write(self, buffer: BinaryIO):
60
65
self .body .write (self .header .version , buffer )
61
66
62
67
def focus (self ):
63
- """Gets the pose to start at (0,0) and have dimensions as big as needed
68
+ """
69
+ Gets the pose to start at (0,0) and have dimensions as big as needed
64
70
"""
65
71
mins = ma .min (self .body .data , axis = (0 , 1 , 2 ))
66
72
maxs = ma .max (self .body .data , axis = (0 , 1 , 2 ))
@@ -145,10 +151,7 @@ def unnormalize_distribution(self, mu, std):
145
151
"""
146
152
self .body .data = (self .body .data * std ) + mu
147
153
148
- def frame_dropout_uniform (self ,
149
- dropout_min : float = 0.2 ,
150
- dropout_max : float = 1.0 ) -> Tuple ["Pose" , List [int ]]:
151
-
154
+ def frame_dropout_uniform (self , dropout_min : float = 0.2 , dropout_max : float = 1.0 ) -> Tuple ["Pose" , List [int ]]:
152
155
"""
153
156
Perform uniform frame dropout on Pose
154
157
@@ -167,9 +170,7 @@ def frame_dropout_uniform(self,
167
170
body , selected_indexes = self .body .frame_dropout_uniform (dropout_min = dropout_min , dropout_max = dropout_max )
168
171
return Pose (header = self .header , body = body ), selected_indexes
169
172
170
- def frame_dropout_normal (self ,
171
- dropout_mean : float = 0.5 ,
172
- dropout_std : float = 0.1 ) -> Tuple ["Pose" , List [int ]]:
173
+ def frame_dropout_normal (self , dropout_mean : float = 0.5 , dropout_std : float = 0.1 ) -> Tuple ["Pose" , List [int ]]:
173
174
"""
174
175
Normal frame dropout on Pose.
175
176
@@ -189,7 +190,8 @@ def frame_dropout_normal(self,
189
190
return Pose (header = self .header , body = body ), selected_indexes
190
191
191
192
def get_components (self , components : List [str ], points : Dict [str , List [str ]] = None ):
192
- """get pose components based on criteria.
193
+ """
194
+ get pose components based on criteria.
193
195
194
196
Parameters
195
197
----------
@@ -209,13 +211,17 @@ def get_components(self, components: List[str], points: Dict[str, List[str]] = N
209
211
idx = 0
210
212
for component in self .header .components :
211
213
if component .name in components :
212
- new_component = PoseHeaderComponent (component .name , component .points ,
213
- component .limbs , component . colors , component . format )
214
+ new_component = PoseHeaderComponent (component .name , component .points , component . limbs , component . colors ,
215
+ component .format )
214
216
if points is not None and component .name in points : # copy and permute points
215
- new_component .points = points [component .name ]
216
- point_index_mapping = {component .points .index (point ): i for i , point in enumerate (new_component .points )}
217
+ new_component .points = points [component .name ]
218
+ point_index_mapping = {
219
+ component .points .index (point ): i for i , point in enumerate (new_component .points )
220
+ }
217
221
old_indexes_set = set (point_index_mapping .keys ())
218
- new_component .limbs = [(point_index_mapping [l1 ], point_index_mapping [l2 ]) for l1 , l2 in component .limbs if l1 in old_indexes_set and l2 in old_indexes_set ]
222
+ new_component .limbs = [(point_index_mapping [l1 ], point_index_mapping [l2 ])
223
+ for l1 , l2 in component .limbs
224
+ if l1 in old_indexes_set and l2 in old_indexes_set ]
219
225
220
226
indexes [component .name ] = [idx + component .points .index (p ) for p in new_component .points ]
221
227
else : # Copy component as is
@@ -235,7 +241,8 @@ def get_components(self, components: List[str], points: Dict[str, List[str]] = N
235
241
return Pose (header = new_header , body = new_body )
236
242
237
243
def bbox (self ):
238
- """Calculates bounding box for Pose.
244
+ """
245
+ Calculates bounding box for Pose.
239
246
240
247
Returns
241
248
-------
@@ -254,7 +261,8 @@ def bbox(self):
254
261
"tensorflow" , # Convert body to tensorflow
255
262
"slice_step" , # Step through the data
256
263
}
257
- """A set of method names which define actions that can be applied to the pose data.
264
+ """
265
+ A set of method names which define actions that can be applied to the pose data.
258
266
259
267
Parameters
260
268
----------
@@ -271,8 +279,6 @@ def bbox(self):
271
279
slice_step : str
272
280
Represents a method to step through the data.
273
281
"""
274
-
275
-
276
282
277
283
def __getattr__ (self , attr ):
278
284
"""
0 commit comments