Safemotion Lib
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
graph.Graph Class Reference

Public Member Functions

 __init__ (self, layout='openpose', strategy='uniform', max_hop=1, dilation=1)
 
 __str__ (self)
 
 get_edge (self, layout)
 
 get_adjacency (self, strategy)
 

Public Attributes

 max_hop
 
 dilation
 
 hop_dis
 
 num_node
 
 edge
 
 center
 
 A
 

Detailed Description

 The Graph to model the skeletons extracted by the openpose

Args:
    strategy (string): must be one of the follow candidates
    - uniform: Uniform Labeling
    - distance: Distance Partitioning
    - spatial: Spatial Configuration
    For more information, please refer to the section 'Partition Strategies'
        in our paper (https://arxiv.org/abs/1801.07455).

    layout (string): must be one of the follow candidates
    - openpose: Is consists of 18 joints. For more information, please
        refer to https://github.com/CMU-Perceptual-Computing-Lab/openpose#output
    - ntu-rgb+d: Is consists of 25 joints. For more information, please
        refer to https://github.com/shahroudy/NTURGB-D

    max_hop (int): the maximal distance between two connected nodes
    dilation (int): controls the spacing between the kernel points

Definition at line 3 of file graph.py.

Constructor & Destructor Documentation

◆ __init__()

graph.Graph.__init__ ( self,
layout = 'openpose',
strategy = 'uniform',
max_hop = 1,
dilation = 1 )

Definition at line 25 of file graph.py.

29 dilation=1):
30 self.max_hop = max_hop
31 self.dilation = dilation
32
33 self.get_edge(layout)
34 self.hop_dis = get_hop_distance(
35 self.num_node, self.edge, max_hop=max_hop)
36 self.get_adjacency(strategy)
37

Member Function Documentation

◆ __str__()

graph.Graph.__str__ ( self)

Definition at line 38 of file graph.py.

38 def __str__(self):
39 return self.A
40

◆ get_adjacency()

graph.Graph.get_adjacency ( self,
strategy )

Definition at line 84 of file graph.py.

84 def get_adjacency(self, strategy):
85 valid_hop = range(0, self.max_hop + 1, self.dilation)
86 adjacency = np.zeros((self.num_node, self.num_node))
87 for hop in valid_hop:
88 adjacency[self.hop_dis == hop] = 1
89 normalize_adjacency = normalize_digraph(adjacency)
90
91 if strategy == 'uniform':
92 A = np.zeros((1, self.num_node, self.num_node))
93 A[0] = normalize_adjacency
94 self.A = A
95 elif strategy == 'distance':
96 A = np.zeros((len(valid_hop), self.num_node, self.num_node))
97 for i, hop in enumerate(valid_hop):
98 A[i][self.hop_dis == hop] = normalize_adjacency[self.hop_dis ==
99 hop]
100 self.A = A
101 elif strategy == 'spatial':
102 A = []
103 for hop in valid_hop:
104 a_root = np.zeros((self.num_node, self.num_node))
105 a_close = np.zeros((self.num_node, self.num_node))
106 a_further = np.zeros((self.num_node, self.num_node))
107 for i in range(self.num_node):
108 for j in range(self.num_node):
109 if self.hop_dis[j, i] == hop:
110 if self.hop_dis[j, self.center] == self.hop_dis[
111 i, self.center]:
112 a_root[j, i] = normalize_adjacency[j, i]
113 elif self.hop_dis[j, self.
114 center] > self.hop_dis[i, self.
115 center]:
116 a_close[j, i] = normalize_adjacency[j, i]
117 else:
118 a_further[j, i] = normalize_adjacency[j, i]
119 if hop == 0:
120 A.append(a_root)
121 else:
122 A.append(a_root + a_close)
123 A.append(a_further)
124 A = np.stack(A)
125 self.A = A
126 else:
127 raise ValueError("Do Not Exist This Strategy")
128
129

◆ get_edge()

graph.Graph.get_edge ( self,
layout )

Definition at line 41 of file graph.py.

41 def get_edge(self, layout):
42 if layout == 'openpose':
43 self.num_node = 18
44 self_link = [(i, i) for i in range(self.num_node)]
45 neighbor_link = [(4, 3), (3, 2), (7, 6), (6, 5), (13, 12), (12,
46 11),
47 (10, 9), (9, 8), (11, 5), (8, 2), (5, 1), (2, 1),
48 (0, 1), (15, 0), (14, 0), (17, 15), (16, 14)]
49 self.edge = self_link + neighbor_link
50 self.center = 1
51 elif layout == 'ntu-rgb+d':
52 self.num_node = 25
53 self_link = [(i, i) for i in range(self.num_node)]
54 neighbor_1base = [(1, 2), (2, 21), (3, 21), (4, 3), (5, 21),
55 (6, 5), (7, 6), (8, 7), (9, 21), (10, 9),
56 (11, 10), (12, 11), (13, 1), (14, 13), (15, 14),
57 (16, 15), (17, 1), (18, 17), (19, 18), (20, 19),
58 (22, 23), (23, 8), (24, 25), (25, 12)]
59 neighbor_link = [(i - 1, j - 1) for (i, j) in neighbor_1base]
60 self.edge = self_link + neighbor_link
61 self.center = 21 - 1
62 elif layout == 'ntu_edge':
63 self.num_node = 24
64 self_link = [(i, i) for i in range(self.num_node)]
65 neighbor_1base = [(1, 2), (3, 2), (4, 3), (5, 2), (6, 5), (7, 6),
66 (8, 7), (9, 2), (10, 9), (11, 10), (12, 11),
67 (13, 1), (14, 13), (15, 14), (16, 15), (17, 1),
68 (18, 17), (19, 18), (20, 19), (21, 22), (22, 8),
69 (23, 24), (24, 12)]
70 neighbor_link = [(i - 1, j - 1) for (i, j) in neighbor_1base]
71 self.edge = self_link + neighbor_link
72 self.center = 2
73 elif layout=='coco':
74 self.num_node = 17
75 self_link = [(i, i) for i in range(self.num_node)]
76 neighbor_link = [(15, 13), (13, 11), (16, 14), (14, 12), (11, 5),
77 (12, 6), (9, 7), (7, 5), (10, 8), (8, 6), (5, 0),
78 (6, 0), (1, 0), (3, 1), (2, 0), (4, 2)]
79 self.edge = self_link + neighbor_link
80 self.center = 0
81 else:
82 raise ValueError("Do Not Exist This Layout.")
83

Member Data Documentation

◆ A

graph.Graph.A

Definition at line 94 of file graph.py.

◆ center

graph.Graph.center

Definition at line 50 of file graph.py.

◆ dilation

graph.Graph.dilation

Definition at line 31 of file graph.py.

◆ edge

graph.Graph.edge

Definition at line 35 of file graph.py.

◆ hop_dis

graph.Graph.hop_dis

Definition at line 34 of file graph.py.

◆ max_hop

graph.Graph.max_hop

Definition at line 30 of file graph.py.

◆ num_node

graph.Graph.num_node

Definition at line 35 of file graph.py.


The documentation for this class was generated from the following file: