diff --git a/omnigibson/examples/object_states/dicing_demo.py b/omnigibson/examples/object_states/dicing_demo.py index 1c0cc2a50..dd3029e89 100644 --- a/omnigibson/examples/object_states/dicing_demo.py +++ b/omnigibson/examples/object_states/dicing_demo.py @@ -95,15 +95,17 @@ def main(random_selection=False, headless=False, short_exec=False): orientation=T.euler2quat([-math.pi / 2, 0, 0]), ) - input("The knife will fall on the apple and dice it. Press [ENTER] to continue.") + if short_exec == False: + input("The knife will fall on the apple and dice it. Press [ENTER] to continue.") # Step simulation for a bit so that apple is diced - for i in range(1000): + for _ in range(1000): env.step(th.empty(0)) - input("Apple has been diced! Press [ENTER] to terminate the demo.") + if short_exec == False: + input("Apple has been diced! Press [ENTER] to terminate the demo.") - # Always close environment at the end + # Always close simulator at the end env.close() diff --git a/omnigibson/examples/object_states/heat_source_or_sink_demo.py b/omnigibson/examples/object_states/heat_source_or_sink_demo.py index 9c5ddce5f..911b4756f 100644 --- a/omnigibson/examples/object_states/heat_source_or_sink_demo.py +++ b/omnigibson/examples/object_states/heat_source_or_sink_demo.py @@ -8,7 +8,7 @@ from omnigibson.macros import gm gm.ENABLE_OBJECT_STATES = True -def main(): +def main(random_selection=False, headless=False, short_exec=False): # Create the scene config to load -- empty scene with a stove object added cfg = { "scene": { @@ -56,7 +56,8 @@ def main(): assert not heat_source_state # Toggle on stove, notify user - input("Heat source will now turn ON: Press ENTER to continue.") + if not short_exec: + input("Heat source will now turn ON: Press ENTER to continue.") stove.states[object_states.ToggledOn].set_value(True) assert stove.states[object_states.ToggledOn].get_value() @@ -71,20 +72,23 @@ def main(): env.step(th.empty(0)) # Toggle off stove, notify user - input("Heat source will now turn OFF: Press ENTER to continue.") + if not short_exec: + input("Heat source will now turn OFF: Press ENTER to continue.") stove.states[object_states.ToggledOn].set_value(False) assert not stove.states[object_states.ToggledOn].get_value() for _ in range(200): env.step(th.empty(0)) # Move stove, notify user - input("Heat source is now moving: Press ENTER to continue.") + if not short_exec: + input("Heat source is now moving: Press ENTER to continue.") stove.set_position(th.tensor([0, 1.0, 0.61])) for i in range(100): env.step(th.empty(0)) # Toggle on stove again, notify user - input("Heat source will now turn ON: Press ENTER to continue.") + if not short_exec: + input("Heat source will now turn ON: Press ENTER to continue.") stove.states[object_states.ToggledOn].set_value(True) assert stove.states[object_states.ToggledOn].get_value() for i in range(500): diff --git a/omnigibson/examples/object_states/heated_state_demo.py b/omnigibson/examples/object_states/heated_state_demo.py index 1467f879f..657ab573d 100644 --- a/omnigibson/examples/object_states/heated_state_demo.py +++ b/omnigibson/examples/object_states/heated_state_demo.py @@ -8,7 +8,7 @@ from omnigibson.macros import gm gm.ENABLE_OBJECT_STATES = True -def main(): +def main(random_selection=False, headless=False, short_exec=False): # Define object configurations for objects to load -- we want to load a light and three bowls obj_configs = [] @@ -70,8 +70,9 @@ def main(): print("==== Initial state ====") report_states(objs) - # Notify user that we're about to heat the object - input("Objects will be heated, and steam will slowly rise. Press ENTER to continue.") + if not short_exec: + # Notify user that we're about to heat the object + input("Objects will be heated, and steam will slowly rise. Press ENTER to continue.") # Heated. for obj in objs: @@ -83,7 +84,8 @@ def main(): # After a while, objects will be below the Steam temperature threshold. print("==== Objects are now heated... ====") print() - for _ in range(2000): + max_iterations = 2000 if not short_exec else 100 + for _ in range(max_iterations): env.step(th.empty(0)) # Also print temperatures temps = [f"{obj.states[object_states.Temperature].get_value():>7.2f}" for obj in objs] @@ -94,8 +96,10 @@ def main(): print("==== Objects are no longer heated... ====") report_states(objs) - # Close environment at the end - input("Demo completed. Press ENTER to shutdown environment.") + if not short_exec: + # Close environment at the end + input("Demo completed. Press ENTER to shutdown environment.") + env.close() diff --git a/omnigibson/examples/object_states/object_state_texture_demo.py b/omnigibson/examples/object_states/object_state_texture_demo.py index 5aefd5c7f..66e667488 100644 --- a/omnigibson/examples/object_states/object_state_texture_demo.py +++ b/omnigibson/examples/object_states/object_state_texture_demo.py @@ -11,7 +11,7 @@ gm.USE_GPU_DYNAMICS = True gm.ENABLE_HQ_RENDERING = True -def main(): +def main(random_selection=False, headless=False, short_exec=False): # Create the scene config to load -- empty scene plus a cabinet cfg = { "scene": { @@ -87,38 +87,45 @@ def main(): report_states() # Notify user that we're about to freeze the object, and then freeze the object - input("\nObject will be frozen. Press ENTER to continue.") + if not short_exec: + input("\nObject will be frozen. Press ENTER to continue.") obj.states[object_states.Temperature].set_value(-50) report_states() # Notify user that we're about to cook the object, and then cook the object - input("\nObject will be cooked. Press ENTER to continue.") + if not short_exec: + input("\nObject will be cooked. Press ENTER to continue.") obj.states[object_states.Temperature].set_value(100) report_states() # Notify user that we're about to burn the object, and then burn the object - input("\nObject will be burned. Press ENTER to continue.") + if not short_exec: + input("\nObject will be burned. Press ENTER to continue.") obj.states[object_states.Temperature].set_value(250) report_states() # Notify user that we're about to reset the object to its default state, and then reset state - input("\nObject will be reset to default state. Press ENTER to continue.") + if not short_exec: + input("\nObject will be reset to default state. Press ENTER to continue.") obj.states[object_states.Temperature].set_value(macros.object_states.temperature.DEFAULT_TEMPERATURE) obj.states[object_states.MaxTemperature].set_value(macros.object_states.temperature.DEFAULT_TEMPERATURE) report_states() # Notify user that we're about to soak the object, and then soak the object - input("\nObject will be saturated with water. Press ENTER to continue.") + if not short_exec: + input("\nObject will be saturated with water. Press ENTER to continue.") obj.states[object_states.Saturated].set_value(env.scene.get_system("water"), True) report_states() # Notify user that we're about to unsoak the object, and then unsoak the object - input("\nObject will be unsaturated with water. Press ENTER to continue.") + if not short_exec: + input("\nObject will be unsaturated with water. Press ENTER to continue.") obj.states[object_states.Saturated].set_value(env.scene.get_system("water"), False) report_states() # Close environment at the end - input("Demo completed. Press ENTER to shutdown environment.") + if not short_exec: + input("Demo completed. Press ENTER to shutdown environment.") env.close() diff --git a/omnigibson/examples/object_states/overlaid_demo.py b/omnigibson/examples/object_states/overlaid_demo.py index 6d8116acb..a28ea7327 100644 --- a/omnigibson/examples/object_states/overlaid_demo.py +++ b/omnigibson/examples/object_states/overlaid_demo.py @@ -68,6 +68,7 @@ def main(random_selection=False, headless=False, short_exec=False): while steps != max_steps: print(f"Overlaid {carpet.states[Overlaid].get_value(breakfast_table)} ", end="\r") env.step(th.empty(0)) + steps += 1 # Shut down env at the end env.close() diff --git a/omnigibson/examples/objects/draw_bounding_box.py b/omnigibson/examples/objects/draw_bounding_box.py index 4bb7a86e5..518181213 100644 --- a/omnigibson/examples/objects/draw_bounding_box.py +++ b/omnigibson/examples/objects/draw_bounding_box.py @@ -76,7 +76,9 @@ def main(random_selection=False, headless=False, short_exec=False): if "3d" not in bbox_modality: from omnigibson.utils.deprecated_utils import colorize_bboxes - colorized_img = colorize_bboxes(bboxes_2d_data=obs[bbox_modality], bboxes_2d_rgb=obs["rgb"], num_channels=4) + colorized_img = colorize_bboxes( + bboxes_2d_data=obs[bbox_modality], bboxes_2d_rgb=obs["rgb"].cpu().numpy(), num_channels=4 + ) fpath = f"{bbox_modality}_img.png" plt.imsave(fpath, colorized_img) og.log.info(f"Saving modality [{bbox_modality}] image to: {fpath}") diff --git a/omnigibson/objects/object_base.py b/omnigibson/objects/object_base.py index 83ebf8a27..4d4749ab5 100644 --- a/omnigibson/objects/object_base.py +++ b/omnigibson/objects/object_base.py @@ -327,7 +327,7 @@ class BaseObject(EntityPrim, Registerable, metaclass=ABCMeta): } material.enable_emission = True if enabled else self._highlight_cached_values[material]["enable_emission"] material.emissive_color = ( - m.HIGHLIGHT_RGB if enabled else self._highlight_cached_values[material]["emissive_color"] + m.HIGHLIGHT_RGB if enabled else self._highlight_cached_values[material]["emissive_color"].tolist() ) material.emissive_intensity = ( m.HIGHLIGHT_INTENSITY if enabled else self._highlight_cached_values[material]["emissive_intensity"] diff --git a/omnigibson/objects/primitive_object.py b/omnigibson/objects/primitive_object.py index 8c0618c5e..ff4b7d379 100644 --- a/omnigibson/objects/primitive_object.py +++ b/omnigibson/objects/primitive_object.py @@ -184,7 +184,11 @@ class PrimitiveObject(StatefulObject): raise ValueError("Prim type must either be PrimType.RIGID or PrimType.CLOTH for loading a primitive object") visual_geom_prim.color = self._load_config["color"] - visual_geom_prim.opacity = self._load_config["opacity"].item() + visual_geom_prim.opacity = ( + self._load_config["opacity"].item() + if isinstance(self._load_config["opacity"], th.Tensor) + else self._load_config["opacity"] + ) @property def radius(self): @@ -326,10 +330,13 @@ class PrimitiveObject(StatefulObject): for attr in (geom.GetPointsAttr(), geom.GetNormalsAttr()): # Scale all three axes by the scaling factor vals = th.tensor(attr.Get()).double() * scaling_factor - attr.Set(lazy.pxr.Vt.Vec3fArray([lazy.pxr.Gf.Vec3f(*v) for v in vals])) + attr.Set(lazy.pxr.Vt.Vec3fArray([lazy.pxr.Gf.Vec3f(*v.tolist()) for v in vals])) geom.GetExtentAttr().Set( lazy.pxr.Vt.Vec3fArray( - [lazy.pxr.Gf.Vec3f(*(-self._extents / 2.0)), lazy.pxr.Gf.Vec3f(*(self._extents / 2.0))] + [ + lazy.pxr.Gf.Vec3f(*(-self._extents / 2.0).tolist()), + lazy.pxr.Gf.Vec3f(*(self._extents / 2.0).tolist()), + ] ) ) diff --git a/omnigibson/sensors/vision_sensor.py b/omnigibson/sensors/vision_sensor.py index b1a5e287d..96f952ef6 100644 --- a/omnigibson/sensors/vision_sensor.py +++ b/omnigibson/sensors/vision_sensor.py @@ -294,7 +294,8 @@ class VisionSensor(BaseSensor): # All segmentation modalities return uint32 warp arrays, but PyTorch doesn't support it if modality in ["seg_semantic", "seg_instance", "seg_instance_id"]: obs[modality] = obs[modality].view(lazy.warp.int32) - obs[modality] = lazy.warp.to_torch(obs[modality]) + if not modality in ["bbox_2d_tight", "bbox_2d_loose", "bbox_3d"]: + obs[modality] = lazy.warp.to_torch(obs[modality]) if modality == "seg_semantic": id_to_labels = raw_obs["info"]["idToLabels"] obs[modality], info[modality] = self._remap_semantic_segmentation(obs[modality], id_to_labels) @@ -341,7 +342,7 @@ class VisionSensor(BaseSensor): replicator_mapping[key] = categories[0] assert ( - replicator_mapping[key] in semantic_class_id_to_name(self._scene).values() + replicator_mapping[key] in semantic_class_id_to_name().values() ), f"Class {val['class']} does not exist in the semantic class name to id mapping!" image_keys = th.unique(img) @@ -349,9 +350,7 @@ class VisionSensor(BaseSensor): set(replicator_mapping.keys()) ), "Semantic segmentation image does not match the original id_to_labels mapping." - return VisionSensor.SEMANTIC_REMAPPER.remap( - replicator_mapping, semantic_class_id_to_name(self._scene), img, image_keys - ) + return VisionSensor.SEMANTIC_REMAPPER.remap(replicator_mapping, semantic_class_id_to_name(), img, image_keys) def _remap_instance_segmentation(self, img, id_to_labels, semantic_img, semantic_labels, id=False): """ diff --git a/omnigibson/utils/asset_utils.py b/omnigibson/utils/asset_utils.py index 58d4a25a6..94c1accf2 100644 --- a/omnigibson/utils/asset_utils.py +++ b/omnigibson/utils/asset_utils.py @@ -163,6 +163,7 @@ def get_all_system_categories(): og_categories_path = os.path.join(og_dataset_path, "systems") categories = [f for f in os.listdir(og_categories_path) if not is_dot_file(f)] + categories.append("cloth") return sorted(categories) diff --git a/omnigibson/utils/constants.py b/omnigibson/utils/constants.py index c76e54745..c9bdb7c64 100644 --- a/omnigibson/utils/constants.py +++ b/omnigibson/utils/constants.py @@ -11,7 +11,7 @@ import torch as th import omnigibson as og from omnigibson.macros import gm -from omnigibson.utils.asset_utils import get_all_object_categories, get_og_avg_category_specs +from omnigibson.utils.asset_utils import get_all_object_categories, get_all_system_categories MAX_INSTANCE_COUNT = th.iinfo(th.int32).max MAX_CLASS_COUNT = th.iinfo(th.int32).max @@ -170,7 +170,7 @@ UNDER_OBJECTS = [ @cache -def semantic_class_name_to_id(scene): +def semantic_class_name_to_id(): """ Get mapping from semantic class name to class id @@ -178,8 +178,8 @@ def semantic_class_name_to_id(scene): dict: class name to class id """ categories = get_all_object_categories() + systems = get_all_system_categories() - systems = sorted(scene.system_registry.object_names) all_semantics = sorted(set(categories + systems + ["background", "unlabelled", "object", "light", "agent"])) # Assign a unique class id to each class name with hashing, the upper limit here is the max of int32 @@ -189,11 +189,11 @@ def semantic_class_name_to_id(scene): @cache -def semantic_class_id_to_name(scene): +def semantic_class_id_to_name(): """ Get mapping from semantic class id to class name Returns: dict: class id to class name """ - return {v: k for k, v in semantic_class_name_to_id(scene).items()} + return {v: k for k, v in semantic_class_name_to_id().items()} diff --git a/omnigibson/utils/deprecated_utils.py b/omnigibson/utils/deprecated_utils.py index 663ade90f..bda08cf71 100644 --- a/omnigibson/utils/deprecated_utils.py +++ b/omnigibson/utils/deprecated_utils.py @@ -10,6 +10,7 @@ import omni import omni.graph.core as ogc import omni.timeline import omni.usd as ou +import numpy as np import torch import torch as th import warp as wp @@ -681,10 +682,10 @@ def colorize_bboxes(bboxes_2d_data, bboxes_2d_rgb, num_channels=3): for bbox_2d in bboxes_2d_data: semantic_id_list.append(bbox_2d["semanticId"]) bbox_2d_list.append(bbox_2d) - semantic_id_list_np = th.unique(th.tensor(semantic_id_list)) + semantic_id_list_np = np.unique(np.array(semantic_id_list)) color_list = random_colours(len(semantic_id_list_np.tolist()), True, num_channels) for bbox_2d in bbox_2d_list: - index = th.where(semantic_id_list_np == bbox_2d["semanticId"])[0][0] + index = np.where(semantic_id_list_np == bbox_2d["semanticId"])[0][0] bbox_color = color_list[index] outline = (bbox_color[0], bbox_color[1], bbox_color[2]) if num_channels == 4: @@ -697,5 +698,5 @@ def colorize_bboxes(bboxes_2d_data, bboxes_2d_rgb, num_channels=3): rgb_img_draw.rectangle( [(bbox_2d["x_min"], bbox_2d["y_min"]), (bbox_2d["x_max"], bbox_2d["y_max"])], outline=outline, width=2 ) - bboxes_2d_rgb = th.tensor(rgb_img) + bboxes_2d_rgb = np.array(rgb_img) return bboxes_2d_rgb diff --git a/omnigibson/utils/vision_utils.py b/omnigibson/utils/vision_utils.py index d2307ffb1..34a3bc231 100644 --- a/omnigibson/utils/vision_utils.py +++ b/omnigibson/utils/vision_utils.py @@ -153,7 +153,7 @@ class Remapper: f"We do not have semantic information about bounding box semantic id {semantic_id} yet. Marking as unlabelled." ) self.warning_printed.add(semantic_id) - return semantic_class_name_to_id(scene)["unlabelled"] + return semantic_class_name_to_id()["unlabelled"] return self.key_array[semantic_id] diff --git a/tests/create_tests_of_examples.py b/tests/create_tests_of_examples.py index fdbb250e8..e2d7fc438 100644 --- a/tests/create_tests_of_examples.py +++ b/tests/create_tests_of_examples.py @@ -17,7 +17,10 @@ EXAMPLES_TO_SKIP = [ "learning.navigation_policy_demo", "teleoperation.robot_teleoperate_demo", # TODO: Temporarily skip the following examples - "robots.all_robots_visualizer", + "robots.all_robots_visualizer", # waiting for base link bug to be fixed + "object_states.attachment_demo", # seg fualt?? + "environments.behavior_env_demo", # This only works with pre-sampled cached BEHAVIOR activity scene + "robots.advanced.ik_example", # waiting for base link bug to be fixed; Fetch is fix base in this example ]