forked from facebookresearch/habitat-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvln_benchmark.py
77 lines (60 loc) · 2.44 KB
/
vln_benchmark.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
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import argparse
from collections import defaultdict
from typing import Dict
import habitat
from habitat.config.default import get_config
from habitat.sims.habitat_simulator.actions import HabitatSimActions
from habitat.tasks.nav.shortest_path_follower import ShortestPathFollower
def reference_path_benchmark(config, num_episodes=None):
"""
Custom benchmark for the reference path agent because it requires access
to habitat_env during each episode. Agent follows the ground truth
reference path by navigating to intermediate viewpoints en route to goal.
Args:
config: Config
num_episodes: Count of episodes to evaluate on.
"""
with habitat.Env(config=config) as env:
if num_episodes is None:
num_episodes = len(env.episodes)
follower = ShortestPathFollower(
env.sim, goal_radius=0.5, return_one_hot=False
)
follower.mode = "geodesic_path"
agg_metrics: Dict = defaultdict(float)
for _ in range(num_episodes):
env.reset()
for point in env.current_episode.reference_path:
while not env.episode_over:
best_action = follower.get_next_action(point)
if best_action == None:
break
env.step(best_action)
while not env.episode_over:
best_action = follower.get_next_action(
env.current_episode.goals[0].position
)
if best_action == None:
best_action = HabitatSimActions.STOP
env.step(best_action)
for m, v in env.get_metrics().items():
agg_metrics[m] += v
avg_metrics = {k: v / num_episodes for k, v in agg_metrics.items()}
return avg_metrics
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--task-config", type=str, default="configs/tasks/vln_r2r.yaml"
)
args = parser.parse_args()
config = get_config(args.task_config)
metrics = reference_path_benchmark(config, num_episodes=10)
print("Benchmark for Reference Path Follower agent:")
for k, v in metrics.items():
print("{}: {:.3f}".format(k, v))
if __name__ == "__main__":
main()