Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the generation code compatible with ai2thor 2.4.0 (latest) #45

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

107 changes: 59 additions & 48 deletions env/thor_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import numpy as np
from collections import Counter, OrderedDict
from env.tasks import get_task
import ai2thor
from ai2thor.controller import Controller
import gen.utils.image_util as image_util
from gen.utils import game_util
from gen.utils.game_util import get_objects_of_type, get_obj_of_type_closest_to_obj


DEFAULT_RENDER_SETTINGS = {'renderImage': True,
'renderDepthImage': False,
'renderDepthImage': True,
'renderClassImage': False,
'renderObjectImage': False,
}
Expand All @@ -26,13 +27,13 @@ def __init__(self, x_display=constants.X_DISPLAY,
quality='MediumCloseFitShadows',
build_path=constants.BUILD_PATH):

super().__init__(quality=quality)
self.local_executable_path = build_path
self.start(x_display=x_display,
player_screen_height=player_screen_height,
player_screen_width=player_screen_width)
self.task = None

super().__init__(quality=quality,
x_display=x_display,
height=player_screen_height,
width=player_screen_width)

# internal states
self.cleaned_objects = set()
self.cooled_objects = set()
Expand Down Expand Up @@ -62,7 +63,6 @@ def reset(self, scene_name_or_num,
event = super().step(dict(
action='Initialize',
gridSize=grid_size,
cameraY=camera_y,
renderImage=render_image,
renderDepthImage=render_depth_image,
renderClassImage=render_class_image,
Expand Down Expand Up @@ -95,24 +95,31 @@ def restore_scene(self, object_poses, object_toggles, dirty_and_empty):
super().step(dict(
action='Initialize',
gridSize=constants.AGENT_STEP_SIZE / constants.RECORD_SMOOTHING_FACTOR,
cameraY=constants.CAMERA_HEIGHT_OFFSET,
renderImage=constants.RENDER_IMAGE,
renderDepthImage=constants.RENDER_DEPTH_IMAGE,
renderClassImage=constants.RENDER_CLASS_IMAGE,
renderObjectImage=constants.RENDER_OBJECT_IMAGE,
visibility_distance=constants.VISIBILITY_DISTANCE,
makeAgentsVisible=False,
))
if len(object_toggles) > 0:
super().step((dict(action='SetObjectToggles', objectToggles=object_toggles)))



if len(object_toggles) > 0:
# TODO: problem here: the API has change on these two attributes.
for o in object_toggles:
super().step((dict(action='SetObjectStates',
SetObjectStates=o)))

if dirty_and_empty:
super().step(dict(action='SetStateOfAllObjects',
StateChange="CanBeDirty",
forceAction=True))
super().step(dict(action='SetStateOfAllObjects',
StateChange="CanBeFilled",
forceAction=False))
# TODO: problem here: the API also change on these two attributes.
for o in object_poses:
super().step(dict(action='SetObjectStates',
SetObjectStates={'objectType': o['objectName'].split('_')[0], 'stateChange': 'dirtyable', 'isDirty': True}))

super().step(dict(action='SetObjectStates',
SetObjectStates={'objectType': o['objectName'].split('_')[0], 'stateChange': 'canFillWithLiquid', 'isFilledWithLiquid': False}))

super().step((dict(action='SetObjectPoses', objectPoses=object_poses)))

def set_task(self, traj, args, reward_type='sparse', max_episode_length=2000):
Expand All @@ -126,22 +133,25 @@ def step(self, action, smooth_nav=False):
'''
overrides ai2thor.controller.Controller.step() for smooth navigation and goal_condition updates
'''
if smooth_nav:
if "MoveAhead" in action['action']:
self.smooth_move_ahead(action)
elif "Rotate" in action['action']:
self.smooth_rotate(action)
elif "Look" in action['action']:
self.smooth_look(action)
if 'action' in action:
if smooth_nav:
if "MoveAhead" in action['action']:
self.smooth_move_ahead(action)
elif "Rotate" in action['action']:
self.smooth_rotate(action)
elif "Look" in action['action']:
self.smooth_look(action)
else:
super().step(action)
else:
super().step(action)
if "LookUp" in action['action']:
self.look_angle(-constants.AGENT_HORIZON_ADJ)
elif "LookDown" in action['action']:
self.look_angle(constants.AGENT_HORIZON_ADJ)
else:
super().step(action)
else:
if "LookUp" in action['action']:
self.look_angle(-constants.AGENT_HORIZON_ADJ)
elif "LookDown" in action['action']:
self.look_angle(constants.AGENT_HORIZON_ADJ)
else:
super().step(action)
super().step(action)

event = self.update_states(action)
self.check_post_conditions(action)
Expand All @@ -151,8 +161,9 @@ def check_post_conditions(self, action):
'''
handle special action post-conditions
'''
if action['action'] == 'ToggleObjectOn':
self.check_clean(action['objectId'])
if 'action' in action:
if action['action'] == 'ToggleObjectOn':
self.check_clean(action['objectId'])

def update_states(self, action):
'''
Expand All @@ -162,20 +173,21 @@ def update_states(self, action):
event = self.last_event
if event.metadata['lastActionSuccess']:
# clean
if action['action'] == 'ToggleObjectOn' and "Faucet" in action['objectId']:
sink_basin = get_obj_of_type_closest_to_obj('SinkBasin', action['objectId'], event.metadata)
cleaned_object_ids = sink_basin['receptacleObjectIds']
self.cleaned_objects = self.cleaned_objects | set(cleaned_object_ids) if cleaned_object_ids is not None else set()
# heat
if action['action'] == 'ToggleObjectOn' and "Microwave" in action['objectId']:
microwave = get_objects_of_type('Microwave', event.metadata)[0]
heated_object_ids = microwave['receptacleObjectIds']
self.heated_objects = self.heated_objects | set(heated_object_ids) if heated_object_ids is not None else set()
# cool
if action['action'] == 'CloseObject' and "Fridge" in action['objectId']:
fridge = get_objects_of_type('Fridge', event.metadata)[0]
cooled_object_ids = fridge['receptacleObjectIds']
self.cooled_objects = self.cooled_objects | set(cooled_object_ids) if cooled_object_ids is not None else set()
if 'action' in action:
if action['action'] == 'ToggleObjectOn' and "Faucet" in action['objectId']:
sink_basin = get_obj_of_type_closest_to_obj('SinkBasin', action['objectId'], event.metadata)
cleaned_object_ids = sink_basin['receptacleObjectIds']
self.cleaned_objects = self.cleaned_objects | set(cleaned_object_ids) if cleaned_object_ids is not None else set()
# heat
if action['action'] == 'ToggleObjectOn' and "Microwave" in action['objectId']:
microwave = get_objects_of_type('Microwave', event.metadata)[0]
heated_object_ids = microwave['receptacleObjectIds']
self.heated_objects = self.heated_objects | set(heated_object_ids) if heated_object_ids is not None else set()
# cool
if action['action'] == 'CloseObject' and "Fridge" in action['objectId']:
fridge = get_objects_of_type('Fridge', event.metadata)[0]
cooled_object_ids = fridge['receptacleObjectIds']
self.cooled_objects = self.cooled_objects | set(cooled_object_ids) if cooled_object_ids is not None else set()

return event

Expand Down Expand Up @@ -428,8 +440,7 @@ def to_thor_api_exec(self, action, object_id="", smooth_nav=False):
elif "PutObject" in action:
inventory_object_id = self.last_event.metadata['inventoryObjects'][0]['objectId']
action = dict(action="PutObject",
objectId=inventory_object_id,
receptacleObjectId=object_id,
objectId=object_id,
forceAction=True,
placeStationary=True)
event = self.step(action)
Expand Down
15 changes: 8 additions & 7 deletions gen/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
########################################################################################################################
# Goals

GOALS = ["pick_and_place_simple",
"pick_two_obj_and_place",
"look_at_obj_in_light",
GOALS = [
"pick_and_place_simple",
"pick_two_obj_and_place",
"look_at_obj_in_light",
"pick_clean_then_place_in_recep",
"pick_heat_then_place_in_recep",
"pick_cool_then_place_in_recep",
"pick_and_place_with_movable_recep"]

"pick_and_place_with_movable_recep",
]
GOALS_VALID = {"pick_and_place_simple": {"Kitchen", "LivingRoom", "Bathroom", "Bedroom"},
"pick_two_obj_and_place": {"Kitchen", "LivingRoom", "Bathroom", "Bedroom"},
"look_at_obj_in_light": {"LivingRoom", "Bedroom"},
Expand Down Expand Up @@ -88,11 +89,11 @@
X_DISPLAY = '0'

AGENT_STEP_SIZE = 0.25
AGENT_HORIZON_ADJ = 15
AGENT_HORIZON_ADJ = 30
AGENT_ROTATE_ADJ = 90
CAMERA_HEIGHT_OFFSET = 0.75
VISIBILITY_DISTANCE = 1.5
HORIZON_GRANULARITY = 15
HORIZON_GRANULARITY = 30

RENDER_IMAGE = True
RENDER_DEPTH_IMAGE = True
Expand Down
Loading