-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathalfred-patch.patch
219 lines (200 loc) · 8.97 KB
/
alfred-patch.patch
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
From 265e35e028917701c0153d0fd5f9d5ba4bc8ceec Mon Sep 17 00:00:00 2001
From: Valts Blukis <[email protected]>
Date: Thu, 29 Jul 2021 11:10:26 -0400
Subject: [PATCH 2/2] Added ability to capture intermediate events from smooth
actions
---
env/thor_env.py | 54 +++++++++++++++++++++-----------------
gen/constants.py | 2 +-
models/eval/leaderboard.py | 4 +--
3 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/env/thor_env.py b/env/thor_env.py
index 932fd597..9a7512c5 100644
--- a/env/thor_env.py
+++ b/env/thor_env.py
@@ -1,5 +1,6 @@
import cv2
import copy
+import random
import gen.constants as constants
import numpy as np
from collections import Counter, OrderedDict
@@ -128,14 +129,16 @@ class ThorEnv(Controller):
'''
if smooth_nav:
if "MoveAhead" in action['action']:
- self.smooth_move_ahead(action)
+ events = self.smooth_move_ahead(action)
elif "Rotate" in action['action']:
- self.smooth_rotate(action)
+ events = self.smooth_rotate(action)
elif "Look" in action['action']:
- self.smooth_look(action)
+ events = self.smooth_look(action)
else:
super().step(action)
+ events = []
else:
+ events = []
if "LookUp" in action['action']:
self.look_angle(-constants.AGENT_HORIZON_ADJ)
elif "LookDown" in action['action']:
@@ -145,7 +148,7 @@ class ThorEnv(Controller):
event = self.update_states(action)
self.check_post_conditions(action)
- return event
+ return event, events
def check_post_conditions(self, action):
'''
@@ -394,37 +397,37 @@ class ThorEnv(Controller):
if "RotateLeft" in action:
action = dict(action="RotateLeft",
forceAction=True)
- event = self.step(action, smooth_nav=smooth_nav)
+ event, events = self.step(action, smooth_nav=smooth_nav)
elif "RotateRight" in action:
action = dict(action="RotateRight",
forceAction=True)
- event = self.step(action, smooth_nav=smooth_nav)
+ event, events = self.step(action, smooth_nav=smooth_nav)
elif "MoveAhead" in action:
action = dict(action="MoveAhead",
forceAction=True)
- event = self.step(action, smooth_nav=smooth_nav)
+ event, events = self.step(action, smooth_nav=smooth_nav)
elif "LookUp" in action:
action = dict(action="LookUp",
forceAction=True)
- event = self.step(action, smooth_nav=smooth_nav)
+ event, events = self.step(action, smooth_nav=smooth_nav)
elif "LookDown" in action:
action = dict(action="LookDown",
forceAction=True)
- event = self.step(action, smooth_nav=smooth_nav)
+ event, events = self.step(action, smooth_nav=smooth_nav)
elif "OpenObject" in action:
action = dict(action="OpenObject",
objectId=object_id,
moveMagnitude=1.0)
- event = self.step(action)
+ event, events = self.step(action)
elif "CloseObject" in action:
action = dict(action="CloseObject",
objectId=object_id,
forceAction=True)
- event = self.step(action)
+ event, events = self.step(action)
elif "PickupObject" in action:
action = dict(action="PickupObject",
objectId=object_id)
- event = self.step(action)
+ event, events = self.step(action)
elif "PutObject" in action:
inventory_object_id = self.last_event.metadata['inventoryObjects'][0]['objectId']
action = dict(action="PutObject",
@@ -432,16 +435,16 @@ class ThorEnv(Controller):
receptacleObjectId=object_id,
forceAction=True,
placeStationary=True)
- event = self.step(action)
+ event, events = self.step(action)
elif "ToggleObjectOn" in action:
action = dict(action="ToggleObjectOn",
objectId=object_id)
- event = self.step(action)
+ event, events = self.step(action)
elif "ToggleObjectOff" in action:
action = dict(action="ToggleObjectOff",
objectId=object_id)
- event = self.step(action)
+ event, events = self.step(action)
elif "SliceObject" in action:
# check if agent is holding knife in hand
inventory_objects = self.last_event.metadata['inventoryObjects']
@@ -450,11 +453,11 @@ class ThorEnv(Controller):
action = dict(action="SliceObject",
objectId=object_id)
- event = self.step(action)
+ event, events = self.step(action)
else:
raise Exception("Invalid action. Conversion to THOR API failed! (action='" + str(action) + "')")
- return event, action
+ return event, events, action
def check_clean(self, object_id):
'''
@@ -465,12 +468,12 @@ class ThorEnv(Controller):
event = self.last_event
if event.metadata['lastActionSuccess'] and 'Faucet' in object_id:
# Need to delay one frame to let `isDirty` update on stream-affected.
- event = self.step({'action': 'Pass'})
+ event, events = self.step({'action': 'Pass'})
sink_basin_obj = game_util.get_obj_of_type_closest_to_obj("SinkBasin", object_id, event.metadata)
for in_sink_obj_id in sink_basin_obj['receptacleObjectIds']:
if (game_util.get_object(in_sink_obj_id, event.metadata)['dirtyable']
and game_util.get_object(in_sink_obj_id, event.metadata)['isDirty']):
- event = self.step({'action': 'CleanObject', 'objectId': in_sink_obj_id})
+ event, events = self.step({'action': 'CleanObject', 'objectId': in_sink_obj_id})
return event
def prune_by_any_interaction(self, instances_ids):
@@ -551,7 +554,9 @@ class ThorEnv(Controller):
if len(instance_ids) == 0:
err = "Bad interact mask. Couldn't locate target object"
success = False
- return success, None, None, err, None
+ return success, None, [], None, err, None
+
+ print(f"Put Instance IDS: {instance_ids}")
target_instance_id = instance_ids[0]
else:
@@ -560,10 +565,11 @@ class ThorEnv(Controller):
if debug:
print("taking action: " + str(action) + " on target_instance_id " + str(target_instance_id))
try:
- event, api_action = self.to_thor_api_exec(action, target_instance_id, smooth_nav)
+ event, events, api_action = self.to_thor_api_exec(action, target_instance_id, smooth_nav)
except Exception as err:
success = False
- return success, None, None, err, None
+ events = []
+ return success, None, [], None, err, None
if not event.metadata['lastActionSuccess']:
if interact_mask is not None and debug:
@@ -577,10 +583,10 @@ class ThorEnv(Controller):
cv2.waitKey(0)
print(event.metadata['errorMessage'])
success = False
- return success, event, target_instance_id, event.metadata['errorMessage'], api_action
+ return success, event, events, target_instance_id, event.metadata['errorMessage'], api_action
success = True
- return success, event, target_instance_id, '', api_action
+ return success, event, events, target_instance_id, '', api_action
@staticmethod
def bbox_to_mask(bbox):
diff --git a/gen/constants.py b/gen/constants.py
index 2667f0dd..1b34385a 100644
--- a/gen/constants.py
+++ b/gen/constants.py
@@ -85,7 +85,7 @@ data_dict = OrderedDict() # dictionary for storing trajectory data to be dumped
# Unity Hyperparameters
BUILD_PATH = None
-X_DISPLAY = '0'
+X_DISPLAY = '1'
AGENT_STEP_SIZE = 0.25
AGENT_HORIZON_ADJ = 15
diff --git a/models/eval/leaderboard.py b/models/eval/leaderboard.py
index 1ba65bb7..6a336b1c 100644
--- a/models/eval/leaderboard.py
+++ b/models/eval/leaderboard.py
@@ -147,11 +147,11 @@ class Leaderboard(EvalTask):
seen_files, unseen_files = self.splits['tests_seen'], self.splits['tests_unseen']
# add seen trajectories to queue
- for traj in seen_files:
+ for i, traj in enumerate(seen_files):
task_queue.put(traj)
# add unseen trajectories to queue
- for traj in unseen_files:
+ for i, traj in enumerate(unseen_files):
task_queue.put(traj)
return task_queue
--
2.25.1