Skip to content

Commit

Permalink
merge from distortion
Browse files Browse the repository at this point in the history
  • Loading branch information
KuoHaoZeng committed Feb 8, 2025
2 parents 9cdbe76 + 8ecd19a commit 2f63498
Show file tree
Hide file tree
Showing 39 changed files with 3,897 additions and 592 deletions.
22 changes: 10 additions & 12 deletions ai2thor/_quality_settings.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# GENERATED FILE - DO NOT EDIT
DEFAULT_QUALITY = "Ultra"
QUALITY_SETTINGS = {
"DONOTUSE": 0,
"High": 5,
"High WebGL": 8,
"Low": 2,
"Medium": 3,
"MediumCloseFitShadows": 4,
"Ultra": 7,
"Very High": 6,
"Very Low": 1,
}
DEFAULT_QUALITY = 'Ultra'
QUALITY_SETTINGS = {'DONOTUSE': 0,
'High': 5,
'High WebGL': 8,
'Low': 2,
'Medium': 3,
'MediumCloseFitShadows': 4,
'Ultra': 7,
'Very High': 6,
'Very Low': 1}
8 changes: 7 additions & 1 deletion ai2thor/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,12 +1012,18 @@ def run_metadata_hook(self, metadata: MetadataWrapper) -> bool:
return True
return False

def step(self, action: Union[str, Dict[str, Any]] = None, **action_args):
def step(self, action: Union[str, list, Dict[str, Any]] = None, **action_args):
if isinstance(action, Dict):
# We attempt to prevent changes from leaking, doing a deep copy
# isn't a good idea as the action may have huge arguments (e.g. when
# generating a house)
action = {**action}
elif isinstance(action, list):
# Multi action
action = dict(
action="MultiStep",
actions=action
)
else:
action = dict(action=action)

Expand Down
7 changes: 7 additions & 0 deletions ai2thor/fifo_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class FieldType(IntEnum):
THIRD_PARTY_IMAGE_IDS = 14
THIRD_PARTY_CLASSES = 15
THIRD_PARTY_FLOW = 16
DISTORTION_IMAGE = 17,
THIRD_PARTY_DISTORTION=18,
END_OF_MESSAGE = 255


Expand Down Expand Up @@ -83,19 +85,22 @@ def __init__(
# allows us to map the enum to form field names
# for backwards compatibility
# this can be removed when the wsgi server is removed
# TODO make more generic cod ewise, one new value you have to modify 3 different arrays
self.form_field_map = {
FieldType.RGB_IMAGE: "image",
FieldType.DEPTH_IMAGE: "image_depth",
FieldType.CLASSES_IMAGE: "image_classes",
FieldType.IDS_IMAGE: "image_ids",
FieldType.NORMALS_IMAGE: "image_normals",
FieldType.FLOWS_IMAGE: "image_flow",
FieldType.DISTORTION_IMAGE: "image_distortion",
FieldType.THIRD_PARTY_IMAGE: "image-thirdParty-camera",
FieldType.THIRD_PARTY_DEPTH: "image_thirdParty_depth",
FieldType.THIRD_PARTY_NORMALS: "image_thirdParty_normals",
FieldType.THIRD_PARTY_IMAGE_IDS: "image_thirdParty_image_ids",
FieldType.THIRD_PARTY_CLASSES: "image_thirdParty_classes",
FieldType.THIRD_PARTY_FLOW: "image_thirdParty_flow",
FieldType.THIRD_PARTY_DISTORTION: "image_thirdParty_distortion",
}

self.image_fields = {
Expand All @@ -111,6 +116,8 @@ def __init__(
FieldType.THIRD_PARTY_IMAGE_IDS,
FieldType.THIRD_PARTY_CLASSES,
FieldType.THIRD_PARTY_FLOW,
FieldType.DISTORTION_IMAGE,
FieldType.THIRD_PARTY_DISTORTION
}

self.eom_header = self._create_header(FieldType.END_OF_MESSAGE, b"")
Expand Down
57 changes: 41 additions & 16 deletions ai2thor/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ def write_image(
image_dir,
suffix,
image_per_frame=False,
color_frame=False,
semantic_segmentation_frame=False,
instance_segmentation_frame=False,
depth_frame=False,
color_frame=False,
distortion_frame=False,
third_party_camera_frames=False,
metadata=False,
):
def save_image(name, image, flip_br=False):
Expand Down Expand Up @@ -271,6 +273,13 @@ def json_write(name, obj):
array_to_image,
save_image,
),
(
"distortion",
distortion_frame,
lambda event: event.distortion_frame,
array_to_image,
lambda x, y: save_image(x, y, flip_br=True),
),
(
"depth",
depth_frame,
Expand All @@ -290,6 +299,22 @@ def json_write(name, obj):
x.astype(np.float32),
),
),
(
"third_party_camera_frames",
third_party_camera_frames,
lambda event: event.third_party_camera_frames,
lambda x: x,
lambda name, images: [save_image(name, image, flip_br=True) for (i, image) in zip(range(len(images)), images)]

),
(
"third_party_distortion_frames",
third_party_camera_frames and distortion_frame,
lambda event: event.third_party_distortion_frames,
lambda x: x,
lambda name, images: [save_image(name, image, flip_br=True) for (i, image) in zip(range(len(images)), images)]

),
(
"metadata",
metadata,
Expand All @@ -300,19 +325,19 @@ def json_write(name, obj):
]

for frame_filename, condition, frame_func, transform, save in frame_writes:
frame = frame_func(event)
if frame is not None and condition:
frame = transform(frame)
image_name = os.path.join(
image_dir,
"{}{}".format(frame_filename, "{}".format(suffix) if image_per_frame else ""),
)
print("Image {}, {}".format(image_name, image_dir))
save(image_name, frame)

elif condition:
print(
"No frame '{}' present, call initialize with the right parameters".format(
frame_filename
if condition:
frame = frame_func(event)
if frame is not None:
frame = transform(frame)
image_name = os.path.join(
image_dir,
"{}{}".format(frame_filename, "{}".format(suffix) if image_per_frame else ""),
)
print("Image {}, {}".format(image_name, image_dir))
save(image_name, frame)
else:
print(
"No frame '{}' present, call initialize with the right parameters".format(
frame_filename
)
)
)
14 changes: 14 additions & 0 deletions ai2thor/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def __init__(self, metadata):
self.third_party_instance_masks = []
self.third_party_class_masks = []
self.third_party_camera_frames = []
self.third_party_distortion_frames = []
self.third_party_semantic_segmentation_frames = []
self.third_party_instance_segmentation_frames = []
self.third_party_depth_frames = []
Expand Down Expand Up @@ -646,6 +647,17 @@ def add_image_flows(self, image_flows_data):
image_flows_data, self.screen_width, self.screen_height
)

# TODO make more generic, above methids minus depth are basically the same
def add_image_distortion(self, image_distortion_data):
self.distortion_frame = read_buffer_image(
image_distortion_data, self.screen_width, self.screen_height
)

def add_third_party_image_distortion(self, distortion_data):
self.third_party_distortion_frames.append(
read_buffer_image(distortion_data, self.screen_width, self.screen_height)
)

def add_third_party_camera_image(self, third_party_image_data):
self.third_party_camera_frames.append(
read_buffer_image(third_party_image_data, self.screen_width, self.screen_height)
Expand Down Expand Up @@ -775,6 +787,7 @@ def create_event(self, metadata, files):
image_classes=e.add_image_classes,
image_normals=e.add_image_normals,
image_flow=e.add_image_flows,
image_distortion=e.add_image_distortion
)

for key in image_mapping.keys():
Expand All @@ -796,6 +809,7 @@ def create_event(self, metadata, files):
"image_thirdParty_classes": e.add_third_party_image_classes,
"image_thirdParty_normals": e.add_third_party_image_normals,
"image_thirdParty_flows": e.add_third_party_image_flows,
"image_thirdParty_distortion": e.add_third_party_image_distortion
}

if a["thirdPartyCameras"] is not None:
Expand Down
20 changes: 15 additions & 5 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,14 @@ def local_build_test(context, prefix="local", arch="OSXIntel64"):


@task(iterable=["scenes"])
def local_build(context, prefix="local", arch="OSXIntel64", scenes=None, scripts_only=False):
def local_build(context, prefix="local", arch="OSXIntel64", scenes=None, scripts_only=False, exclude_private_scenes=False):
import ai2thor.controller

build = ai2thor.build.Build(arch, prefix, False)
env = dict()
if os.path.isdir("unity/Assets/Private/Scenes") or os.path.isdir(
"Assets/Resources/ai2thor-objaverse/NoveltyTHOR_Assets/Scenes"
and not exclude_private_scenes
):
env["INCLUDE_PRIVATE_SCENES"] = "true"

Expand Down Expand Up @@ -1079,6 +1080,8 @@ def ci_build(
novelty_thor_scenes=False,
skip_delete_tmp_dir=False, # bool
cloudrendering_first=False,
only_cloudrendering=False,
private_scenes_skip=False
):
assert (commit_id is None) == (
branch is None
Expand Down Expand Up @@ -1158,15 +1161,22 @@ def ci_build(
# disabling delete temporarily since it interferes with pip releases
# pytest_s3_object(build["commit_id"]).delete()
logger.info(f"pending build for {build['branch']} {build['commit_id']}")

if not private_scenes_skip:
novelty_thor_scenes = False
private_repos = []

clean(private_repos=private_repos)
private_scene_options = [novelty_thor_scenes]

subprocess.check_call("git fetch", shell=True)
subprocess.check_call("git checkout %s --" % build["branch"], shell=True)
logger.info(f" After checkout")
subprocess.check_call("git checkout -qf %s" % build["commit_id"], shell=True)

private_scene_options = [novelty_thor_scenes]

build_archs = ["OSXIntel64"] # , "Linux64"]
build_archs = [] if only_cloudrendering else ["OSXIntel64"] # , "Linux64"]


# CloudRendering only supported with 2020.3.25
# should change this in the future to automatically install
Expand Down Expand Up @@ -1260,10 +1270,10 @@ def ci_build(
# succeeded during an earlier run

pytest_platform = (
"OSXIntel64" if sys.platform.startswith("darwin") else "CloudRendering"
"CloudRendering" if only_cloudrendering else ("OSXIntel64" if sys.platform.startswith("darwin") else "CloudRendering")
)
# Weirdly even in Linux you can run utf tests using OSX build cache, but not CloudRendering
utf_test_platform = "OSXIntel64"
utf_test_platform = "CloudRendering" if only_cloudrendering else "OSXIntel64"

link_build_cache(
arch_temp_dirs[utf_test_platform], utf_test_platform, build["branch"]
Expand Down
Loading

0 comments on commit 2f63498

Please sign in to comment.