3
3
from posenet .constants import *
4
4
5
5
6
- def get_offset_point (coord , keypoint_id , offsets ):
7
- return np .array ((
8
- offsets [coord [0 ], coord [1 ], keypoint_id ],
9
- offsets [coord [0 ], coord [1 ], keypoint_id + NUM_KEYPOINTS ])).astype (np .int32 )
10
-
11
-
12
- def get_image_coords (heatmap_coord , keypoint_id , output_stride , offsets ):
13
- return heatmap_coord * output_stride + get_offset_point (heatmap_coord , keypoint_id , offsets )
14
-
15
-
16
6
def traverse_to_targ_keypoint (
17
7
edge_id , source_keypoint , target_keypoint_id , scores , offsets , output_stride , displacements
18
8
):
19
9
height = scores .shape [0 ]
20
10
width = scores .shape [1 ]
21
- num_edges = displacements .shape [2 ] // 2
22
11
23
12
source_keypoint_indices = np .clip (
24
13
np .round (source_keypoint / output_stride ), a_min = 0 , a_max = [height - 1 , width - 1 ]).astype (np .int32 )
25
14
26
- displacement = np .array ((
27
- displacements [source_keypoint_indices [0 ], source_keypoint_indices [1 ], edge_id ],
28
- displacements [source_keypoint_indices [0 ], source_keypoint_indices [1 ], edge_id + num_edges ]
29
- ))
30
-
31
- displaced_point = source_keypoint + displacement
15
+ displaced_point = source_keypoint + displacements [
16
+ source_keypoint_indices [0 ], source_keypoint_indices [1 ], edge_id ]
32
17
33
18
displaced_point_indices = np .clip (
34
19
np .round (displaced_point / output_stride ), a_min = 0 , a_max = [height - 1 , width - 1 ]).astype (np .int32 )
35
20
36
- offset_point = get_offset_point (displaced_point_indices , target_keypoint_id , offsets )
37
-
38
21
score = scores [displaced_point_indices [0 ], displaced_point_indices [1 ], target_keypoint_id ]
39
22
40
- position = displaced_point_indices * output_stride + offset_point
23
+ image_coord = displaced_point_indices * output_stride + offsets [
24
+ displaced_point_indices [0 ], displaced_point_indices [1 ], target_keypoint_id ]
41
25
42
- return score , position
26
+ return score , image_coord
43
27
44
28
45
29
def decode_pose (
46
- root_score , root_id , root_coord ,
30
+ root_score , root_id , root_image_coord ,
47
31
scores ,
48
32
offsets ,
49
33
output_stride ,
@@ -55,11 +39,8 @@ def decode_pose(
55
39
56
40
instance_keypoint_scores = np .zeros (num_parts )
57
41
instance_keypoint_coords = np .zeros ((num_parts , 2 ))
58
-
59
- root_point = get_image_coords (root_coord , root_id , output_stride , offsets )
60
-
61
42
instance_keypoint_scores [root_id ] = root_score
62
- instance_keypoint_coords [root_id ] = root_point
43
+ instance_keypoint_coords [root_id ] = root_image_coord
63
44
64
45
# FIXME can we vectorize these loops cleanly?
65
46
for edge in reversed (range (num_edges )):
0 commit comments