Skip to content

Commit 022e785

Browse files
committed
[update] better readme for release
1 parent b321ec5 commit 022e785

11 files changed

+286
-167
lines changed

README.md

+70-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,86 @@
1-
## Install
1+
# DexPoint: Generalizable Point Cloud Reinforcement Learning for
2+
3+
Sim-to-Real Dexterous Manipulation
4+
5+
[[Project Page]](https://yzqin.github.io/dexpoint/) [[Paper]](https://arxiv.org/abs/2211.09423) [[Poster]](https://docs.google.com/presentation/d/1dDtAPQ49k1emhETRPAib5R0wCGdwlz5l/edit?usp=sharing&ouid=108317450590466198031&rtpof=true&sd=true)
6+
-----
7+
8+
[DexPoint: Generalizable Point Cloud Reinforcement Learning for
9+
Sim-to-Real Dexterous Manipulation ](https://yzqin.github.io/dexpoint/)
10+
11+
Yuzhe Qin*, Binghao Huang*, Zhao-Heng Yin, Hao Su, Xiaolong Wang, CoRL 2022.
12+
13+
DexPoint is a novel system and algorithm for RL from point cloud. This repo contains the simulated environment and
14+
training code for DexPoint.
15+
16+
![Teaser](docs/teaser.png)
17+
18+
## Bibtex
19+
20+
```
21+
@article{dexpoint,
22+
title = {DexPoint: Generalizable Point Cloud Reinforcement Learning for Sim-to-Real Dexterous Manipulation },
23+
author = {Qin, Yuzhe and Huang, Binghao and Yin, Zhao-Heng and Su, Hao and Wang, Xiaolong},
24+
journal = {Conference on Robot Learning (CoRL)},
25+
year = {2022},
26+
}
27+
```
28+
29+
## Installation
230

331
```shell
4-
# Install SAPIEN dev version, example for 3.8, you can choose a different whl file for 3.7, 3.9, 3.10
5-
pip3 install sapien>=2.1.0
32+
git clone [email protected]:yzqin/dexpoint-release.git
33+
cd dexart-release
34+
conda create --name dexpoint python=3.8
35+
conda activate dexpoint
36+
pip install -e .
637
```
738

8-
Download data file for hand detector and scene
39+
Download data file for the scene
940
from [Google Drive Link](https://drive.google.com/file/d/1Xe3jgcIUZm_8yaFUsHnO7WJWr8cV41fE/view?usp=sharing).
1041
Place the `day.ktx` at `assets/misc/ktx/day.ktx`.
1142

1243
```shell
44+
pip install gdown
1345
gdown https://drive.google.com/uc?id=1Xe3jgcIUZm_8yaFUsHnO7WJWr8cV41fE
1446
```
1547

1648
## File Structure
1749

18-
- `hand_teleop`: main entry for the environment, utils, and other staff needs for teleoperation and RL training.
50+
- `dexpoint`: main content for the environment, utils, and other staff needs for RL training.
1951
- `assets`: robot and object models, and other static files
20-
- `main`: entry files
52+
- `example`: entry files to learn how to use the DexPoint environment
53+
- `docker`: dockerfile that can create container to be used for headless training on server
54+
55+
## Quick Start
56+
57+
### Use DexPoint environment and extend it for your project
58+
59+
Run and explore the comments in the file below provided to familiarize yourself with the basic architecture of the
60+
DexPoint environment. Check the printed messages to understand the observation, action, camera, and speed for these
61+
environments.
62+
63+
- [state_only_env.py](example/example_use_state_only_env.py): minimal state only environment
64+
- [example_use_pc_env.py](example/example_use_pc_env.py): minimal point cloud environment
65+
- [example_use_imagination_env.py](example/example_use_imagination_env.py): point cloud environment with imagined point
66+
proposed
67+
in DexPoint
68+
- [example_use_multi_camera_visual_env.py](example/example_use_multi_camera_visual_env.py): environment with multiple
69+
different visual modalities, including depth, rgb, segmentation. We provide it for your reference, although it is not
70+
used in DexPoint
71+
72+
The environment we used in the training of DexPoint paper can be found here
73+
in [example_dexpoint_grasping.py](example/example_dexpoint_grasping.py).
74+
75+
### Example extension of DexPoint environment framework in other project
76+
77+
[DexArt: Benchmarking Generalizable Dexterous Manipulation with Articulated Objects (CVPR 2023)](https://github.com/Kami-code/dexart-release):
78+
extend DexPoint to articulated object manipulation.
79+
80+
[From One Hand to Multiple Hands: Imitation Learning for Dexterous Manipulation from Single-Camera Teleoperation (RA-L 2022)](https://yzqin.github.io/dex-teleop-imitation/):
81+
use teleoperation for data collection in DexPoint environment.
82+
83+
84+
2185

22-
## How to use
2386

24-
Play with the `runnable` files inside the `main` directory. It provides an example of how to use PointCloud and Imaged
25-
Point Cloud in your environment.

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ RUN apt-get update -q \
2424
# Install python package
2525
ENV LANG C.UTF-8
2626
RUN pip3 install gym open3d scipy opencv-python numpy nlopt scipy transforms3d imageio nvitop setuptools opencv-contrib-python tensorboard moviepy h5py --upgrade
27-
RUN pip3 install https://storage1.ucsd.edu/wheels/sapien-dev/sapien-2.0.0.dev20220531-cp38-cp38-manylinux2014_x86_64.whl
27+
RUN pip3 install sapien==2.1.0
2828
RUN pip3 install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113

docs/teaser.png

3.61 MB
Loading

example/example_dexpoint_grasping.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os
2+
from time import time
3+
4+
import numpy as np
5+
6+
from dexpoint.env.rl_env.relocate_env import AllegroRelocateRLEnv
7+
from dexpoint.real_world import task_setting
8+
9+
if __name__ == '__main__':
10+
def create_env_fn():
11+
object_names = ["mustard_bottle", "tomato_soup_can", "potted_meat_can"]
12+
object_name = np.random.choice(object_names)
13+
rotation_reward_weight = 0 # whether to match the orientation of the goal pose
14+
use_visual_obs = True
15+
env_params = dict(object_name=object_name, rotation_reward_weight=rotation_reward_weight,
16+
randomness_scale=1, use_visual_obs=use_visual_obs, use_gui=False,
17+
no_rgb=True)
18+
19+
# If a computing device is provided, designate the rendering device.
20+
# On a multi-GPU machine, this sets the rendering GPU and RL training GPU to be the same,
21+
# based on "CUDA_VISIBLE_DEVICES".
22+
if "CUDA_VISIBLE_DEVICES" in os.environ:
23+
env_params["device"] = "cuda"
24+
environment = AllegroRelocateRLEnv(**env_params)
25+
26+
# Create camera
27+
environment.setup_camera_from_config(task_setting.CAMERA_CONFIG["relocate"])
28+
29+
# Specify observation
30+
environment.setup_visual_obs_config(task_setting.OBS_CONFIG["relocate_noise"])
31+
32+
# Specify imagination
33+
environment.setup_imagination_config(task_setting.IMG_CONFIG["relocate_robot_only"])
34+
return environment
35+
36+
37+
env = create_env_fn()
38+
print("Observation space:")
39+
print(env.observation_space)
40+
print("Action space:")
41+
print(env.action_space)
42+
43+
obs = env.reset()
44+
45+
tic = time()
46+
rl_steps = 1000
47+
for _ in range(rl_steps):
48+
action = np.zeros(env.action_space.shape)
49+
action[0] = 0.002 # Moving forward ee link in x-axis
50+
obs, reward, done, info = env.step(action)
51+
elapsed_time = time() - tic
52+
53+
simulation_steps = rl_steps * env.frame_skip
54+
print(f"Single process for point-cloud environment with {rl_steps} RL steps "
55+
f"(= {simulation_steps} simulation steps) takes {elapsed_time}s.")
56+
print("Keep in mind that using multiple processes during RL training can significantly increase the speed.")
57+
env.scene = None
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import os
2+
from time import time
3+
4+
import numpy as np
5+
import open3d as o3d
6+
7+
from dexpoint.env.rl_env.relocate_env import AllegroRelocateRLEnv
8+
from dexpoint.real_world import task_setting
9+
10+
if __name__ == '__main__':
11+
def create_env_fn():
12+
object_names = ["mustard_bottle", "tomato_soup_can", "potted_meat_can"]
13+
object_name = np.random.choice(object_names)
14+
rotation_reward_weight = 0 # whether to match the orientation of the goal pose
15+
use_visual_obs = True
16+
env_params = dict(object_name=object_name, rotation_reward_weight=rotation_reward_weight,
17+
randomness_scale=1, use_visual_obs=use_visual_obs, use_gui=False,
18+
no_rgb=True)
19+
20+
# If a computing device is provided, designate the rendering device.
21+
# On a multi-GPU machine, this sets the rendering GPU and RL training GPU to be the same,
22+
# based on "CUDA_VISIBLE_DEVICES".
23+
if "CUDA_VISIBLE_DEVICES" in os.environ:
24+
env_params["device"] = "cuda"
25+
environment = AllegroRelocateRLEnv(**env_params)
26+
27+
# Create camera
28+
environment.setup_camera_from_config(task_setting.CAMERA_CONFIG["relocate"])
29+
30+
# Specify observation
31+
environment.setup_visual_obs_config(task_setting.OBS_CONFIG["relocate_noise"])
32+
33+
# Specify imagination
34+
environment.setup_imagination_config(task_setting.IMG_CONFIG["relocate_goal_robot"])
35+
return environment
36+
37+
38+
env = create_env_fn()
39+
print("Observation space:")
40+
print(env.observation_space)
41+
print("Action space:")
42+
print(env.action_space)
43+
44+
obs = env.reset()
45+
print("For state task, observation is a numpy array. For visual tasks, observation is a python dict.")
46+
47+
print("Observation keys")
48+
print(obs.keys())
49+
50+
tic = time()
51+
rl_steps = 1000
52+
for _ in range(rl_steps):
53+
action = np.zeros(env.action_space.shape)
54+
action[0] = 0.002 # Moving forward ee link in x-axis
55+
obs, reward, done, info = env.step(action)
56+
elapsed_time = time() - tic
57+
58+
pc = obs["relocate-point_cloud"]
59+
# The name of the key in observation is "CAMERA_NAME"-"MODALITY_NAME".
60+
# While CAMERA_NAME is defined in task_setting.CAMERA_CONFIG["relocate"], name is point_cloud.
61+
# See example_use_multi_camera_visual_env.py for more modalities.
62+
63+
simulation_steps = rl_steps * env.frame_skip
64+
print(f"Single process for point-cloud environment with {rl_steps} RL steps "
65+
f"(= {simulation_steps} simulation steps) takes {elapsed_time}s.")
66+
print("Keep in mind that using multiple processes during RL training can significantly increase the speed.")
67+
env.scene = None
68+
69+
# Note that in the DexPoint paper, we never use "imagination_goal" but only "imagination_robot"
70+
goal_pc = obs["imagination_goal"]
71+
goal_robot = obs["imagination_robot"]
72+
imagination_goal_cloud = o3d.geometry.PointCloud(
73+
points=o3d.utility.Vector3dVector(goal_pc))
74+
imagination_goal_cloud.paint_uniform_color(np.array([0, 1, 0]))
75+
imagination_robot_cloud = o3d.geometry.PointCloud(
76+
points=o3d.utility.Vector3dVector(goal_robot))
77+
imagination_robot_cloud.paint_uniform_color(np.array([0, 0, 1]))
78+
79+
obs_cloud = o3d.geometry.PointCloud(points=o3d.utility.Vector3dVector(pc))
80+
obs_cloud.paint_uniform_color(np.array([1, 0, 0]))
81+
coordinate = o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.05, origin=[0, 0, 0])
82+
o3d.visualization.draw_geometries([imagination_goal_cloud, imagination_robot_cloud, coordinate, obs_cloud])
83+
84+
env.scene = None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
3+
import imageio
4+
import numpy as np
5+
from PIL import ImageColor
6+
7+
from dexpoint.env.rl_env.relocate_env import AllegroRelocateRLEnv
8+
9+
if __name__ == '__main__':
10+
def create_env_fn():
11+
object_names = ["mustard_bottle", "tomato_soup_can", "potted_meat_can"]
12+
object_name = np.random.choice(object_names)
13+
rotation_reward_weight = 0
14+
use_visual_obs = True
15+
env_params = dict(object_name=object_name, rotation_reward_weight=rotation_reward_weight,
16+
randomness_scale=1, use_visual_obs=use_visual_obs, use_gui=False, no_rgb=False)
17+
18+
# If a computing device is provided, designate the rendering device.
19+
# On a multi-GPU machine, this sets the rendering GPU and RL training GPU to be the same,
20+
# based on "CUDA_VISIBLE_DEVICES".
21+
if "CUDA_VISIBLE_DEVICES" in os.environ:
22+
env_params["device"] = "cuda"
23+
environment = AllegroRelocateRLEnv(**env_params)
24+
25+
# Create camera
26+
camera_cfg = {
27+
"cam1": dict(position=np.array([-0.4, 0.4, 0.6]), look_at_dir=np.array([0.4, -0.4, -0.6]),
28+
right_dir=np.array([-1, -1, 0]), fov=np.deg2rad(69.4), resolution=(256, 256)),
29+
"cam2": dict(position=np.array([-0.6, -0.3, 0.8]), look_at_dir=np.array([0.6, 0.3, -0.8]),
30+
right_dir=np.array([1, -2, 0]), fov=np.deg2rad(69.4), resolution=(256, 256))
31+
}
32+
environment.setup_camera_from_config(camera_cfg)
33+
34+
# Specify observation modality
35+
empty_info = {} # level empty dict for default observation setting
36+
obs_cfg = {"cam1": {"rgb": empty_info, "segmentation": empty_info},
37+
"cam2": {"depth": empty_info}}
38+
environment.setup_visual_obs_config(obs_cfg)
39+
return environment
40+
41+
42+
env = create_env_fn()
43+
print("Observation space:")
44+
print(env.observation_space)
45+
print("Action space:")
46+
print(env.action_space)
47+
48+
obs = env.reset()
49+
print("For state task, observation is a numpy array. For visual tasks, observation is a python dict.")
50+
51+
print("Observation keys")
52+
print(obs.keys())
53+
rgb = obs["cam1-rgb"]
54+
rgb_pic = (rgb * 255).astype(np.uint8)
55+
imageio.imsave("cam1-rgb.png", rgb_pic)
56+
57+
# Segmentation
58+
link_seg = obs["cam1-segmentation"][..., 0]
59+
part_seg = obs["cam1-segmentation"][..., 1]
60+
colormap = sorted(set(ImageColor.colormap.values()))
61+
color_palette = np.array([ImageColor.getrgb(color) for color in colormap], dtype=np.uint8)
62+
imageio.imsave("cam1-link_seg.png", color_palette[link_seg].astype(np.uint8))
63+
imageio.imsave("cam1-part_seg.png", color_palette[part_seg].astype(np.uint8))
64+
65+
# Depth normalization
66+
depth = obs["cam2-depth"] / 10 * 65535
67+
imageio.imwrite("cam2-depth.png", depth[..., 0].astype(np.uint16))
68+
69+
env.scene = None

main/example_use_pc_env.py example/example_use_pc_env.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ def create_env_fn():
4343

4444
print("Observation keys")
4545
print(obs.keys())
46-
# The name of the key in observation is "CAMERA_NAME"-"MODALITY_NAME".
47-
# While CAMERA_NAME is defined in task_setting.CAMERA_CONFIG["relocate"], name is point_cloud.
48-
# See example_use_multi_camera_visual_env.py for more modalities.
4946

5047
tic = time()
5148
rl_steps = 1000
5249
for _ in range(rl_steps):
5350
action = np.zeros(env.action_space.shape)
5451
action[0] = 0.002 # Moving forward ee link in x-axis
5552
obs, reward, done, info = env.step(action)
53+
elapsed_time = time() - tic
5654

5755
pc = obs["relocate-point_cloud"]
56+
# The name of the key in observation is "CAMERA_NAME"-"MODALITY_NAME".
57+
# While CAMERA_NAME is defined in task_setting.CAMERA_CONFIG["relocate"], name is point_cloud.
58+
# See example_use_multi_camera_visual_env.py for more modalities.
5859

59-
elapsed_time = time() - tic
6060
simulation_steps = rl_steps * env.frame_skip
6161
print(f"Single process for point-cloud environment with {rl_steps} RL steps "
6262
f"(= {simulation_steps} simulation steps) takes {elapsed_time}s.")
File renamed without changes.

0 commit comments

Comments
 (0)