Skip to content

Commit

Permalink
Multi action pass and removes logs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroHG committed Dec 19, 2024
1 parent 0d51b19 commit 7c61ad0
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 14 deletions.
8 changes: 7 additions & 1 deletion ai2thor/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,12 +1002,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
58 changes: 57 additions & 1 deletion test_distortion.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,36 @@ def load_scene(scene_name, house_path=None, run_in_editor=False, platform=None,

enableDistortionMap = True

# STRETCH_ENV_ARGS = dict(
# gridSize=GRID_SIZE
# * 0.75, # Intentionally make this smaller than AGENT_MOVEMENT_CONSTANT to improve fidelity
# width=GOPRO_CAMERA_WIDTH,
# height=GOPRO_CAMERA_HEIGHT,
# visibilityDistance=MAXIMUM_DISTANCE_ARM_FROM_AGENT_CENTER,
# visibilityScheme="Distance",
# fieldOfView=INTEL_VERTICAL_FOV,
# server_class=ai2thor.fifo_server.FifoServer,
# useMassThreshold=True,
# massThreshold=10,
# autoSimulation=False,
# autoSyncTransforms=True,
# renderInstanceSegmentation=True,
# agentMode="stretch",
# renderDepthImage=SAVE_DEPTH,
# cameraNearPlane=0.01, # VERY VERY IMPORTANT
# branch=None, # IMPORTANT do not use branch
# commit_id=STRETCH_COMMIT_ID,
# server_timeout=MAXIMUM_SERVER_TIMEOUT,
# snapToGrid=False,
# fastActionEmit=False,
# action_hook_runner=_ACTION_HOOK_RUNNER,
# renderDistortionImage=True,
# enableDistortionMap=True,

all_args = dict(
# local_executable_path="unity/builds/thor-OSXIntel64-local/thor-OSXIntel64-local.app/Contents/MacOS/AI2-THOR",
# local_build=True,
# agentMode="stretch",
agentMode="stretch",
platform=platform,
scene=scene_name,
gridSize=0.25,
Expand All @@ -44,6 +70,7 @@ def load_scene(scene_name, house_path=None, run_in_editor=False, platform=None,
renderInstanceSegmentation=True,
enableDistortionMap=enableDistortionMap,
fieldOfView=120,
fastActionEmit=False,
**args,
)

Expand Down Expand Up @@ -158,6 +185,35 @@ def load_scene(scene_name, house_path=None, run_in_editor=False, platform=None,
print(f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}")
print(f'Error: {evt.metadata["errorMessage"]}')

# event = controller.step(
# action="MultiStep",
# actions=[
# dict(action="MoveBack"),
# dict(action="MoveBac"),
# dict(action="MoveBack"),
# dict(action="MoveBack")
# ]
# )


event = controller.step([
dict(action="MoveBack"),
dict(action="MoveBack"),
dict(action="MoveBack"),
dict(action="MoveBack")
]
)

print("MultiStep")
print(f"last action: {event.metadata['lastAction']}")
print(f"Action {controller.last_action['action']} success: {event.metadata['lastActionSuccess']}")
print(f'Error: {event.metadata["errorMessage"]}')

event = controller.step({'action': 'RotateAgent', 'degrees': -34.391552838580424})
print(f"last action: {event.metadata['lastAction']}")
print(f"Action {controller.last_action['action']} success: {event.metadata['lastActionSuccess']}")
print(f'Error: {event.metadata["errorMessage"]}')

InteractiveControllerPrompt.write_image(controller.last_event, image_dir, "", semantic_segmentation_frame=True, depth_frame=True, color_frame=True, third_party_camera_frames=True, distortion_frame=distortion)
# input()

Expand Down
17 changes: 9 additions & 8 deletions unity/Assets/Scripts/AgentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,14 @@ public void UpdateRenderingManagers(IEnumerable<string> activePassList, bool cam
var renderingManagers = agents.Select(agent => agent.m_Camera.GetComponent<RenderingManager>())
.Concat(thirdPartyCameras.Select(cam => cam.GetComponent<RenderingManager>()));
foreach (var renderingManager in renderingManagers) {
Debug.Log($"------ updateRenderingManagers enablepasses for {renderingManager.transform.parent.name}");
// Debug.Log($"------ updateRenderingManagers enablepasses for {renderingManager.transform.parent.name}");
renderingManager.EnablePasses(activePassList, cameraChange);
}
}

private void UpdateActivePasses() {
// TODO Refactor so that we know where these strings come from
Debug.Log($"--------- enableDistortionMap {this.enableDistortionMap}");
// Debug.Log($"--------- enableDistortionMap {this.enableDistortionMap}");
activeCapturePassList = new Dictionary<string, bool>() {
{"_img", true},
{"_depth", this.renderDepthImage},
Expand Down Expand Up @@ -1163,7 +1163,7 @@ private void captureScreenAsyncNew(
Camera camera
) {
var rm = camera.GetComponent<RenderingManager>();
Debug.Log($"-- is rendering manager null? {rm == null} rm {rm}");
// Debug.Log($"-- is rendering manager null? {rm == null} rm {rm}");
rm.GetCaptureAsync("_img", payload, key);
}

Expand Down Expand Up @@ -1229,7 +1229,7 @@ private byte[] captureCamera(Camera camera) {
// tex.Apply();
var bytes = tex.GetRawTextureData();

Debug.Log($"-------- captureCamera {bytes.Length}");
// Debug.Log($"-------- captureCamera {bytes.Length}");
return bytes;
}

Expand Down Expand Up @@ -1351,7 +1351,7 @@ private void addObjectImage(
ref MetadataWrapper metadata
) {
if (this.renderInstanceSegmentation || this.renderSemanticSegmentation) {
Debug.Log($"imageSynthesis null {agent.ImageSynthesis == null}");
// Debug.Log($"imageSynthesis null {agent.ImageSynthesis == null}");
if (!agent.ImageSynthesis.hasCapturePass("_id")) {
Debug.LogError(
"Object Image not available in imagesynthesis - returning empty image"
Expand All @@ -1366,7 +1366,7 @@ ref MetadataWrapper metadata

List<ColorId> colors = new List<ColorId>();

Debug.Log($"----- imageSynt null? {agent.ImageSynthesis == null} { agent.ImageSynthesis} colorids null {agent.ImageSynthesis.colorIds == null}");
// Debug.Log($"----- imageSynt null? {agent.ImageSynthesis == null} { agent.ImageSynthesis} colorids null {agent.ImageSynthesis.colorIds == null}");
foreach (Color key in agent.ImageSynthesis.colorIds.Keys) {
ColorId cid = new ColorId();
cid.color = new ushort[]
Expand Down Expand Up @@ -1407,12 +1407,12 @@ private void addCapture(
string fieldName
) {
if (flag) {
Debug.Log($"------- Gettin capture for {captureName} {flag}");
// Debug.Log($"------- Gettin capture for {captureName} {flag}");
var renderingManager = camera.GetComponent<RenderingManager>();
byte[] bytes = renderingManager.GetCaptureBytes(captureName);
if (captureName == "_depth") {
var localBytesX = new byte[] {bytes[0], bytes[1], bytes[2], bytes[3] };
Debug.Log($"-------- _depth bytes {string.Join(", ", bytes.Take(100))} convert {System.BitConverter.ToSingle(localBytesX, 0)}");
// Debug.Log($"-------- _depth bytes {string.Join(", ", bytes.Take(100))} convert {System.BitConverter.ToSingle(localBytesX, 0)}");
}
payload.Add(new KeyValuePair<string, byte[]>(fieldName, bytes));
}
Expand Down Expand Up @@ -1489,6 +1489,7 @@ bool shouldRenderImageSynthesis
cameraMetadata[i] = cMetadata;
// addThirdPartyCameraImage(renderPayload, camera);
renderPayload.Add(new KeyValuePair<string, byte[]>("image-thirdParty-camera", captureCamera(camera)));
// Debug.Log($"------- shouldRenderImageSynthesis {shouldRenderImageSynthesis}");

if (shouldRenderImageSynthesis) {
ImageSynthesis imageSynthesis =
Expand Down
24 changes: 24 additions & 0 deletions unity/Assets/Scripts/BaseFPSAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2789,6 +2789,30 @@ public void ProcessControlCommand(DynamicServerAction controlCommand) {
ProcessControlCommand(controlCommand: controlCommand, target: this);
}

public ActionFinished MultiStep(List<JObject> actions) {
var actionResults = new List<ActionFinished>();
foreach (var jobject in actions) {
var action = new DynamicServerAction(jobject);
Debug.Log($"---- Running action: {action.action}");
this.ProcessControlCommand(action);
var actionFinished = new ActionFinished(
success: this.lastActionSuccess,
actionReturn: this.actionReturn,
errorMessage: this.errorMessage
);
if (!actionFinished.success) {
// this.lastAction = action.action;
return actionFinished;
}
actionResults.Add(actionFinished);
}
return new ActionFinished(
success: actionResults.All(x => x.success),
actionReturn: actionResults.Select(x => x.actionReturn),
errorMessage: string.Join("/n", actionResults.Select(x => x.errorCode))
);
}

public void ProcessControlCommand<T>(DynamicServerAction controlCommand, T target)
where T : ActionInvokable {
lastActionInitialPhysicsSimulateCount = PhysicsSceneManager.PhysicsSimulateCallCount;
Expand Down
2 changes: 1 addition & 1 deletion unity/Assets/Scripts/CapturePass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public virtual void OnInitialize(Camera mainCamera) {


public virtual void OnCameraChange(Camera mainCamera) {
Debug.Log($"-------OnCameraChange {name} on object {mainCamera.gameObject.name}");
// Debug.Log($"-------OnCameraChange {name} on object {mainCamera.gameObject.name}");
if (tex != null) {
UnityEngine.Object.Destroy(tex);
tex = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ Shader "Custom/BarrelDistortionMap" {

float smoothDistortionMagnitude = 1.0 + _k1 * pow(r, 2.0) + _k2 * pow(r, 4.0) + _k3 * pow(r,6.0) + _k4 * pow(r,8.0);

float zoom_percent = 0.2;
float translate = (1.0 - zoom_percent) / 2.0;
float2 centered_uv_norm = normalize(centered_uv);


Expand Down
2 changes: 1 addition & 1 deletion unity/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ PlayerSettings:
webGLThreadsSupport: 0
webGLDecompressionFallback: 0
scriptingDefineSymbols:
1:
1: UNITY_POST_PROCESSING_STACK_V2
4: CROSS_PLATFORM_INPUT;MOBILE_INPUT;UNITY_POST_PROCESSING_STACK_V2
7: CROSS_PLATFORM_INPUT;MOBILE_INPUT;UNITY_POST_PROCESSING_STACK_V2
13: UNITY_POST_PROCESSING_STACK_V2
Expand Down

0 comments on commit 7c61ad0

Please sign in to comment.