The official implementation of the paper "Diffusion Stabilizer Policy for Automated Surgical Robot Manipulations".
this repo implemented the training and evaluation of DSP in SurRoL, the surgical environment.
git clone --recursive https://github.com/Rappy325/DSP.git
cd DSPconda create -n dsp python=3.10 -y
conda activate dsppip install -e SurRoL/ # install surrol environments
pip install -e CleanDiffuser/
pip install -r requirements.txtInstall PyTorch 2.2.2 Following the Official Guideline using Conda.
For default, use the command:
pip3 install torch torchvision torchaudio# directory: anaconda3/envs/dsp/lib/python3.10/site-packages/
import surrol.gymThis repo provides pipelines for the two category of noise.
Dataset is generated by script, not manually collected. We use shell scripts to loop over SurRoL tasks and imperfect trajectory types, then calls data_generation.py to roll out oracle-policy demonstrations. The generated files are saved under datasets/demo/ (or datasets/video/ when video recording is enabled).
Action-level noise is injected during data generation/training in the corresponding training script. You can directly edit the script and run it.
To test the main result of DSP, run the following script:
bash scripts/training/train_action-level.shScripts for ablation studies are provided for reference as well.
train_action-level_noise_setups.shis for testing DSP on different noise strength and densitytrain_thresholds_action-level.shis for testing different thresholding method.
bash scripts/training/ablation/train_action-level_noise_setups.sh
bash scripts/training/ablation/train_thresholds_action-level.shTrajectory-level noise training requires you to run two scripts:
- Generate trajectory-level noisy datasets first.
- Run training using the generated datasets.
please edit the shell if you want to tweak the configurations.
Stage 1: dataset generation
To generate data, please run the following command.
bash scripts/training/traj-level_data_generate.sh- if you want to design and try out your own traj-level perturbation setup, the relevant files are being defined in the wrapper files in
dsp/surrol_wrappers/tasks. You might have to define your own trajectory-level imperfect type in there and do some testing.
Stage 2: training
bash scripts/training/train_traj-level.shSimularly, scripts for ablation studies for Trajectory-level noises are provided for reference as well.
bash scripts/training/ablation/train_thresholds_traj-level.shNotes:
- In trajectory-level generation, task-specific imperfect types are configured in
scripts/training/traj-level_data_generate.sh. - The imperfect type is passed from shell to SurRoL via environment variable (
TRAJ_IMPERFECT_TYPE), and SurRoL selects the corresponding waypoint pattern for each task. - Some imperfect types are configured in SurRoL to enforce success-only data collection automatically.
if you are only testing for the original diffusion policy, use train_clean.sh instead.
edit the parameters in scripts/training/train_clean.sh and run in terminal:
bash scripts/training/train_clean.shEvaluates the model's performance on the provided dataset and logs the evaluation metrics. The evaluation process includes calculating the success rates with five different seeds, which returns 5 success rates for calculating IQM. When you run the shell scripts below, log files containing the evaluation results will be saved in the 'logs/eval/' directory by default.
Evaluation is provided with the same two pipelines as training.
Edit the script and run:
bash scripts/evaluation/eval_action-level.shAblation scripts for action-level evaluation:
eval_action-level_noise_setups.shevaluates DSP on different action-level noise strength/density setups (e.g., different(sigma, noisy_steps)combinations).eval_thresholds_action-level.shevaluates different adaptive thresholding methods (otsu,k-means,logGMM,strict,loose, and normal-online baseline) under action-level noise.
bash scripts/evaluation/ablation/eval_action-level_noise_setups.sh
bash scripts/evaluation/ablation/eval_thresholds_action-level.shEdit the script and run:
bash scripts/evaluation/eval_traj-level.shAblation script for trajectory-level thresholding:
bash scripts/evaluation/ablation/eval_thresholds_traj-level.shif you are only testing for the original diffusion policy, use eval_clean.sh instead.
bash scripts/evaluation/eval_clean.shscript for figure 3 is provided as testFilter.sh in scripts/training/ablation. This is used to evaluate how the noisy-sample filter behaves during stage-2 online training. It loads stage-1 checkpoints and runs diffusion_trainer.py with --test_filter and --filter_noisy so you can measure filter-related metrics while training progresses, instead of only checking final task success. By looping over all six SurRoL tasks and multiple clean/noisy dataset combinations, it provides a consistent way to compare filter quality and stability across different environments and data scales.
Before running:
- make sure stage-1 checkpoints already exist for each
(env, clean_num, noisy_num)combination - make sure the corresponding datasets are available (the script uses noisy dataset names with
noise_02_10)
Run command:
bash scripts/training/ablation/testFilter.shThe script will call diffusion_trainer.py with --test_filter and save logs/checkpoints using the configured --msg naming pattern.
