diff --git a/nav_src/agent.py b/nav_src/agent.py index 413b43d..ddcc60d 100644 --- a/nav_src/agent.py +++ b/nav_src/agent.py @@ -817,109 +817,3 @@ class NavGPTAgent(BaseAgent): return self.traj -class RandomAgent(BaseAgent): - def __init__( - self, - env: REVERIENavBatch, - config: Namespace): - """ - Initialize the LLM Navigation Agent. - - Args: - env: The Matterport3D environment. - config: The configuration. - """ - super().__init__(env) - self.config = config - - - def init_trajecotry(self, obs: List[dict]): - """Initialize the trajectory with the given observation.""" - # Record the navigation path - self.traj = [{ - 'instr_id': ob['instr_id'], - 'path': [[ob['start']]], - 'details': [], - } for ob in obs] - # Record the history of actions taken - - - def make_equiv_action(self, actions: List[str]) -> str: - """ - Interface between Panoramic view and Egocentric view - Take in the next viewpoint ID and move the agent to that viewpoint - return the turned angle and new observation - """ - def normalize_angle(angle): - while angle > 180: - angle -= 360 - while angle <= -180: - angle += 360 - return angle - - def angle_to_left_right(angle): - return f"left {-angle:.2f}" if angle < 0 else f"right {angle:.2f}" - - # Get current agent facing angle - cur_obs = self.env._get_obs()[0] - cur_heading = np.rad2deg(cur_obs['heading']) - # Make the action - new_obs = self.env.step(actions)[0] - new_heading = np.rad2deg(new_obs['heading']) - # Record the trajectory - self.traj[0]['path'].append(self.env.env.sims[0].gmap.bfs_shortest_path(cur_obs['viewpoint'], actions[0])[1:]) - # Calculate the turned angle - turned_angle = new_heading - cur_heading - # Generate action description - cur_heading = angle_to_left_right(normalize_angle(cur_heading)) - new_heading = angle_to_left_right(normalize_angle(new_heading)) - action_description = f'Turn heading direction {turned_angle:.2f} degrees from {cur_heading} to {new_heading}.' - return action_description, new_obs - - def rollout(self, reset=True): - if reset: # Reset env - obs = self.env.reset() - else: - obs = self.env._get_obs() - - global FINAL_STOP_POINT - global TEMP_STEPS_COUNTER - - FINAL_STOP_POINT = obs[0]['stop'] - - if TEMP_STEPS_COUNTER != 0: - TEMP_STEPS_COUNTER = 0 - - print(obs[0].keys()) - print(obs[0]['obs']) - print(obs[0]['obs_summary']) - print(obs[0]['objects']) - print(obs[0]['instr_id']) - print(obs[0]['scan']) - print(obs[0]['viewpoint']) - print(obs[0]['heading']) - print(obs[0]['elevation']) - print(obs[0]['candidate']) - print(obs[0]['instruction']) - print(obs[0]['gt_path']) - print(obs[0]['path_id']) - print(obs[0]['stop']) - print(obs[0]['start']) - print(obs[0]['target']) - - - print("==") - - # Initialize the trajectory - self.init_trajecotry(obs) - - for i, init_ob in enumerate(obs): - - navigable = init_ob['candidate'] - heading = np.rad2deg(init_ob['heading']) - elevation = np.rad2deg(init_ob['elevation']) - orientation = f'\nheading: {heading:.2f}, elevation: {elevation:.2f}' - - output = self.agent_executor(input) - - return self.traj