Skip to content

Commit 3a865a7

Browse files
committed
update
1 parent 7c5b964 commit 3a865a7

25 files changed

+2045
-1451
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,5 @@ scene_graph/orb_setting/ORBvoc.txt
155155
sEDM/
156156
data_detector
157157
data/home_service/5_1
158-
data/home_service/old
158+
data/home_service/old
159+
.word_vectors_cache

Diff for: datagen/datagen_runner.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,9 @@ def rearrangement_datagen_worker(
615615
stage = "train"
616616
stage = "_".join([stage, room_seen])
617617
if room_seen == "seen":
618-
scene_inds = range(1, 26)
618+
scene_inds = range(1, 21)
619619
elif room_seen == "unseen":
620-
scene_inds = range(26, 31)
620+
scene_inds = range(21, 31)
621621
else:
622622
raise RuntimeError
623623

Diff for: env/constants.py

+18
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@
4747
"Bathroom": 4,
4848
}
4949

50+
SCENE_GRAPH_DIR = os.path.join(
51+
os.path.abspath(os.path.dirname(Path(__file__))), '../scene_graph'
52+
)
53+
# Yolact Arguments
54+
YOLACT_KWARGS = {
55+
"trained_model": os.path.join(SCENE_GRAPH_DIR, "weights/yolact_base_357_200000.pth"),
56+
"top_k": 5,
57+
"cuda": True,
58+
"fast_nms": True,
59+
"cross_class_nms": False,
60+
"display_masks": True,
61+
"display_bboxes": True,
62+
"display_text": True,
63+
"display_scores": True,
64+
"score_threshold": 0.85,
65+
"dataset": "robot_home_service_dataset",
66+
}
67+
5068
# fmt: off
5169
REARRANGE_SIM_OBJECTS = [
5270
# A

Diff for: env/environment.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,13 @@ def _task_spec_reset(
730730
)
731731

732732
pos = self.current_task_spec.agent_positions[scene_type]
733-
rot = {"x": 0, "y": self.current_task_spec.agent_rotations[scene_type], "z": 0}
733+
rot = {
734+
"x": 0,
735+
"y": round_to_factor(
736+
self.current_task_spec.agent_rotations[scene_type], 90
737+
) if force_axis_aligned_start else self.current_task_spec.agent_rotations[scene_type],
738+
"z": 0,
739+
}
734740
self.controller.step(
735741
"TeleportFull",
736742
**pos,
@@ -739,6 +745,7 @@ def _task_spec_reset(
739745
standing=True,
740746
forceAction=True,
741747
)
748+
assert self.controller.last_event.metadata["lastActionSuccess"]
742749

743750
if reset_scene == self.current_task_spec.target_scene:
744751
with include_object_data(self.controller):

Diff for: env/expert.py

+111-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import copy
44
import random
5+
from networkx.algorithms.shortest_paths.generic import shortest_path
6+
import numpy as np
57
from collections import defaultdict
68
from typing import (
79
Dict,
@@ -38,6 +40,7 @@
3840
from env.tasks import HomeServiceSimplePickAndPlaceTask, HomeServiceBaseTask
3941

4042
AgentLocKeyType = Tuple[float, float, int, int]
43+
PositionKeyType = Tuple[float, float, float]
4144

4245

4346
# class ExplorerTHOR:
@@ -93,6 +96,7 @@ def __init__(
9396
self.controller = controller
9497

9598
self._include_move_left_right = include_move_left_right
99+
self._position_to_object_id: Dict[PositionKeyType, str] = {}
96100

97101
@lazy_property
98102
def nav_actions_set(self) -> frozenset:
@@ -127,6 +131,7 @@ def on_reset(self):
127131
"""Function that must be called whenever the AI2-THOR controller is
128132
reset."""
129133
self._current_scene = None
134+
self._position_to_object_id = {}
130135

131136
@property
132137
def graph(self) -> nx.DiGraph:
@@ -860,7 +865,7 @@ def expert_action(self) -> int:
860865
return self.expert_action_list[-1]
861866

862867
@property
863-
def goto_action(self) -> str:
868+
def goto_action(self) -> str:
864869
if len(self.goto_action_list) > 0:
865870
return self.goto_action_list.pop()
866871

@@ -933,6 +938,34 @@ def _get_interactable_positions(
933938
#TODO
934939
pass
935940

941+
def _expert_goto_action_to_scene_type(
942+
self,
943+
scene_type: str
944+
) -> Optional[str]:
945+
if len(self.goto_action_list) == 0:
946+
if not self.task._1st_check:
947+
for _ in range(4):
948+
self.goto_action_list.append("RotateRight")
949+
self.task._1st_check = True
950+
else:
951+
if not self.task._took_goto_action:
952+
self.goto_action_list.append(f"Goto{scene_type}")
953+
elif not self.task._2nd_check:
954+
for _ in range(4):
955+
self.goto_action_list.append("RotateRight")
956+
self.task._2nd_check = True
957+
958+
goto_action = self.goto_action
959+
if len(self.goto_action_list) == 0:
960+
if self.task._2nd_check:
961+
self.task._check_goto_done = True
962+
elif self.task._1st_check and (
963+
SCENE_TO_SCENE_TYPE[self.task.env.scene] == scene_type
964+
):
965+
self.task._check_goto_done = True
966+
967+
return goto_action
968+
936969
def _expert_nav_action_to_obj(
937970
self,
938971
obj: Dict[str, Any]
@@ -948,6 +981,8 @@ def _expert_nav_action_to_obj(
948981
]
949982

950983
if len(target_keys) == 0:
984+
print(f'No target keys')
985+
import pdb; pdb.set_trace()
951986
return None
952987

953988
source_state_key = shortest_path_navigator.get_key(env.get_agent_location())
@@ -959,6 +994,7 @@ def _expert_nav_action_to_obj(
959994
source_state_key=source_state_key, goal_state_keys=target_keys,
960995
)
961996
except nx.NetworkXNoPath as _:
997+
print('h?')
962998
return None
963999

9641000
if action != "Pass":
@@ -977,6 +1013,63 @@ def _expert_nav_action_to_obj(
9771013

9781014
return None
9791015

1016+
def _expert_nav_action_to_position(self, position) -> Optional[str]:
1017+
"""Get the shortest path navigational action towards the certain position
1018+
1019+
"""
1020+
env: HomeServiceTHOREnvironment = self.task.env
1021+
shortest_path_navigator = self.shortest_path_navigator
1022+
1023+
if isinstance(position, np.ndarray):
1024+
position_key = (round(position[0], 2), round(position[1], 2), round(position[2], 2))
1025+
position = dict(
1026+
x=position[0],
1027+
y=position[1],
1028+
z=position[2],
1029+
)
1030+
elif isinstance(position, dict):
1031+
position_key = (round(position['x'], 2), round(position['y'], 2), round(position['z'], 2))
1032+
1033+
if position_key not in shortest_path_navigator._position_to_object_id:
1034+
# Spawn the TargetCircle and place it on the position
1035+
event = env.controller.step("SpawnTargetCircle", anywhere=True)
1036+
assert event.metadata["lastActionSuccess"]
1037+
id_target_circle = event.metadata["actionReturn"]
1038+
1039+
1040+
event = env.controller.step(
1041+
"TeleportObject",
1042+
objectId=id_target_circle,
1043+
position=position,
1044+
rotation=0,
1045+
forceAction=True
1046+
)
1047+
assert event.metadata["lastActionSuccess"]
1048+
1049+
# To change objectId for former target circle
1050+
event = env.controller.step("SpawnTargetCircle", anywhere=True)
1051+
assert event.metadata["lastActionSuccess"]
1052+
id_target_circle = event.metadata["actionReturn"]
1053+
1054+
event = env.controller.step("RemoveFromScene", objectId=id_target_circle)
1055+
assert event.metadata["lastActionSuccess"]
1056+
1057+
# check
1058+
target_circle_after_teleport = next(
1059+
obj for obj in env.last_event.metadata['objects']
1060+
if obj['objectType'] == "TargetCircle" and obj["position"] == position
1061+
1062+
)
1063+
assert target_circle_after_teleport is not None
1064+
shortest_path_navigator._position_to_object_id[position_key] = target_circle_after_teleport['objectId']
1065+
1066+
object_id = shortest_path_navigator._position_to_object_id[position_key]
1067+
obj = next(
1068+
obj for obj in env.last_event.metadata['objects']
1069+
if obj['objectId'] == object_id
1070+
)
1071+
return self._expert_nav_action_to_obj(obj=obj)
1072+
9801073
def _invalidate_interactable_loc_for_pose(
9811074
self,
9821075
location: Dict[str, Any],
@@ -1051,12 +1144,22 @@ def _generate_expert_action_dict(self) -> Dict[str, Any]:
10511144
return dict(action="Done")
10521145

10531146
elif subtask_action == "Goto":
1054-
return dict(action="Goto", sceneType=subtask_target)
1147+
expert_goto_action = self._expert_goto_action_to_scene_type(
1148+
scene_type=subtask_target
1149+
)
1150+
if expert_goto_action is None:
1151+
raise RuntimeError
1152+
1153+
return dict(action=expert_goto_action)
10551154

10561155
elif subtask_action == "Scan":
1057-
pass
1156+
# TODO
1157+
1158+
# return dict(action="HEHEE")
1159+
return dict(action="Pass")
10581160

10591161
elif subtask_action == "Navigate":
1162+
# from metadata
10601163
with include_object_data(env.controller):
10611164
current_objects = env.last_event.metadata["objects"]
10621165

@@ -1068,8 +1171,11 @@ def _generate_expert_action_dict(self) -> Dict[str, Any]:
10681171
)
10691172
assert target_obj is not None
10701173
self._last_to_interact_object_pose = target_obj
1071-
expert_nav_action = self._expert_nav_action_to_obj(
1072-
obj=target_obj
1174+
# expert_nav_action = self._expert_nav_action_to_obj(
1175+
# obj=target_obj
1176+
# )
1177+
expert_nav_action = self._expert_nav_action_to_position(
1178+
position=self.task.target_positions[subtask_target]
10731179
)
10741180

10751181
if expert_nav_action is None:

0 commit comments

Comments
 (0)