From f8bbad976485d97dab5854308db86d7ef47f71df Mon Sep 17 00:00:00 2001 From: LinxiFan Date: Sat, 23 May 2020 14:04:20 -0700 Subject: [PATCH 1/6] parse_config supports both dict and a config yaml path --- gibson2/utils/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gibson2/utils/utils.py b/gibson2/utils/utils.py index fdca935fe..5c7f1f9d4 100644 --- a/gibson2/utils/utils.py +++ b/gibson2/utils/utils.py @@ -1,9 +1,17 @@ +import os import numpy as np import yaml from scipy.spatial.transform import Rotation as R # File I/O related def parse_config(config): + if isinstance(config, dict): + return config + else: + assert isinstance(config, str) + + if not os.path.exists(config): + raise ValueError(f'config path {config} does not exist. Please either pass in a dict or a string that represents the file path to the config yaml.') with open(config, 'r') as f: config_data = yaml.load(f, Loader=yaml.FullLoader) return config_data From b1d8ba4bf9cc73c851354323d5e6798a2885c62a Mon Sep 17 00:00:00 2001 From: LinxiFan Date: Sat, 23 May 2020 14:10:06 -0700 Subject: [PATCH 2/6] minor fix --- gibson2/utils/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gibson2/utils/utils.py b/gibson2/utils/utils.py index 5c7f1f9d4..659eae04d 100644 --- a/gibson2/utils/utils.py +++ b/gibson2/utils/utils.py @@ -1,17 +1,18 @@ import os import numpy as np import yaml +import collections.abc from scipy.spatial.transform import Rotation as R # File I/O related def parse_config(config): - if isinstance(config, dict): + if isinstance(config, collections.abc.Mapping): return config else: assert isinstance(config, str) if not os.path.exists(config): - raise ValueError(f'config path {config} does not exist. Please either pass in a dict or a string that represents the file path to the config yaml.') + raise FileNotFoundError(f'config path {config} does not exist. Please either pass in a dict or a string that represents the file path to the config yaml.') with open(config, 'r') as f: config_data = yaml.load(f, Loader=yaml.FullLoader) return config_data From 7bb56e75bf863fb663f6adcfebe51e12ace1350c Mon Sep 17 00:00:00 2001 From: LinxiFan Date: Sun, 31 May 2020 22:04:13 -0700 Subject: [PATCH 3/6] Add os environment variable support for specifying gibson data paths --- gibson2/__init__.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gibson2/__init__.py b/gibson2/__init__.py index da0c81ce0..293f4371f 100644 --- a/gibson2/__init__.py +++ b/gibson2/__init__.py @@ -9,8 +9,19 @@ 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) -assets_path = global_config['assets_path'] -dataset_path = global_config['dataset_path'] +# can override assets_path and dataset_path from environment variable +if 'GIBSON_ASSETS_PATH' in os.environ: + assets_path = os.environ['GIBSON_ASSETS_PATH'] +else: + assets_path = global_config['assets_path'] +assets_path = os.path.expanduser(assets_path) + +if 'GIBSON_DATASET_PATH' in os.environ: + dataset_path = os.environ['GIBSON_DATASET_PATH'] +else: + dataset_path = global_config['dataset_path'] +dataset_path = os.path.expanduser(dataset_path) + root_path = os.path.dirname(os.path.realpath(__file__)) if not os.path.isabs(assets_path): From 75607613387aaee725cfd213846515fcbf77aac4 Mon Sep 17 00:00:00 2001 From: LinxiFan Date: Mon, 1 Jun 2020 10:41:25 -0700 Subject: [PATCH 4/6] Fix `normal` output to be consistent with RGB --- gibson2/envs/locomotor_env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gibson2/envs/locomotor_env.py b/gibson2/envs/locomotor_env.py index 0e626188c..cbc7c6a7e 100644 --- a/gibson2/envs/locomotor_env.py +++ b/gibson2/envs/locomotor_env.py @@ -308,7 +308,7 @@ def get_normal(self): """ :return: surface normal reading """ - return self.simulator.renderer.render_robot_cameras(modes='normal') + return self.simulator.renderer.render_robot_cameras(modes='normal')[0][:, :, :3] def get_seg(self): """ From cb476559c41e7682c9e36f6d238930c118629ae1 Mon Sep 17 00:00:00 2001 From: LinxiFan Date: Tue, 2 Jun 2020 20:13:24 -0700 Subject: [PATCH 5/6] Add GIBSON_DEVICE_ID environment var to manually override get_available_devices --- .../render/mesh_renderer/mesh_renderer_cpu.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/gibson2/core/render/mesh_renderer/mesh_renderer_cpu.py b/gibson2/core/render/mesh_renderer/mesh_renderer_cpu.py index 6f0b071c7..a0c83836a 100644 --- a/gibson2/core/render/mesh_renderer/mesh_renderer_cpu.py +++ b/gibson2/core/render/mesh_renderer/mesh_renderer_cpu.py @@ -1,3 +1,4 @@ +import os import sys import ctypes @@ -324,13 +325,18 @@ def __init__(self, width=512, height=512, vertical_fov=90, device_idx=0, use_fis self.fisheye = use_fisheye # self.context = glcontext.Context() # self.context.create_opengl_context((self.width, self.height)) - available_devices = get_available_devices() - if device_idx < len(available_devices): - device = available_devices[device_idx] - logging.info("Using device {} for rendering".format(device)) + if 'GIBSON_DEVICE_ID' in os.environ: + device = int(os.environ.get('GIBSON_DEVICE_ID')) + logging.info(f'GIBSON_DEVICE_ID environment variable has been manually set. ' + f'Using device {device} for rendering') else: - logging.info("Device index is larger than number of devices, falling back to use 0") - device = 0 + available_devices = get_available_devices() + if device_idx < len(available_devices): + device = available_devices[device_idx] + logging.info(f"Using device {device} for rendering") + else: + logging.info("Device index is larger than number of devices, falling back to use 0") + device = 0 self.device_idx = device_idx self.device_minor = device From 815e34971c6ef2138d8d648aad51516e3178a458 Mon Sep 17 00:00:00 2001 From: LinxiFan Date: Tue, 2 Jun 2020 20:22:36 -0700 Subject: [PATCH 6/6] minor fix to account for empty string case --- gibson2/core/render/mesh_renderer/mesh_renderer_cpu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gibson2/core/render/mesh_renderer/mesh_renderer_cpu.py b/gibson2/core/render/mesh_renderer/mesh_renderer_cpu.py index a0c83836a..31b8e0a2c 100644 --- a/gibson2/core/render/mesh_renderer/mesh_renderer_cpu.py +++ b/gibson2/core/render/mesh_renderer/mesh_renderer_cpu.py @@ -325,7 +325,7 @@ def __init__(self, width=512, height=512, vertical_fov=90, device_idx=0, use_fis self.fisheye = use_fisheye # self.context = glcontext.Context() # self.context.create_opengl_context((self.width, self.height)) - if 'GIBSON_DEVICE_ID' in os.environ: + if os.environ.get('GIBSON_DEVICE_ID', None): device = int(os.environ.get('GIBSON_DEVICE_ID')) logging.info(f'GIBSON_DEVICE_ID environment variable has been manually set. ' f'Using device {device} for rendering')