From 054a8f068137675a259b466cbc82c58122f59ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cem=20G=C3=B6kmen?= <1408354+cgokmen@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:57:39 -0700 Subject: [PATCH] Add colab docker and make some scripts more amenable to a quick demo --- .dockerignore | 3 +- docker/build_docker.sh | 7 +- docker/colab.Dockerfile | 21 +++++ docker/nginx.conf | 24 ++++++ .../examples/robots/robot_control_example.py | 38 +++++++-- omnigibson/utils/asset_utils.py | 77 +++++++------------ 6 files changed, 106 insertions(+), 64 deletions(-) create mode 100644 docker/colab.Dockerfile create mode 100644 docker/nginx.conf diff --git a/.dockerignore b/.dockerignore index 89ce2d9d5..89db90041 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1 @@ -omnigibson/data -docker \ No newline at end of file +omnigibson/data \ No newline at end of file diff --git a/docker/build_docker.sh b/docker/build_docker.sh index 313e475f0..5d72279cf 100755 --- a/docker/build_docker.sh +++ b/docker/build_docker.sh @@ -2,12 +2,11 @@ set -e -o pipefail docker build \ - -t stanfordvl/omnigibson:latest \ - -t stanfordvl/omnigibson:$(sed -ne "s/.*version= *['\"]\([^'\"]*\)['\"] *.*/\1/p" setup.py) \ + -t stanfordvl/omnigibson:colab-docker \ -f docker/prod.Dockerfile \ . docker build \ - -t stanfordvl/omnigibson-vscode:latest \ - -f docker/vscode.Dockerfile \ + -t stanfordvl/omnigibson-colab \ + -f docker/colab.Dockerfile \ . \ No newline at end of file diff --git a/docker/colab.Dockerfile b/docker/colab.Dockerfile new file mode 100644 index 000000000..c4eafdcb7 --- /dev/null +++ b/docker/colab.Dockerfile @@ -0,0 +1,21 @@ +FROM stanfordvl/omnigibson:colab-docker + +# environment settings +ARG DEBIAN_FRONTEND="noninteractive" +ENV OMNIGIBSON_HEADLESS="1" +ENV OMNIGIBSON_REMOTE_STREAMING="webrtc" + +# Fix the JS file to allow for remote streaming on the same port (80) +RUN sed -i "s/49100/80/g" /isaac-sim/extscache/omni.services.streamclient.webrtc-1.3.8/web/js/kit-player.js && \ + sed -i -E 's/IsValidIPv4=.*test\(e\)/IsValidIPv4=function(e){return true/g' /isaac-sim/extscache/omni.services.streamclient.webrtc-1.3.8/web/js/kit-player.js + +# Install nginx +RUN apt-get update && apt-get install -y nginx && apt-get clean + +# Download the demo dataset and the assets +RUN python -m omnigibson.utils.asset_utils --download_assets --download_demo_data --accept_license + +# Add the nginx configuration file +ADD docker/nginx.conf /etc/nginx/sites-available/default + +CMD nginx && python -m omnigibson.examples.robots.robot_control_example --quickstart \ No newline at end of file diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 000000000..0f91da807 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,24 @@ +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + +server { + listen 8123; + + location /streaming/ { + proxy_pass http://127.0.0.1:8211/streaming/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $host; + } + + location / { + proxy_pass http://127.0.0.1:49100/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $host; + } +} \ No newline at end of file diff --git a/omnigibson/examples/robots/robot_control_example.py b/omnigibson/examples/robots/robot_control_example.py index e08667944..5f0cc7cbf 100644 --- a/omnigibson/examples/robots/robot_control_example.py +++ b/omnigibson/examples/robots/robot_control_example.py @@ -57,7 +57,7 @@ def choose_controllers(robot, random_selection=False): return controller_choices -def main(random_selection=False, headless=False, short_exec=False): +def main(random_selection=False, headless=False, short_exec=False, quickstart=False): """ Robot control demo with selection Queries the user to select a robot, the controllers, a scene and a type of input (random actions or teleop) @@ -65,12 +65,16 @@ def main(random_selection=False, headless=False, short_exec=False): og.log.info(f"Demo {__file__}\n " + "*" * 80 + "\n Description:\n" + main.__doc__ + "*" * 80) # Choose scene to load - scene_model = choose_from_options(options=SCENES, name="scene", random_selection=random_selection) + scene_model = "Rs_int" + if not quickstart: + scene_model = choose_from_options(options=SCENES, name="scene", random_selection=random_selection) # Choose robot to create - robot_name = choose_from_options( - options=list(sorted(REGISTERED_ROBOTS.keys())), name="robot", random_selection=random_selection - ) + robot_name = "Fetch" + if not quickstart: + robot_name = choose_from_options( + options=list(sorted(REGISTERED_ROBOTS.keys())), name="robot", random_selection=random_selection + ) scene_cfg = dict() if scene_model == "empty": @@ -82,7 +86,7 @@ def main(random_selection=False, headless=False, short_exec=False): # Add the robot we want to load robot0_cfg = dict() robot0_cfg["type"] = robot_name - robot0_cfg["obs_modalities"] = ["rgb", "depth", "seg_instance", "normal", "scan", "occupancy_grid"] + robot0_cfg["obs_modalities"] = ["rgb"] robot0_cfg["action_type"] = "continuous" robot0_cfg["action_normalize"] = True @@ -94,11 +98,20 @@ def main(random_selection=False, headless=False, short_exec=False): # Choose robot controller to use robot = env.robots[0] - controller_choices = choose_controllers(robot=robot, random_selection=random_selection) + controller_choices = { + "base": "DifferentialDriveController", + "arm_0": "InverseKinematicsController", + "gripper_0": "MultiFingerGripperController", + "camera": "JointController" + } + if not quickstart: + controller_choices = choose_controllers(robot=robot, random_selection=random_selection) # Choose control mode if random_selection: control_mode = "random" + elif quickstart: + control_mode = "teleop" else: control_mode = choose_from_options(options=CONTROL_MODES, name="control mode") @@ -151,4 +164,13 @@ def main(random_selection=False, headless=False, short_exec=False): if __name__ == "__main__": - main() + import argparse + parser = argparse.ArgumentParser(description="Teleoperate a robot in a BEHAVIOR scene.") + + parser.add_argument( + "--quickstart", + action="store_true", + help="Whether the example should be loaded with default settings for a quick start.", + ) + args = parser.parse_args() + main(quickstart=args.quickstart) diff --git a/omnigibson/utils/asset_utils.py b/omnigibson/utils/asset_utils.py index 5082717bb..9491ed481 100644 --- a/omnigibson/utils/asset_utils.py +++ b/omnigibson/utils/asset_utils.py @@ -394,7 +394,7 @@ def download_assets(): # These datasets come as folders; in these folder there are scenes, so --strip-components are needed. -def download_demo_data(): +def download_demo_data(accept_license=False): """ Download OmniGibson demo dataset """ @@ -402,15 +402,16 @@ def download_demo_data(): if os.path.exists(gm.KEY_PATH): print("OmniGibson dataset encryption key already installed.") else: - print("\n") - print_user_agreement() - while ( - input( - "Do you agree to the above terms for using OmniGibson dataset? [y/n]" - ) - != "y" - ): - print("You need to agree to the terms for using OmniGibson dataset.") + if not accept_license: + print("\n") + print_user_agreement() + while ( + input( + "Do you agree to the above terms for using OmniGibson dataset? [y/n]" + ) + != "y" + ): + print("You need to agree to the terms for using OmniGibson dataset.") download_key() @@ -445,7 +446,7 @@ def download_key(): assert urlretrieve(path, gm.KEY_PATH, show_progress), "Key download failed." -def download_og_dataset(): +def download_og_dataset(accept_license=False): """ Download OmniGibson dataset """ @@ -453,15 +454,16 @@ def download_og_dataset(): if os.path.exists(gm.KEY_PATH): print("OmniGibson dataset encryption key already installed.") else: - print("\n") - print_user_agreement() - while ( - input( - "Do you agree to the above terms for using OmniGibson dataset? [y/n]" - ) - != "y" - ): - print("You need to agree to the terms for using OmniGibson dataset.") + if not accept_license: + print("\n") + print_user_agreement() + while ( + input( + "Do you agree to the above terms for using OmniGibson dataset? [y/n]" + ) + != "y" + ): + print("You need to agree to the terms for using OmniGibson dataset.") download_key() @@ -477,28 +479,6 @@ def download_og_dataset(): # These datasets come as folders; in these folder there are scenes, so --strip-components are needed. -def change_data_path(): - """ - Changes the data paths for this repo - """ - with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "global_config.yaml")) as f: - global_config = yaml.load(f, Loader=yaml.FullLoader) - print("Current dataset path:") - for k, v in global_config.items(): - print("{}: {}".format(k, v)) - for k, v in global_config.items(): - new_path = input("Change {} from {} to: ".format(k, v)) - global_config[k] = new_path - - print("New dataset path:") - for k, v in global_config.items(): - print("{}: {}".format(k, v)) - response = input("Save? [y/n]") - if response == "y": - with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "global_config.yaml"), "w") as f: - yaml.dump(global_config, f) - - def decrypt_file(encrypted_filename, decrypted_filename): with open(gm.KEY_PATH, "rb") as filekey: key = filekey.read() @@ -543,17 +523,14 @@ def decrypted(encrypted_filename): parser.add_argument("--download_assets", action="store_true", help="download assets file") parser.add_argument("--download_demo_data", action="store_true", help="download demo data Rs") parser.add_argument("--download_og_dataset", action="store_true", help="download OmniGibson Dataset") - parser.add_argument("--change_data_path", action="store_true", help="change the path to store assets and datasets") - + parser.add_argument("--accept_license", action="store_true", help="pre-accept the OmniGibson dataset license") args = parser.parse_args() if args.download_assets: download_assets() - elif args.download_demo_data: - download_demo_data() - elif args.download_og_dataset: - download_og_dataset() - elif args.change_data_path: - change_data_path() + if args.download_demo_data: + download_demo_data(accept_license=args.accept_license) + if args.download_og_dataset: + download_og_dataset(accept_license=args.accept_license) og.shutdown()