Skip to content

Commit

Permalink
Merge branch 'naive-scale' into nanna
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroHG committed Oct 11, 2022
2 parents b760177 + 50f40ca commit 95df853
Show file tree
Hide file tree
Showing 383 changed files with 52,875 additions and 59,848 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,3 @@ AI2 is a non-profit institute with the mission to contribute to humanity through
<a href="//prior.allenai.org">
<p align="center"><img width="100%" src="https://raw.githubusercontent.com/allenai/ai2thor/main/doc/static/ai2-prior.svg" /></p>
</a>

2 changes: 1 addition & 1 deletion ai2thor/tests/data/floorplan28-fixed-obj-poses.json

Large diffs are not rendered by default.

136 changes: 65 additions & 71 deletions ai2thor/tests/test_unity_procedural.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# import pytest
import json
import os
import pytest

import cv2
import numpy as np
from ai2thor.wsgi_server import WsgiServer
import pytest

from ai2thor.fifo_server import FifoServer
from .test_unity import build_controller, images_near, depth_images_near
import cv2
import json
from ai2thor.wsgi_server import WsgiServer

from .test_unity import build_controller, depth_images_near, images_near

DATA_PATH = "ai2thor/tests/data/"
IMAGE_FOLDER_PATH = os.path.join(DATA_PATH, "procedural")
Expand All @@ -19,7 +22,7 @@
width=300,
height=300,
fieldOfView=45,
agentCount=1
agentCount=1,
)

_wsgi_controller = dict(server_class=WsgiServer, **shared_args)
Expand All @@ -29,12 +32,14 @@
wsgi = [_wsgi_controller]
fifo = [_fifo_controller]


def create_pixel_diff_image(img, g_truth):
dx = np.where(~np.all(g_truth == img, axis=-1))
copy = img.copy()
copy[dx] = (255, 0, 255)
return copy


house_template = {
"id": "house_0",
"layout": """
Expand All @@ -60,104 +65,92 @@ def create_pixel_diff_image(img, g_truth):
"wallTemplate": {
"material": {
"unlit": False,
"color": {
"r": 1.0,
"g": 0.0,
"b": 0.0,
"a": 1.0
}
"color": {"r": 1.0, "g": 0.0, "b": 0.0, "a": 1.0},
}
},
"floorTemplate": {
"roomType": "Bedroom",
"floorMaterial": { "name": "DarkWoodFloors" },
"floorMaterial": {"name": "DarkWoodFloors"},
},
"floorYPosition": 0.0,
"wallHeight": 3.0
"wallHeight": 3.0,
},
"2": {
"wallTemplate": {
"material": {
"unlit": False,
"color": {
"r": 0.0,
"g": 0.0,
"b": 1.0,
"a": 1.0
}
"color": {"r": 0.0, "g": 0.0, "b": 1.0, "a": 1.0},
}
},
"floorTemplate": {
"roomType": "LivingRoom",
"floorMaterial": { "name": "RedBrick"}
"floorMaterial": {"name": "RedBrick"},
},
"floorYPosition": 0.0,
"wallHeight": 3.0
}
},
"holes": {
"=": {
"room0": "1",
"openness": 1.0,
"assetId": "Doorway_1"
}
},
"objects": {
"+": {
"kinematic": True,
"assetId": "Chair_007_1"
}
"wallHeight": 3.0,
},
},
"holes": {"=": {"room0": "1", "openness": 1.0, "assetId": "Doorway_1"}},
"objects": {"+": {"kinematic": True, "assetId": "Chair_007_1"}},
"proceduralParameters": {
"floorColliderThickness": 1.0,
"receptacleHeight": 0.7,
"skyboxId": "Sky1",
"ceilingMaterial": { "name": "ps_mat" }
"ceilingMaterial": {"name": "ps_mat"},
},
"schema": "1.0.0"
"metadata": {"schema": "1.0.0"},
}

# TODO rendering is different for fifo and wsgi server
@pytest.mark.parametrize("controller_args", fifo)
def test_render_lit(controller_args):
print("Args")
print(controller_args)
controller = build_controller(
**controller_args
)
controller = build_controller(**controller_args)

rgb_filename = "proc_rgb_lit_fifo.png"
ground_truth = cv2.imread(os.path.join(IMAGE_FOLDER_PATH, rgb_filename))

evt = controller.step(
action="GetHouseFromTemplate",
template=house_template
)
evt = controller.step(action="GetHouseFromTemplate", template=house_template)

print("Action success {0}, message {1}".format(evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]))
print(
"Action success {0}, message {1}".format(
evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]
)
)
assert evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]
house = evt.metadata["actionReturn"]

with open("test_render_lit.json", "w") as f:
print(house)
json.dump(house, f)

evt = controller.step(
action="CreateHouse",
house=house
)
evt = controller.step(action="CreateHouse", house=house)

print("Action success {0}, message {1}".format(evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]))
assert evt.metadata['lastActionSuccess']
print(
"Action success {0}, message {1}".format(
evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]
)
)
assert evt.metadata["lastActionSuccess"]

evt = controller.step(
action="TeleportFull", x=3.0, y=0.9010001, z=1.0, rotation=dict(x=0, y=0, z=0),
horizon=0, standing=True, forceAction=True
action="TeleportFull",
x=3.0,
y=0.9010001,
z=1.0,
rotation=dict(x=0, y=0, z=0),
horizon=0,
standing=True,
forceAction=True,
)

controller.stop()

assert images_near(evt.cv2img, ground_truth, max_mean_pixel_diff=52, debug_save=True)
assert images_near(
evt.cv2img, ground_truth, max_mean_pixel_diff=52, debug_save=True
)


#
# @pytest.mark.parametrize("controller_args", wsgi)
Expand All @@ -179,39 +172,40 @@ def test_render_lit(controller_args):
# assert depth_images_near(server_image, raw_depth, epsilon=2e-1, debug_save=True)



@pytest.mark.parametrize("controller_args", fifo)
def test_depth(controller_args):
controller_args.update(
renderDepthImage=True,
)

controller = build_controller(
**controller_args
)
controller = build_controller(**controller_args)

depth_filename = "proc_depth.npy"
raw_depth = np.load(os.path.join(IMAGE_FOLDER_PATH, depth_filename))

evt = controller.step(
action="GetHouseFromTemplate",
template=house_template
)
evt = controller.step(action="GetHouseFromTemplate", template=house_template)

assert evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]
house = evt.metadata["actionReturn"]

evt = controller.step(
action="CreateHouse",
house=house
)
evt = controller.step(action="CreateHouse", house=house)

print("Action success {0}, message {1}".format(evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]))
assert evt.metadata['lastActionSuccess']
print(
"Action success {0}, message {1}".format(
evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]
)
)
assert evt.metadata["lastActionSuccess"]

evt = controller.step(
action="TeleportFull", x=3.0, y=0.9010001, z=1.0, rotation=dict(x=0, y=0, z=0),
horizon=0, standing=True, forceAction=True
action="TeleportFull",
x=3.0,
y=0.9010001,
z=1.0,
rotation=dict(x=0, y=0, z=0),
horizon=0,
standing=True,
forceAction=True,
)

controller.stop()
Expand Down
2 changes: 1 addition & 1 deletion unity/Assets/Editor/ExpRoomEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ExpRoomEditor : EditorWindow {
[MenuItem("ExpRoom/Add all pickupable receptacle prefabs to AvailableContainers", true)]
[MenuItem("ExpRoom/Interactively add all pickupable prefabs to AvailableObjects", true)]
static bool HideMenuIfNotInExpRoom() {
Debug.Log(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
//Debug.Log(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
return UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "FloorPlan_ExpRoom";
}

Expand Down
11 changes: 11 additions & 0 deletions unity/Assets/Editor/NormalsVisualizer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 95df853

Please sign in to comment.