-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnavigator.py
57 lines (41 loc) · 1.7 KB
/
navigator.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
from base_navigator import BaseNavigator
import random
import numpy as np
class Navigator(BaseNavigator):
def __init__(self):
super(Navigator, self).__init__()
def navigate(self, start_graph_state, show_info):
self.graph_state = start_graph_state
while True:
image_feature = self.get_dummy_image_feature(self.graph_state)
move = self.random_policy(image_feature)
if move == 'stop':
print('Action `stop` is chosen.')
break
self.step(move)
if show_info:
self.show_state_info(self.graph_state)
def policy(self, state):
raise NotImplementedError
def get_image_feature(self, graph_state):
raise NotImplementedError
def random_policy(self, state):
return random.choice(['forward', 'left', 'right', 'stop'])
def get_dummy_image_feature(self, graph_state):
panoid, heading = graph_state
# dummy feature
image_feature = np.random.randn(100, 464, 128)
# rotate the pano feature so the middle is the agent's heading direction
# `shift_angle` is essential for adjusting to the correct heading
# please include the following in your own `get_image_feature` function
shift_angle = 157.5 + self.graph.nodes[panoid].pano_yaw_angle - heading
width = image_feature.shape[1]
shift = int(width * shift_angle / 360)
image_feature = np.roll(image_feature, shift, axis=1)
return image_feature
if __name__ == '__main__':
navigator = Navigator()
navigator.navigate(
start_graph_state=('sbtZW9Akt4izrxdQRDPwMQ', 209),
show_info=True
)