Generate dataset
Download
In this section, we generate a dataset for deep predictive learning using sensor information obtained during object grasping training with AIREC. We provide instructions on how to extract specific files from multiple rosbag data and save them in npz format using the provided sample data and scripts. Please follow the instructions below to download and extract the files.
$ mkdir ~/tmp
$ cd tmp
$ wget https://dl.dropboxusercontent.com/s/90wkfttf9w0bz0t/rosbag.tar
$ tar xvf rosbag.tar
$ cd rosbag
$ ls
1_rosbag2npz.py 2_make_dataset.py 3_check_data.py bag data output utils.py
Files
The downloaded file contains the following files. Users can generate datasets from rosbag data by running the programs in numerical order.
- 1_rosbag2npy.py: Extracts the specified information (topic data) from rosbag files and converts it to the npz format.
- 2_make_dataset.py: This program does three things. First, it adjusts the data length to ensure a consistent time series length for all data, regardless of the
--duration
argument set duringrosbag recording
. Second, it sorts and stores the training and test data based on a specified index. Third, it calculates the normalization parameters (upper and lower bounds) for the joint angles. For detailed information on this process, please refer to the link provided. - 3_check_data.py: This program visualizes the collected data by saving images and joint angles of the robot as gif animation. Before running the training program, it is important to check the cropping range of the images and the normalized range of the joint angles.
- utils.py: This file contains preprocessing programs (e.g. normalization) required for the dataset.
- bag: This directory stores the collected
rosbag
data. - data: After running
2_make_dataset.py
, this directory stores the training and test data, along with the normalization parameters for the joint angles. - output: This directory stores the visualization results, with the training data index in the filename.
Data Extraction
The following command can be used to extract specific information (topic data) from rosbag files. See the details of the arguments below:
- bag_dir: Specify the directory where the rosbag data is stored.
- freq: Since the sampling rate (Hz) of different sensors varies, the data will be extracted and saved at the specified sampling rate.
$ python3 1_rosbag2npz.py ./bag/ --freq 10
Failed to load Python extension for LZ4 support. LZ4 compression will not be available.
./bag/rollout_001.bag
1664630681.9616075
1664630682.0616074
1664630682.1616075
1664630682.2616074
Since storing all topics in the npz file consumes a significant amount of memory, this script provides an example of storing specific robot sensor information, such as camera images, joint angles, and gripper status. Lines 31-35 list the names of the topics to save, and lines 50-87 extract data from the messages of each topic and save it to a predefined list. Note that saving the camera image as it is may require a large amount of storage space, so it is recommended to resize or crop the image beforehand. Even if sampling is performed at regular intervals, the data length of the topics may differ depending on the start and end time of the rosbag recording. Therefore, after line 95, the time series length is adjusted accordingly. The program can be adapted to the user's robot by changing the topic names and the data extraction method.
[SOURCE] 1_rosbag2npz.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
Dataset Preparation
The following command generates training and test data from the npz file converted in the previous section.
$ python3 2_make_dataset.py
./bag/rollout_001.npz
./bag/rollout_002.npz
./bag/rollout_003.npz
./bag/rollout_004.npz
./bag/rollout_005.npz
This program consists of three steps, and all generated data is stored in the data
folder. First, all data is loaded using the load_data
function. The operations performed in lines 21, 22, 28, and 29 are as follows
- resize_img: Resizes the image to the given size. This function supports time series images based on the
cv2.resize
function. - cos_interpolation: To facilitate learning and prediction of rapidly changing 0/1 binary data, such as robot hand open/close commands, cosine interpolation is used to transform the data into smooth open/close commands. See the provided link for more information.
- list_to_numpy: Even if you specify a storage time
--duration
for therosbag record
, the sequence length of all rosbag data may not be the same due to the timing of the ROS system execution. Therefore, the data length is standardized and formatted by performing padding processing according to the longest sequence.
Lines 43-46 sort the training and test data based on user-specified indices (lines 36 and 37). The relationship between the training positions and the indexes is shown in the table below. The positions A-E in the table represent the object position. Four training data points were collected for each teaching position, and one test data point was collected for all positions. A total of 15 data points were collected. When evaluating the model using only the test data collected at the teaching positions, it can be difficult to observe generalization behavior at untaught positions due to overlearning at the teaching positions. Therefore, it is important to include even a small amount of untrained items in the test data to obtain generalization performance across items.
Finally, in lines 49-50, the upper and lower limits of each joint angle are calculated and stored as normalization parameters for the joint angles. For more information on why the upper and lower limits of the joint angles are calculated, see the link provided.
Position | A | B | C | D | E |
---|---|---|---|---|---|
train | 0,1,2,3 | None | 5,6,7,8 | None | 10,11,12,13 |
test | 4 | 15 | 9 | 16 | 14 |
[SOURCE] 2_make_dataset.py | |
---|---|
|
Visualization
The following command saves the image and joint angles of the robot as a GIF animation. The idx
argument represents the index of the data to visualize. The result will display the range of joint angles within the normalized range specified by the user, from [-0.92, 1.85] to [0.1, 0.9]. The figure below shows the actual GIF animation generated, with the camera image, robot joint angles, and normalized robot joint angles displayed from left to right. If the cropping or normalization range of the joint angles differs from the expected range, it is most likely that errors have occurred in the "resize_img" and "calc_minmax" processes described in the previous section.
$ python3 3_check_data.py --idx 4
load test data, index number is 4
Joint: shape=(5, 187, 8), min=-0.92, max=1.85
Norm joint: shape=(5, 187, 8), min=0.1, max=0.9
[SOURCE] 3_check_data.py | |
---|---|
|