Skip to content

Latest commit

 

History

35 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpaHybGen: Learning contact representations in real-world clutter for universal robotic grasping

SpaHybGen generates grasp poses for general robotic hands in SE(3) clutter scenes using learning and optimization strategies. It uses the real grasping dataset GraspNet-1Billion to train the inference section. SpaHybGen can directly and robustly deploy any robotic hand with its URDF to actual clutter grasping in minutes, using a single depth camera.

IMPORTANT: It is feasible to use your own robotic hands without Contact Dataset Generation and Contact Training. To immediately use your custom robotic hands, please directly refer to Pipeline: Grasp Generation (after setting the Code Environment).


Scene-Level Spatial Grasp Generation for General Robotic Hands

Maintain schemes

✅ Autmatic objective-scaling strategy to grasp optimization, replacing constant hand-tuned scales.
✅ Replaced absolute path and magic number.
✅ Polished contact assignment script.
✅ Broke down functions and formated for clarity.
✅ Added functional documentation and type hints.
✅ Added pytest-based modular test [Code Test section]

Code Environment

We use Python 3.8 in Conda to train 3D U-Net, infer contacts, and optimize grasps. All algorithmic procedures are coded in Pytorch and Pytorch_kinematics. Environment setup for the real-world deployment refers to the following Actual Grasping section.

  1. Create virtual env.:
conda create --name spahybgen python=3.8
conda activate spahybgen
  1. Install required packages with pip on virtual env or python3:
pip install -r ./assets/requirements.txt

export SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL=True # for sklearn package error
pip install graspnetAPI # for Graspnet Dataset
  1. Install the project locally in "editable" mode using pip:
pip install -e .

We understand that the setup of conda for GPU-based python packages can be tricky in varied machine and the above instruction may be insufficient for an error-free installation. Thus, we further share the specification of our installed env. in environment.yml for reference.

Code Test

To validate the code and environment, it is recommanded to run modular tests:

pip install pytest
cd spahybgen
pytest tests/ -v

Contact Dataset Generation

We release the generated contact dataset in Google Drive. It includes 4.5GB training data and 4.2GB test data.

If researchers expect to generate the contact dataset, please download the full GraspNet-1Billion dataset and run the following command:

cd spahybgen
python scripts/generate_dataset.py --graspnet PATH_TO_GraspNet --output ./dataset/train

It will take tens of hours for the generation process (currently we have not parallelized it).

Detailed descriptions of the contact generation process are presented in scripts/generate_dataset.py.

The contact dataset should be placed inside a dataset folder as: spahybgen\dataset\train\scene_0000.

Contact Training

After generating or downloading the Contact Dataset in the previous step, run command to train a 3D U-Net:

python scripts/train_shgn.py --dataset dataset/train/ --net unet --orientation quat --gridtype voxel --batch-size 4 --numsample 3000 --epochs 64 --loaders 10 --gridtype voxel

The training logs and models are stored at data/runs/.

To facilitate reproduction, two trained models are also shared in Google Drive and assets/trained_models/, which contains two networks oriented to Voxel and TSDF input observations.

Pipeline: Grasp Generation

The process of grasp generation includes 1.scene observation, 2.contact inference, 3.hand model and 4.grasp optimization.

1. Scene Observation

We enable two formats (Voxel and TSDF) as the scene observation in actual grasping tasks. To obtain observation, one can refer to the generated (downloaded) contact dataset in folder spahybgen/dataset/, where the .npz files are observations for grasping scenes in GraspNet-1Billion. Alternatively, practitioners capture scene volumes using a depth sensor, following the sensing pipeline at src/spahybgen/pipeline/sensor_server.py.

Two observation samples can be found in assets/observations/. You can load them with np.load('assets/observations/scene_010_ann_0124_voxel.npz')["grid"].

2. Contact Inference

With the trained model and obtained observation, dense contact features can be reasoned before grasp optimization.

Note: If you want to individually test the contact inference module, please run:

python scripts/contact_inference_test.py

It will infer contact features using the observation scene_010_ann_0124_voxel.npz and model spahybgen_unet_64_voxel.pt in folder assets/.

3. Hand Model

More than ten robotic hands are released in folder \handmodel. To construct a custom gripper in compatible format, please check these hand examples. Generally, one hand model can be generated within the following steps:

(1). Prepare the standard URDF file for the targeted robotic hand. The CAD filepath and xml encoding information in .urdf should be properly modified to match the code (for the targeted format, please refer to the released hand examples).

(2). Assign contact regions to the hand surface using the tool in scripts/hand_contacts.ipynb.

(3). Append information of the custom hand to file handmodel/hand_infos.json, following the included format.

4. Grasp Optimization

With the inferred contact features and established hand model, grasp optimization is parallelized using Pytorch_kinematics.

After running the contact inference script contact_inference_test.py in Step 2, the following cmd will optimize grasps using the specific hand and visualize the results using Web-based Plotly:

python scripts/grasp_optimization_test.py --hand robotiq2f --max_iter 120 --batch_size 64
# AVAILABLE HAND MODELS: 
# 2F: [robotiq2f, finray2f, antipodal_hand] 
# 3F: [robotiq3f, softpneu3f] 
# 4F: [finray4f, leaphand] 
# 5F: [brunel_hand]

Note: If you want to individually test the grasp optimization module, download the std_inference_result_from_clutter.npy from Google Drive to the folder ./assets, and rename it to inference_results.npy.

Full Pipeline

To run the full algorithmic pipeline without hardware (using the default observation file and trained model contained in folder assets/), please directly run:

python scripts/generation_pipeline_test.py --hand robotiq2f --max_iter 120 --batch_size 64

This script is a combination of 2. Contact Inference and 4. Grasp Optimization. Similarly, it will optimize grasps using Robotiq-2F and visualize the results using Web-based Plotly.

Actual Grasping

Used devices in actual grasping

To enable ROS1 in Python3, please follow Coding_Instruction to make import rospy and import tf2_ros working in python3.

Demonstration

1. Semi-cluttered grasping with seven robotic hands

2. Multi-gripper simultaneous grasping

3. Dynamic grasp update in dense clutter grasping

Cite

@article{wang2026learning,
  title={Learning contact representations in real-world clutter for universal robotic grasping},
  author={Wang, Xianli and Tam, Lap Mou and Xu, Qingsong},
  journal={Nature Machine Intelligence},
  year={2026},
  doi={https://doi.org/10.1038/s42256-026-01292-y},
  publisher={Nature Publishing Group UK London}
}

Acknowledge

This project is inspired by the excellent works VGN, GenDexGrasp, and GraspNetAPI.

About

SpaHybGen: Scene-Level Spatial Grasp Generation for General Robotic Hands (Nature Machine Intelligence, NMI)

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages