Git Product home page Git Product logo

hietalajulius / dynamic-cloth-folding Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 4.0 281.74 MB

Code for our paper: Learning Visual Feedback Control for Dynamic Cloth Folding (IROS 2022)

Home Page: https://sites.google.com/view/dynamic-cloth-folding/home

License: MIT License

Python 26.60% Shell 0.14% CMake 6.32% C++ 66.93% C 0.01%
computer-vision franka-emika gym machine-learning python pytorch realsense robotics ros

dynamic-cloth-folding's Introduction

Learning Visual Feedback Control for Dynamic Cloth Folding (IROS 2022)

The above gif has been slowed down to highlight the cloth dynamics, full speed videos can be found [here](https://sites.google.com/view/dynamic-cloth-folding/home)

The above gif has been slowed down to highlight the cloth dynamics, full speed videos can be found at https://sites.google.com/view/dynamic-cloth-folding/home

Introduction

This repository contains code and instructions on how to run the simulation training presented in our paper Learning Visual Feedback Control for Dynamic Cloth Folding published at 2022 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS 2022).

The setup has been tested on Ubuntu 22.04.1 LTS with Asus ROG Strix G513IE_G513IE (GeForce RTX 3050 Ti Mobile, Driver Version: 510.85.02, CUDA Version: 11.6).

Please contact the authors for instructions on how to run trained policies in the real world (our real-world setup included the Franka Emika Panda and Intel Realsense D435, but other robots and sensors can also be used).

Installation

  • Run conda create -n dynamic-cloth-folding python=3.8.13 && conda activate dynamic-cloth-folding to create and activate a new python environment (conda is not a strict requirement)
  • Run git clone [email protected]:hietalajulius/dynamic-cloth-folding.git --recursive to clone the repository and necessary submodules
  • Install MuJoCo using these instructions (i.e. extract the downloaded mujoco210 directory into ~/.mujoco/mujoco210)
  • Run cd dynamic-cloth-folding && ./install-dependencies.sh to install all required dependencies (assumes CUDA 11.6 and a compatible Nvidia GPU)

Training a model

The gif shows the RL simulation environment. It is implemented using MuJoCo and OpenAI Gym

  • Run source env.sh before each training to set proper environment variables
  • Run python train.py <--kwarg value> for a full training

Each training run will create a new directory in the trainings directory that contains

  • The current neural network weights
  • The settings used for the run
  • The git commit hashes of the submodules
  • The compiled MuJoCo models used during training
  • The evaluation policy and images captured during evaluation for each epoch

Training progress and metrics can be visualized using tensorboard by running tensorboard --logdir tblogs in the root of the repository and opening http://localhost:6006/ in your browser.

Settings

The different settings are passed to the training script as keyword arguments. The available settings are:

General

Kwarg Type Default value Description
--title String default Give a title to the training run, used in filenames when saving progress.
--run Int 0 Run number, used to generate random seeds. Useful when running multiple experiments with the same setup.
--num-processes Int 1 How many python multiprocesses/parallel RL environments to use when collecting experience for the training.

Environment

The environment consists of a Franka Emika Panda robot (agent) and a cloth model lying on a flat surface. Visual feedback is captured using a camera whose settings are tuned to approximately match the Realsense D435 camera.

Kwarg Type Default value Description
--cloth-size Float 0.2 The cloth size in meters
--robot-observation Choice[ee, ctrl, none] ctrl Whether the policy/value functions should observe the true end effector position (ee) or the current desired position of the controller (ctrl) or none
--filter Float 0.03 The filter value to use in the convex combination interpolation of the controller desired position between time steps
--output-max Float 0.03 The maximum Cartesian displacement in any direction of the previous controller desired position between time steps i.e. the maximum action from the policy
--damping-ratio Float 1.0 The damping ratio of the OSC controller
--kp Float 1000.0 Controller position gain
--success-distance Float 0.05 The minimum distance within which the considered cloth points should be from their goals for the task to be considered successful
--frame-stack-size Int 1 How many consecutive frames should be stacked together in the observation
--sparse-dense Int (1=true, 0=false) 1 Whether the reward should increase linearly with the error if the task is considered successful
--success-reward Int 0 The reward at a time step when the task is considered successful
--fail-reward Int -1 The reward at a time step when the task is considered unsuccessful
--extra-reward Int 1 When using a sparse dense reward, the maximum extra reward that can be achieved
--timestep Float 0.01 Simulation timestep length
--control-frequency Int 10 Control frequency (Hz)
--camera-type Choice[up, side, front, all] side The camera angle to use during training
--camera-config Choice[small, large] small Defines the camera fovy range to use. small corresponds to a 848x100 image on the real camera whereas large corresponds to a 848x480 image on the real camera.

Domain randomization

Kwarg Type Default value Description
--goal-noise Float 0.03 The range within which the goal positions of the cloth points should be randomized
--image-obs-noise-mean Float 0.5 The mean of the gaussian defining what the delay is between taking an action and observing an image within a [0,1] timespan between actions
--image-obs-noise-std Float 0.5 The std of the gaussian defining what the delay is between taking an action and observing an image within a [0,1] timespan between actions
--lights-randomization Int (1=true, 0=false) 1 Whether lights in the environment should be randomized
--materials-randomization Int (1=true, 0=false) 1 Whether the visual cloth material properties in the environment should be randomized
--camera-position-randomization Int (1=true, 0=false) 1 Whether the camera position in the environment should be randomized
--lookat-position-randomization-radius Float 0.03 Within what radius in meters should the camera lookat position be randomized from the center of the cloth
--lookat-position-randomization Int (1=true, 0=false) 1 Whether the lookat position should be randomized
--albumentations-randomization Int (1=true, 0=false) 1 Whether the albumentations library should be used to randomly blur and adjust colors of the image observations
--dynamics-randomization Int (1=true, 0=false) 1 Whether the cloth dynamics should be randomized
--fovy-perturbation-size Float 0.05 The max percentage that the camera fovy should be randomized
--rotation-perturbation-size Float 0.75 The max percentage that the camera rotation should be randomized
--position-perturbation-size Float 0.2 The max percentage that the camera position should be randomized

Training

The training is structured as follows: one epoch consists of n_cycles cycles. A cycle consists of n_steps. A step means a single step in the RL environment, but also a single gradient update of the model.

Kwarg Type Default value Description
--train-steps Int 1000 How many steps should be performed per a single cycle
--num-cycles Int 20 How many cycles should be performed per a single epoch
--num-epochs Int 100 How many epochs to run for
--save-policy-every-epoch Int 1 How often should the policy be saved during training
--num-eval-rollouts Int 20 How many evaluation rollouts (until success or --max-path-length environment steps per rollout) to perform after each epoch
--batch-size Int 256 The batch size to use during training the policy network
--discount Float 0.99 The discount factor in the RL problem
--corner-prediction-loss-coef Float 0.001 The weight of the cloth corner predction loss when updating gradients
--save-images-every-epoch Int 10 How often should evaluation images from the RL environment be saveed during training
--fc-layer-size Int 512 The fully-connected layer size to use in the policy and value networks
--fc-layer-depth Int 5 The fully-connected layer depth to use in the policy and value networks
--her-percent Float 0.8 Percentage of training samples whose goal should be recalculated using HER
--buffer-size Int 100000 The maximum number of steps to store in the replay buffer
--num-demoers Int 0 How many of the parallel RL environments should use an agent only executing a demonstration with added noise
--max-path-length Int 50 The maximum number of steps the agent can take in the environment before it resets
--max-close-steps Int 10 The maximum number of steps the task can be considered successful before the environment resets

Misc

  • The ./data folder contains a file demos.csv that is the real-world demonstration that is used along with random noise during training
  • The ./data folder also contains a file model_params.csv that contains the cloth dynamics parameters that are used during dynamics randomization

dynamic-cloth-folding's People

Contributors

hietalajulius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dynamic-cloth-folding's Issues

Segmentation fault (core dumped)

When I was running the training code, the following error occurred,may I ask how to solve this

python train.py

Training with GPU
Created progress directory to: /remote-home/2210975/cloth/dynamic-cloth-folding/trainings/default-run-0
Popen(['git', 'init'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding/submodules/mujoco-py, universal_newlines=False, shell=None, istream=None)
Popen(['git', 'cat-file', '--batch-check'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding/submodules/mujoco-py, universal_newlines=False, shell=None, istream=)
Popen(['git', 'cat-file', '--batch'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding/submodules/mujoco-py, universal_newlines=False, shell=None, istream=)
Popen(['git', 'init'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding/submodules/rlkit, universal_newlines=False, shell=None, istream=None)
Popen(['git', 'cat-file', '--batch-check'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding/submodules/rlkit, universal_newlines=False, shell=None, istream=)
Popen(['git', 'cat-file', '--batch'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding/submodules/rlkit, universal_newlines=False, shell=None, istream=)
Popen(['git', 'init'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding/submodules/robosuite, universal_newlines=False, shell=None, istream=None)
Popen(['git', 'cat-file', '--batch-check'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding/submodules/robosuite, universal_newlines=False, shell=None, istream=)
Popen(['git', 'cat-file', '--batch'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding/submodules/robosuite, universal_newlines=False, shell=None, istream=)
Popen(['git', 'init'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding, universal_newlines=False, shell=None, istream=None)
Popen(['git', 'cat-file', '--batch-check'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding, universal_newlines=False, shell=None, istream=)
Popen(['git', 'cat-file', '--batch'], cwd=/remote-home/2210975/cloth/dynamic-cloth-folding, universal_newlines=False, shell=None, istream=)
2023-06-13 02:32:10.319252 UTC | Variant:
2023-06-13 02:32:10.320003 UTC | {
"algorithm": "SAC",
"title": "default-run-0",
"save_folder": "/remote-home/2210975/cloth/dynamic-cloth-folding/trainings/default-run-0",
"random_seed": 0,
"randomization_kwargs": {
"lights_randomization": true,
"materials_randomization": true,
"camera_position_randomization": true,
"lookat_position_randomization": true,
"lookat_position_randomization_radius": 0.03,
"dynamics_randomization": true,
"albumentations_randomization": true,
"cloth_size": 0.2,
"camera_type": "side",
"camera_config": {
"type": "small",
"fovy_range": [
13,
15
],
"height": 100,
"width": 848
},
"position_perturbation_size": 0.2,
"rotation_perturbation_size": 0.75,
"fovy_perturbation_size": 0.05
},
"value_function_kwargs": {
"fc_layer_size": 512,
"fc_layer_depth": 5
},
"policy_kwargs": {
"input_width": 100,
"input_height": 100,
"input_channels": 1,
"kernel_sizes": [
3,
3,
3,
3
],
"n_channels": [
32,
32,
32,
32
],
"strides": [
2,
2,
2,
2
],
"paddings": [
0,
0,
0,
0
],
"hidden_sizes_aux": [
256,
8
],
"hidden_sizes_main": [
256,
256,
256,
256
],
"init_w": 0.0001,
"aux_output_size": 9
},
"env_kwargs": {
"save_folder": "/remote-home/2210975/cloth/dynamic-cloth-folding/trainings/default-run-0",
"timestep": 0.01,
"success_distance": 0.05,
"robot_observation": "ctrl",
"control_frequency": 10,
"ctrl_filter": 0.03,
"kp": 1000.0,
"frame_stack_size": 1,
"damping_ratio": 1,
"success_reward": 0,
"fail_reward": -1,
"extra_reward": 1,
"output_max": 0.03,
"max_close_steps": 10,
"sparse_dense": true,
"goal_noise_range": [
0.0,
0.03
],
"image_obs_noise_mean": 0.5,
"image_obs_noise_std": 0.5,
"model_kwargs_path": "./data/model_params.csv"
},
"eval_kwargs": {
"save_images_every_epoch": 10,
"num_runs": 20,
"max_path_length": 50,
"additional_keys": "['robot_observation']",
"frame_stack_size": 1,
"save_blurred_images": true,
"save_folder": "/remote-home/2210975/cloth/dynamic-cloth-folding/trainings/default-run-0"
},
"algorithm_kwargs": {
"num_epochs": 100,
"num_trains_per_train_loop": 1000,
"num_expl_steps_per_train_loop": 1000,
"num_train_loops_per_epoch": 20,
"max_path_length": 50,
"save_policy_every_epoch": 1,
"batch_size": 256,
"num_demoers": 0,
"save_folder": "/remote-home/2210975/cloth/dynamic-cloth-folding/trainings/default-run-0"
},
"path_collector_kwargs": {
"additional_keys": "['robot_observation']",
"demo_paths": "['./data/demos.csv']",
"demo_divider": 0.03,
"num_processes": 1
},
"replay_buffer_kwargs": {
"max_size": 100000,
"fraction_goals_rollout_goals": 0.19999999999999996,
"internal_keys": "['image', 'robot_observation']"
},
"trainer_kwargs": {
"discount": 0.99,
"soft_target_tau": 0.005,
"target_update_period": 1,
"policy_lr": 0.0003,
"qf_lr": 0.0003,
"reward_scale": 1,
"use_automatic_entropy_tuning": true,
"corner_prediction_loss_coef": 0.001
}
}
Training started
Segmentation fault (core dumped)

Issue with git cloning and installing dependencies..

upon running this command 'git clone [email protected]:hietalajulius/dynamic-cloth-folding.git --recursive' it says

Cloning into 'dynamic-cloth-folding'...
Warning: Permanently added the ECDSA host key for IP address '140.82.114.3' to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
...

Problem2:
If I download the package manually, and run 'cd dynamic-cloth-folding && ./install-dependencies.sh'

it gives the following errors...

a.
Successfully installed dynamic-cloth-folding-0.2.1.dev0
~/dynamic-cloth-folding/submodules/mujoco-py ~/dynamic-cloth-folding
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
ERROR: Directory '.' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.

b.
~/dynamic-cloth-folding/submodules/robosuite ~/dynamic-cloth-folding
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements-extra.txt'

c.
Obtaining file:///home/pratik/dynamic-cloth-folding/submodules/robosuite
ERROR: file:///home/pratik/dynamic-cloth-folding/submodules/robosuite does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.

d. ~/dynamic-cloth-folding/submodules/rlkit ~/dynamic-cloth-folding
Obtaining file:///home/pratik/dynamic-cloth-folding/submodules/rlkit
ERROR: file:///home/pratik/dynamic-cloth-folding/submodules/rlkit does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.

e.
Obtaining file:///home/pratik/dynamic-cloth-folding/osc-controller-binding
Preparing metadata (setup.py) ... done
Installing collected packages: osc-binding
Running setup.py develop for osc-binding
error: subprocess-exited-with-error

× python setup.py develop did not run successfully.
│ exit code: 1
╰─> [81 lines of output]

f.
note: This error originates from a subprocess, and is likely not a problem with pip.
~/dynamic-cloth-folding

any help is appreciated.

Real world experiments

Hi,

thanks for sharing!

I would like to try your method with a franka panda, could you give more details w.r.t the setup?

Also, I am wandering wether the pre-trained cpkt will be available.

Bests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.