From 227f6db3c0f99fd627c2961d7a5354f87c973825 Mon Sep 17 00:00:00 2001 From: cremebrule <84cremebrule@gmail.com> Date: Fri, 13 Sep 2024 15:40:07 -0700 Subject: [PATCH 1/4] update dependency versions, remove torchvision dep --- omnigibson/scene_graphs/graph_builder.py | 12 ++++-------- setup.py | 7 +++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/omnigibson/scene_graphs/graph_builder.py b/omnigibson/scene_graphs/graph_builder.py index 81d668309..311efd4d3 100644 --- a/omnigibson/scene_graphs/graph_builder.py +++ b/omnigibson/scene_graphs/graph_builder.py @@ -2,9 +2,9 @@ import networkx as nx import torch as th +import numpy as np from matplotlib import pyplot as plt from PIL import Image -from torchvision.transforms import ToPILImage, ToTensor from omnigibson import object_states from omnigibson.object_states.factory import get_state_name @@ -289,14 +289,10 @@ def _draw_graph(): robot_view = (robot_camera_sensor.get_obs()[0]["rgb"][..., :3]).to(th.uint8) imgheight, imgwidth, _ = robot_view.shape - pil_transform = ToPILImage() - torch_transform = ToTensor() - - # check imgheight and imgwidth; if they are too small, we need to upsample the image to 1280x1280 + # check imgheight and imgwidth; if they are too small, we need to upsample the image to 640x640 if imgheight < 640 or imgwidth < 640: - robot_view = torch_transform( - pil_transform((robot_view.permute(2, 0, 1).cpu())).resize((640, 640), Image.BILINEAR) - ).permute(1, 2, 0) + # Convert to PIL Image to upsample, then write back to tensor + robot_view = th.tensor(np.array(Image.fromarray(robot_view.cpu().numpy()).resize((640, 640), Image.BILINEAR)), dtype=th.uint8) imgheight, imgwidth, _ = robot_view.shape figheight = 4.8 diff --git a/setup.py b/setup.py index f69a32992..611bc4383 100644 --- a/setup.py +++ b/setup.py @@ -22,8 +22,8 @@ packages=find_packages(), install_requires=[ "gymnasium>=0.28.1", - "numpy~=1.23.5", - "scipy~=1.10.1", + "numpy~=1.26.4", + "scipy~=1.14.1", "GitPython~=3.1.40", "transforms3d~=0.4.1", "networkx~=3.2.1", @@ -35,7 +35,7 @@ "h5py~=3.10.0", "cryptography~=41.0.7", "bddl~=3.5.0", - "opencv-python~=4.8.1", + "opencv-python~=4.10.0", "nest_asyncio~=1.5.8", "imageio~=2.33.1", "imageio-ffmpeg~=0.4.9", @@ -47,7 +47,6 @@ "rtree~=1.2.0", "graphviz~=0.20", "numba~=0.60.0", - "torchvision~=0.18.1", ], extras_require={ "isaac": ["isaacsim-for-omnigibson>=4.1.0"], From 9ba2fafdd64bf1e432ff2e9b14129574ab25d87b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 22:43:48 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- omnigibson/scene_graphs/graph_builder.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/omnigibson/scene_graphs/graph_builder.py b/omnigibson/scene_graphs/graph_builder.py index 311efd4d3..7050909fa 100644 --- a/omnigibson/scene_graphs/graph_builder.py +++ b/omnigibson/scene_graphs/graph_builder.py @@ -1,8 +1,8 @@ import itertools import networkx as nx -import torch as th import numpy as np +import torch as th from matplotlib import pyplot as plt from PIL import Image @@ -292,7 +292,9 @@ def _draw_graph(): # check imgheight and imgwidth; if they are too small, we need to upsample the image to 640x640 if imgheight < 640 or imgwidth < 640: # Convert to PIL Image to upsample, then write back to tensor - robot_view = th.tensor(np.array(Image.fromarray(robot_view.cpu().numpy()).resize((640, 640), Image.BILINEAR)), dtype=th.uint8) + robot_view = th.tensor( + np.array(Image.fromarray(robot_view.cpu().numpy()).resize((640, 640), Image.BILINEAR)), dtype=th.uint8 + ) imgheight, imgwidth, _ = robot_view.shape figheight = 4.8 From f1e5b1978cb3ef2a01e4e318f5063a52ba0a8d38 Mon Sep 17 00:00:00 2001 From: cremebrule <84cremebrule@gmail.com> Date: Mon, 16 Sep 2024 12:33:48 -0700 Subject: [PATCH 3/4] update package dependencies for backwards compatibility --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 611bc4383..82eae318b 100644 --- a/setup.py +++ b/setup.py @@ -22,8 +22,8 @@ packages=find_packages(), install_requires=[ "gymnasium>=0.28.1", - "numpy~=1.26.4", - "scipy~=1.14.1", + "numpy>=1.23.5", + "scipy>=1.10.1", "GitPython~=3.1.40", "transforms3d~=0.4.1", "networkx~=3.2.1", @@ -35,7 +35,7 @@ "h5py~=3.10.0", "cryptography~=41.0.7", "bddl~=3.5.0", - "opencv-python~=4.10.0", + "opencv-python>=4.8.1", "nest_asyncio~=1.5.8", "imageio~=2.33.1", "imageio-ffmpeg~=0.4.9", @@ -46,7 +46,7 @@ "aenum~=3.1.15", "rtree~=1.2.0", "graphviz~=0.20", - "numba~=0.60.0", + "numba>=0.60.0", ], extras_require={ "isaac": ["isaacsim-for-omnigibson>=4.1.0"], From c74f696d9e84ce2c90f5fb48582f2afd3bf3e4e9 Mon Sep 17 00:00:00 2001 From: cremebrule <84cremebrule@gmail.com> Date: Mon, 16 Sep 2024 12:38:16 -0700 Subject: [PATCH 4/4] remove numpy dep in graph_builder.py --- omnigibson/scene_graphs/graph_builder.py | 6 ++---- omnigibson/utils/numpy_utils.py | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/omnigibson/scene_graphs/graph_builder.py b/omnigibson/scene_graphs/graph_builder.py index 7050909fa..1f987748c 100644 --- a/omnigibson/scene_graphs/graph_builder.py +++ b/omnigibson/scene_graphs/graph_builder.py @@ -1,7 +1,6 @@ import itertools import networkx as nx -import numpy as np import torch as th from matplotlib import pyplot as plt from PIL import Image @@ -12,6 +11,7 @@ from omnigibson.robots import BaseRobot from omnigibson.sensors import VisionSensor from omnigibson.utils import transform_utils as T +from omnigibson.utils.numpy_utils import pil_to_tensor def _formatted_aabb(obj): @@ -292,9 +292,7 @@ def _draw_graph(): # check imgheight and imgwidth; if they are too small, we need to upsample the image to 640x640 if imgheight < 640 or imgwidth < 640: # Convert to PIL Image to upsample, then write back to tensor - robot_view = th.tensor( - np.array(Image.fromarray(robot_view.cpu().numpy()).resize((640, 640), Image.BILINEAR)), dtype=th.uint8 - ) + robot_view = pil_to_tensor(Image.fromarray(robot_view.cpu().numpy()).resize((640, 640), Image.BILINEAR)) imgheight, imgwidth, _ = robot_view.shape figheight = 4.8 diff --git a/omnigibson/utils/numpy_utils.py b/omnigibson/utils/numpy_utils.py index 1d540c27b..fda0a3164 100644 --- a/omnigibson/utils/numpy_utils.py +++ b/omnigibson/utils/numpy_utils.py @@ -15,3 +15,7 @@ def vtarray_to_torch(vtarray, dtype=th.float32, device="cpu"): else: assert device.startswith("cuda") return th.tensor(np.array(vtarray), dtype=dtype, device=device) + + +def pil_to_tensor(pil_image): + return th.tensor(np.array(pil_image), dtype=th.uint8)