def faux_dataset_random_pt(eval_envs): print("Generating faux dataset") units = UnrealUnits(scale=1.0) dataset = [] for env_id in eval_envs: segment_dataset = [] config = load_env_config(env_id) template = load_template(env_id) start_pt = np.asarray(config["startPos"]) second_pt = np.asarray(config["startHeading"]) end_x = random.uniform(0, 1000) end_y = random.uniform(0, 1000) end_pt = np.asarray([end_x, end_y]) state1 = DroneState(None, start_pt) state2 = DroneState(None, second_pt) state3 = DroneState(None, end_pt) segment_dataset.append(bare_min_sample(state1, False, env_id)) segment_dataset.append(bare_min_sample(state2, False, env_id)) segment_dataset.append(bare_min_sample(state3, True, env_id)) dataset.append(segment_dataset) return dataset
def get_landmark_pos(self, env_id): template = load_template(env_id) config = load_env_config(env_id) landmark_idx = config["landmarkName"].index(template["landmark1"]) pos_x = config["xPos"][landmark_idx] pos_y = config["zPos"][landmark_idx] landmark_pos = np.asarray([pos_x, pos_y]) return landmark_pos
def faux_dataset_random_landmark(eval_envs): print("Generating faux dataset") units = UnrealUnits(scale=1.0) dataset = [] for env_id in eval_envs: segment_dataset = [] config = load_env_config(env_id) template = load_template(env_id) path = load_path(env_id) landmark_radii = config["radius"] start_pt = np.asarray(config["startPos"]) second_pt = np.asarray(config["startHeading"]) landmark_choice_ids = list(range(len(config["landmarkName"]))) choice_id = random.choice(landmark_choice_ids) target_x = config["xPos"][choice_id] target_y = config["zPos"][choice_id] target_lm_pos = np.asarray([target_x, target_y]) landmark_dir = target_lm_pos - start_pt method = template["side"] theta = math.atan2(landmark_dir[1], landmark_dir[0]) + math.pi if method == "infront": theta = theta elif method == "random": theta = random.random() * 2 * math.pi elif method == "behind": theta = theta + math.pi elif method == "left": theta = theta - math.pi / 2 elif method == "right": theta = theta + math.pi / 2 x, z = target_lm_pos[0], target_lm_pos[1] landmark_radius = landmark_radii[choice_id] sample_point = np.array([ x + math.cos(theta) * landmark_radius, z + math.sin(theta) * landmark_radius ]) state1 = DroneState(None, start_pt) state2 = DroneState(None, second_pt) state3 = DroneState(None, sample_point) segment_dataset.append(bare_min_sample(state1, False, env_id)) segment_dataset.append(bare_min_sample(state2, False, env_id)) segment_dataset.append(bare_min_sample(state3, True, env_id)) dataset.append(segment_dataset) return dataset
def get_mentioned_landmark_side_tplt(env_id): template = load_template(env_id) mentioned_lm = template["landmark1"] lm_name2index = get_landmark_name_to_index() mentioned_index = lm_name2index[mentioned_lm] mentioned_side = template["side"] side_name2index = get_side_name2idx() side_idx = side_name2index[mentioned_side] return mentioned_lm, mentioned_index, mentioned_side, side_idx
def __add_aux_data_template(self, labels, env_id): template_json = load_template(env_id) # Template data is unavailable - means this is probably real natural language if template_json is None: return False mentioned_landmark_idx, mentioned_side_idx = self.__get_goal_landmark_idx(template_json) labels[:, :, 6] = mentioned_landmark_idx labels[:, :, 7] = mentioned_side_idx for landmark_idx in range(labels.size(1)): labels[:, landmark_idx, 8] = 1.0 if landmark_idx == mentioned_landmark_idx else 0 return True
def is_ambiguous(env_id): template = load_template(env_id) config = load_env_config(env_id) #TODO: Handle the case where instructions refer to multiple landmarks ref_landmark = template["landmark1"] occ_count = 0 for landmark_name in config["landmarkName"]: if has_ambiguous_noun_phrase(landmark_name, ref_landmark): occ_count += 1 if occ_count == 0: print("Error! Referred to landmark that's not found in env!") exit(-1) # More than one such landmark occurs in the test set if occ_count > 1: return True else: return False
def correct_side(self, rollout, env_id): template = load_template(env_id) landmark_pos = self.get_landmark_pos(env_id) last_pos = rollout[-1].state.get_pos() first_pos = rollout[0].state.get_pos() dir_landmark = landmark_pos - first_pos if len(N_SIDES) == 4: dir_lm_to_last = last_pos - landmark_pos dir_landmark_norm = dir_landmark / (np.linalg.norm(dir_landmark) + 1e-18) dir_ortho_norm = np.asarray( [dir_landmark_norm[1], -dir_landmark_norm[0]]) proj = np.dot(dir_lm_to_last, dir_landmark_norm) opp_proj = np.dot(dir_lm_to_last, dir_ortho_norm) angle = math.atan2(proj, opp_proj) DEG45 = 0.785398 if template["side"] == "right": return -DEG45 < angle < DEG45 elif template["side"] == "back": return DEG45 < angle < 3 * DEG45 elif template["side"] == "left": return 3 * DEG45 < angle < math.pi or -math.pi < angle < -3 * DEG45 elif template["side"] == "front": return -3 * DEG45 < angle < -DEG45 else: print("Unknown side: ", template["side"]) print("Angle: ", angle) else: # len(N_SIDES) = 2 dir_end = last_pos - first_pos z = np.cross(dir_landmark, dir_end) if template["side"] == "left": return z > 0 else: return z < 0