# dipn **Repository Path**: assets01/dipn ## Basic Information - **Project Name**: dipn - **Description**: No description available - **Primary Language**: Unknown - **License**: BSD-2-Clause - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-04 - **Last Updated**: 2021-10-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DIPN: Deep Interaction Prediction Network with Application to Clutter Removal We propose a Deep Interaction Prediction Network (DIPN) for learning to predict complex interactions that ensue as a robot end-effector pushes multiple objects, whose physical properties, including size, shape, mass, and friction coefficients may be unknown a priori. DIPN "imagines" the effect of a push action and generates an accurate synthetic image of the predicted outcome. DIPN is shown to be sample efficient when trained in simulation or with a real robotic system. The high accuracy of DIPN allows direct integration with a Grasp Network (GN), yielding a robotic manipulation system capable of executing challenging clutter removal tasks while being trained in a fully self-supervised manner. The overall network demonstrates intelligent behavior in selecting proper actions between push and grasp for completing clutter removal tasks and significantly outperforms the previous state-of-the-art [VPG](https://github.com/andyzeng/visual-pushing-grasping). **Videos:** [](http://www.youtube.com/watch?v=CNkZfZ-0Du8 "DIPN")
## Pre-train Grasp Network and Train Grasp Network in simulation
Switch to pytorch==1.5.1 and torchvision==0.6.1.
`random-pretrain` contains objects which have different shapes and colors to the final objects that will be trained and evaluted on.
`random-pretrain` could be replaced with `random-maskrcnn`, they are essentially collected in the same way.
You may need to restart the training several times, so the loss will go down to around 60.
```shell
python train_foreground.py --dataset_root 'logs/random-pretrain/data'
```
To use DIPN+GN, we just need to train Grasp Network in simulation.
```shell
python main.py --is_sim --grasp_only --experience_replay --explore_rate_decay --save_visualizations --load_snapshot --snapshot_file 'logs/random-pretrain/data/foreground_model.pth'
```
## Train DQN + GN
It will train DQN grasp and push in the same time, which is one of baseline in the paper.
```shell
python main.py --is_sim --push_rewards --experience_replay --explore_rate_decay --save_visualizations --load_snapshot --snapshot_file 'logs/random-pretrain/data/foreground_model.pth'
```
## Creating dataset
The dataset we used can be download from [Google Drive](https://drive.google.com/drive/folders/17X5aGr-50e6RqLkyyvG4mGHP_TUpz_kB?usp=sharing).
The Push prediction related files are located in `logs_push`
The Mask R-CNN, Grasp Network related files are located in `logs`
### collect_data.py
Collect push prediction data (only for sim now).
```shell
python collect_data.py --is_sim
```
### create_mask_rcnn_image.py
Collect dataset for Mask R-CNN and pre-training, `--is_mask` collects data for Mask R-CNN.
You need to drag the `Box` object to the center in CoppeliaSim.
```shell
python create_mask_rcnn_image.py --is_sim --is_mask
```
Create dataset like `random-maskrcnn-hard`, you should run `python utils/generate_hard_case.py` first, then,
```shell
python create_mask_rcnn_image.py --is_sim --is_mask --test_preset_cases
```
## Creating Your Own Test Cases in Simulation
To design your own challenging test case:
1. Open the simulation environment in CoppeliaSim (navigate to your CoppeliaSim directory and run `bash coppeliaSim.sh ~/dipn/simulation/simulation_new_4.1.0.ttt`).
1. In another terminal window, navigate to this repository and run the following:
```shell
python create.py
```
1. In the CoppeliaSim window, use the CoppeliaSim toolbar (object shift/rotate) to move around objects to desired positions and orientations.
1. In the terminal window type in the name of the text file for which to save the test case, then press enter.
1. Try it out: run a trained model on the test case by running `push_main.py` just as in the demo, but with the flag `--test_preset_file` pointing to the location of your test case text file.
## Running on a Real Robot (UR5e)
Change `is_real` in `constants.py` to `True`
### Camera Setup and Calibration
1. Download and install [librealsense SDK 2.0](https://github.com/IntelRealSense/librealsense)
1. Download the [chilitags](https://github.com/chili-epfl/chilitags) library, replace `chilitags/samples/detection/detect-from-file.cpp` with TODO, and compile. Replace `real/detect-from-live` with the compiled `detect-from-file` ececutable.
1. Generate 4 [chilitag markers](https://github.com/chili-epfl/chilitags) and paste them outside of the workspace but inside the camera's view. Put tag info and their center 2D positions in the robot's frame into `tag_loc_robot` variables.
### Quick Start
The workflow is the same as in the simulation.
The software version of UR5e is URSoftware 5.1.1.
1. Use `touch.py` and `debug.py` to test the robot first.
1. Download the dataset [Google Drive](https://drive.google.com/drive/folders/17X5aGr-50e6RqLkyyvG4mGHP_TUpz_kB?usp=sharing).
1. Put the downloaded folders to `dipn`. Change the path of model in the code `push_main.py`, line 83 & 88. The pre-trained DIPN is in `logs_push/push/data/15_push_prediction_model.pth`, the Mask R-CNN is in `logs/real-data/data/maskrcnn.pth`,
1. Place Your objects on the workspace.
1. Run `python push_main.py --save_visualizations --is_testing --load_snapshot --snapshot_file 'logs/real-GN/model/models/snapshot-000500.reinforcement.pth`
### Training
1. Fine-tune the Mask R-CNN with real data `real-data`.
2. Fine-tune the pre-training of Grasp Network with real data `real-data`.
3. Train the Grasp Network with the real robot.
### Additional Tools
* Use `touch.py` to test calibrated camera extrinsics -- provides a UI where the user can click a point on the RGB-D image, and the robot moves its end-effector to the 2D location of that point.
* Use `debug.py` to test robot communication and primitive actions.
* Use `utils/range-detector.py` to find the color range.
* Use `utils/mask-auto-annotate.py` to automatically annotate objects by color.
# Info
The code has dependencies over https://github.com/andyzeng/visual-pushing-grasping".
The code contaies DINP and DQN + GN