Skip to content

Commit 85b0864

Browse files
committed
lint(): yapf, isort, fix pydoc
1 parent e758d95 commit 85b0864

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1157
-923
lines changed

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
lint:
2+
cd src/python && yapf -i -r .
3+
cd src/python && isort .
4+
cd src/python && pydoclint .
5+
6+
test:
7+
cd src/python && pytest .

src/python/pose_format/numpy/pose_body.py

+20-18
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
import numpy as np
44
import numpy.ma as ma
55

6-
from ..pose_body import PoseBody, POINTS_DIMS
6+
from ..pose_body import POINTS_DIMS, PoseBody
77
from ..pose_header import PoseHeader
88
from ..utils.reader import BufferReader, ConstStructs
99

10-
1110
# import numpy as np
1211
# np.seterr(all='raise')
1312

13+
1414
class NumPyPoseBody(PoseBody):
15-
"""Represents pose information leveraging NumPy operations and structures.
15+
"""
16+
Represents pose information leveraging NumPy operations and structures.
1617
1718
* Inherits from: `PoseBody`
1819
* Implements pose info using NumPy operations and structures.
@@ -34,16 +35,14 @@ class NumPyPoseBody(PoseBody):
3435
Pose data either as a masked array or a regular numpy array.
3536
confidence : np.ndarray
3637
confidence array of the pose keypoints.
37-
3838
"""
3939

40-
tensor_reader = 'unpack_numpy'
41-
"""Specifies the method name for unpacking a numpy array (Value: 'unpack_numpy')."""
40+
tensor_reader = 'unpack_numpy' """Specifies the method name for unpacking a numpy array (Value: 'unpack_numpy')."""
4241

4342
def __init__(self, fps: float, data: Union[ma.MaskedArray, np.ndarray], confidence: np.ndarray):
4443
"""
4544
Initializes the NumPyPoseBody instance
46-
"""
45+
"""
4746
if isinstance(data, np.ndarray): # If array is not masked
4847
mask = confidence == 0 # 0 means no-mask, 1 means with-mask
4948
stacked_mask = np.stack([mask] * data.shape[-1], axis=3)
@@ -131,7 +130,8 @@ def mask(self):
131130
return self.data.mask
132131

133132
def torch(self):
134-
"""converts current instance into a TorchPoseBody instance.
133+
"""
134+
converts current instance into a TorchPoseBody instance.
135135
136136
Returns
137137
-------
@@ -141,11 +141,10 @@ def torch(self):
141141
try:
142142
import torch
143143
except ImportError:
144-
raise ImportError(
145-
"Please install torch. https://pytorch.org/"
146-
)
144+
raise ImportError("Please install torch. https://pytorch.org/")
147145

148146
import torch
147+
149148
from ..torch.pose_body import TorchPoseBody
150149

151150
torch_confidence = torch.from_numpy(self.confidence)
@@ -162,6 +161,7 @@ def tensorflow(self):
162161
pose body data represented in TensorFlow tensors
163162
"""
164163
import tensorflow
164+
165165
from ..tensorflow.pose_body import TensorflowPoseBody
166166

167167
tf_confidence = tensorflow.constant(self.confidence)
@@ -361,11 +361,12 @@ def interpolate(self, new_fps: int = None, kind='cubic'):
361361
new_frames.append(np.zeros((len(new_steps), frames.shape[1])))
362362
else:
363363
frame_data = f(new_steps[first_step_index:last_step_index])
364-
new_frames.append(np.concatenate([
365-
np.zeros((first_step_index, frames.shape[1])),
366-
np.array(frame_data),
367-
np.zeros((len(new_steps) - last_step_index, frames.shape[1]))
368-
]))
364+
new_frames.append(
365+
np.concatenate([
366+
np.zeros((first_step_index, frames.shape[1])),
367+
np.array(frame_data),
368+
np.zeros((len(new_steps) - last_step_index, frames.shape[1]))
369+
]))
369370
new_people.append(np.stack(new_frames, axis=0))
370371

371372
new_data = np.stack(new_people, axis=0).transpose([2, 1, 0, 3])
@@ -375,13 +376,14 @@ def interpolate(self, new_fps: int = None, kind='cubic'):
375376
return NumPyPoseBody(fps=new_fps, data=dimensions, confidence=confidence)
376377

377378
def flatten(self):
378-
"""Flattens data and confidence arrays.
379+
"""
380+
Flattens data and confidence arrays.
379381
380382
method reshapes data and confidence arrays to a two-dimensional array.
381383
The flattened array is filtered to remove rows where confidence is zero.
382384
383385
Returns
384-
--------
386+
-------
385387
numpy.ndarray
386388
flattened and filtered version of the data array.
387389

src/python/pose_format/numpy/representation/distance.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33

44
class DistanceRepresentation:
5-
"""A class to compute the Euclidean distance between two sets of points.
65
"""
6+
A class to compute the Euclidean distance between two sets of points.
7+
"""
8+
79
def distance(self, p1s: ma.MaskedArray, p2s: ma.MaskedArray) -> ma.MaskedArray:
810
"""
911
Compute the Euclidean distance between two sets of points.
@@ -21,7 +23,7 @@ def distance(self, p1s: ma.MaskedArray, p2s: ma.MaskedArray) -> ma.MaskedArray:
2123
Euclidean distances between the two sets of points. The returned array has one fewer dimension than the input arrays, as the distance calculation collapses the last dimension.
2224
2325
Note
24-
-----
26+
----
2527
this method assumes that input arrays `p1s` and `p2s` have same shape.
2628
"""
2729
diff = p1s - p2s

src/python/pose_format/numpy/representation/distance_test.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import math
12
from unittest import TestCase
23

34
import numpy as np
45
import numpy.ma as ma
5-
import math
66

77
from pose_format.numpy.representation.distance import DistanceRepresentation
88

@@ -13,17 +13,18 @@ class TestDistanceRepresentation(TestCase):
1313
"""
1414
Unit tests for DistanceRepresentation class to computes Euclidean distance between sets of 3D points.
1515
"""
16+
1617
def test_call_value_should_be_distance(self):
1718
"""
1819
Test if computed distance between two points is correct.
1920
2021
Note
21-
-----
22+
----
2223
This test initializes two sets of 3D points:
2324
p1 = (1, 2, 3) and p2 = (4, 5, 6). It then checks if the
2425
computed Euclidean distance between p1 and p2 is sqrt(27).
2526
"""
26-
27+
2728
p1s = ma.array([[[[1, 2, 3]]]], dtype=np.float32)
2829
p2s = ma.array([[[[4, 5, 6]]]], dtype=np.float32)
2930
distances = representation(p1s, p2s)
@@ -34,11 +35,11 @@ def test_call_masked_value_should_be_zero(self):
3435
Test if the distance for masked values is zero.
3536
3637
Note
37-
-----
38+
----
3839
This test checks scenario where one set of points
3940
is masked.The computed distance in such in such a case be 0.
4041
"""
41-
42+
4243
mask = [[[[True, True, True]]]]
4344
p1s = ma.array([[[[1, 2, 3]]]], mask=mask, dtype=np.float32)
4445
p2s = ma.array([[[[4, 5, 6]]]], dtype=np.float32)

src/python/pose_format/pose.py

+29-23
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
from itertools import chain
2-
from typing import List, BinaryIO, Dict, Type, Tuple
2+
from typing import BinaryIO, Dict, List, Tuple, Type
33

44
import numpy as np
55
import numpy.ma as ma
66

77
from pose_format.numpy import NumPyPoseBody
88
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)
1012
from pose_format.utils.fast_math import distance_batch
1113
from pose_format.utils.reader import BufferReader
1214

1315

1416
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.
1619
1720
Parameters
1821
----------
@@ -28,7 +31,8 @@ def __init__(self, header: PoseHeader, body: PoseBody):
2831

2932
@staticmethod
3033
def read(buffer: bytes, pose_body: Type[PoseBody] = NumPyPoseBody, **kwargs):
31-
"""Read Pose object from buffer.
34+
"""
35+
Read Pose object from buffer.
3236
3337
Parameters
3438
----------
@@ -49,7 +53,8 @@ def read(buffer: bytes, pose_body: Type[PoseBody] = NumPyPoseBody, **kwargs):
4953
return Pose(header, body)
5054

5155
def write(self, buffer: BinaryIO):
52-
"""Write Pose object to buffer.
56+
"""
57+
Write Pose object to buffer.
5358
5459
Parameters
5560
----------
@@ -60,7 +65,8 @@ def write(self, buffer: BinaryIO):
6065
self.body.write(self.header.version, buffer)
6166

6267
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
6470
"""
6571
mins = ma.min(self.body.data, axis=(0, 1, 2))
6672
maxs = ma.max(self.body.data, axis=(0, 1, 2))
@@ -145,10 +151,7 @@ def unnormalize_distribution(self, mu, std):
145151
"""
146152
self.body.data = (self.body.data * std) + mu
147153

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]]:
152155
"""
153156
Perform uniform frame dropout on Pose
154157
@@ -167,9 +170,7 @@ def frame_dropout_uniform(self,
167170
body, selected_indexes = self.body.frame_dropout_uniform(dropout_min=dropout_min, dropout_max=dropout_max)
168171
return Pose(header=self.header, body=body), selected_indexes
169172

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]]:
173174
"""
174175
Normal frame dropout on Pose.
175176
@@ -189,7 +190,8 @@ def frame_dropout_normal(self,
189190
return Pose(header=self.header, body=body), selected_indexes
190191

191192
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.
193195
194196
Parameters
195197
----------
@@ -209,13 +211,17 @@ def get_components(self, components: List[str], points: Dict[str, List[str]] = N
209211
idx = 0
210212
for component in self.header.components:
211213
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)
214216
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+
}
217221
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]
219225

220226
indexes[component.name] = [idx + component.points.index(p) for p in new_component.points]
221227
else: # Copy component as is
@@ -235,7 +241,8 @@ def get_components(self, components: List[str], points: Dict[str, List[str]] = N
235241
return Pose(header=new_header, body=new_body)
236242

237243
def bbox(self):
238-
"""Calculates bounding box for Pose.
244+
"""
245+
Calculates bounding box for Pose.
239246
240247
Returns
241248
-------
@@ -254,7 +261,8 @@ def bbox(self):
254261
"tensorflow", # Convert body to tensorflow
255262
"slice_step", # Step through the data
256263
}
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.
258266
259267
Parameters
260268
----------
@@ -271,8 +279,6 @@ def bbox(self):
271279
slice_step : str
272280
Represents a method to step through the data.
273281
"""
274-
275-
276282

277283
def __getattr__(self, attr):
278284
"""

0 commit comments

Comments
 (0)