forked from themightyoarfish/deepVO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequence_visualizer.py
82 lines (62 loc) · 2.28 KB
/
sequence_visualizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'''
.. module:: sequence_visualizer
Contains the :py:class:`SequenceVisualizer` to visualise trajectory
.. moduleauthor:: Christian Heiden
'''
import numpy as np
import matplotlib.pyplot as plt
class SequenceVisualizer(object):
'''This class visualizes the output of the network'''
def __init__(self):
super(SequenceVisualizer, self).__init__()
# Define initial position to be (0,0)
self.outputs = []
self.labels = []
self.position = 0
self.reset_plot()
def add_data(self, output, label):
self.outputs.append(np.copy(output))
self.labels.append(np.copy(label))
def plot_path(self):
# If there is no or no new information do not plot.
if len(self.outputs) == 0 or self.position == len(self.outputs):
return
# Extract only the relevant data the has not yet been plotted
output_to_plot = np.asarray(self.outputs[self.position:])
label_to_plot = np.asarray(self.labels[self.position:])
# Only plot the positions
output_to_plot = output_to_plot[:, :2]
label_to_plot = label_to_plot[:, :2]
# Update the data pointer
self.position = len(self.outputs)
self.ax.plot(output_to_plot[:, 0], output_to_plot[:, 1], 'ro-')
self.ax.plot(label_to_plot[:, 0], label_to_plot[:, 1], 'g^-')
plt.pause(2)
def reset_plot(self):
self.figure = plt.figure()
self.ax = self.figure.add_subplot(111)
# Clear the contents
del self.outputs[:]
del self.labels[:]
def save_plot(self, path):
pass
def main():
vis = SequenceVisualizer()
# generate pose data
label = np.zeros(6)
for i in range(20):
# imitate movement by adding random numbers
label += np.random.randn(6)
output = label + np.random.randn(6)*0.5
# slightly change the output from the groundtruth position
vis.add_data(output, label)
vis.plot_path()
for i in range(20):
# imitate movement by adding random numbers
label += np.random.randn(6)
output = label + np.random.randn(6)*0.1
# slightly change the output from the groundtruth position
vis.add_data(output, label)
vis.plot_path()
if __name__ == '__main__':
main()