[Locomotion] [IL] Motion Tracking Control: From Motion Retargeting to Imitation Learning Training
DEEP Robotics · Uploaded · 44:25 · Watch on YouTube
A DEEP Robotics algorithm engineer walks through converting human motion capture data into DR02 humanoid motion using GMR-based inverse kinematics. He then shows the imitation learning code structure and PPO training setup for motion tracking policies.
Transcript
Captions as a .vtt fileEmbed with the transcript
- 0:14Hello everyone, my name is Robo Xiang. I am an algorithm engineer at Deep Robotics.
- 0:22Many of you have probably seen robots dancing like humans on video platforms or on stage.
- 0:30These smooth human-like movements are usually achieved through imitation learning.
- 0:37In this video, I will introduce the imitation learning training code for the DR02 robot.
- 0:45The video has two main parts, motion retargeting and imitation learning training.
- 0:53Both parts are open source, delivering to GitHub repositories, Deep Robotics Retarget and Deep Robotic Mimic.
- 1:04Before we dive in, let me make a quick disclaimer.
- 1:10Both repositories are still work in progress.
- 1:14If you spot anything that could be improved, feel free to let us know.
- 1:20Let's go start.
- 1:22First, let's look at motion retargeting.
- 1:25In this section, I will explain why we need motion retargeting.
- 1:29Look at some common human motion data formats.
- 1:33Introduce the GMR algorithm and its implementation.
- 1:38And finally, show you how to use our retargeting tool.
- 1:43Motion retargeting is a technique.
- 1:45It converts human motion data into motion for a humanoid robot.
- 1:51The robot usually has a different skeleton sculpture and different body proportions.
- 1:58You might be wondering, why do we need motion retargeting at all?
- 2:03Can we just collect data that the robot can use structurally?
- 2:08Let's think about a simple example.
- 2:11Suppose you bend down and want your fingers to touch the ground.
- 2:17If we want the robot to imitate this movement,
- 2:20we can't simply copy the human joint angles.
- 2:24That's because humans and robots have different body structures.
- 2:29They have different body proportions, different joint motion ranges,
- 2:34and different coordinate system directions.
- 2:38As you can see, these images compare our robot with the human skeleton
- 2:44from the free-motion data source.
- 2:47So, copying the joint angles directly will most likely not achieve the same movement.
- 2:55The robot head might go through the ground or stay in the air.
- 3:01The robot might even end up in an unnatural posture.
- 3:06So, the purpose of motion retargeting is to convert human motion into a form
- 3:12that the robot can actually use.
- 3:16In general, complete human motion data is a squeeze of skeleton process
- 3:23that changes over time.
- 3:25It has two parts, the skeleton and the motion.
- 3:30The skeleton describes which joints the human body has and how they connect.
- 3:37The motion describes the pose of the skeleton at each time step.
- 3:43Playing many frames continuously on one skeleton gives a complete motion.
- 3:50Common human motion data formats include SMPL and BVH.
- 3:56Let's look at both.
- 3:58SMPL is a parametric human body model.
- 4:02It describes the body with shape parameters, called beta,
- 4:07and pose parameters, called theta.
- 4:10The ARMA's dataset contains a large amount of human motion capture data,
- 4:16converted into the SMPL parameter format.
- 4:21Let's see what is stored in the data file.
- 4:25First, the bird shape parameter is beta.
- 4:29And this is gender.
- 4:31It is used because SMPLX provides three gender models.
- 4:37Based on this parameter, we select the correct one.
- 4:41And this is sampling rate.
- 4:44Then, we have the full body pose.
- 4:47The pose data has a shape of 718 by 63,
- 4:53which means 718 frames and 63 body joints.
- 4:59We also have position and orientation of the model roots in the vertical coordinate system.
- 5:10There are some other frames, but we usually do not use them.
- 5:15If you are interested, you can find more details in the relative documentation.
- 5:21BVH stands for BioVision Hierarchy.
- 5:26Compared with SMPL, BVH is more compact.
- 5:31It mainly contains two types of information,
- 5:35the skeleton hierarchy and motion data for each frame.
- 5:40At the beginning of the file,
- 5:43BVH defines the skeleton hierarchy,
- 5:47includes parent-children relationships between joints and joint offsets.
- 5:53Then, it records profound motion information, such as joint rotations.
- 6:00Our code is modified from the GMR project.
- 6:04GMR stands for General Motion Retargeting.
- 6:07It is an open-source, general-purpose motion retargeting framework.
- 6:13It provides a unified solution for motion retargeting.
- 6:17The code of the GMR is based on inverse kinematics, or IEK.
- 6:25The GMR algorithm has three steps.
- 6:28First, use a configuration file defines the correspondence between human body parts,
- 6:36human body parts and robot body parts.
- 6:39Second, for each frame of human motion,
- 6:42we calculate the positions and orientations of the human body parts.
- 6:49Finally, we use this value as targets for the robot,
- 6:54and solve the robot joint angles with inverse kinematics.
- 6:59Now, let's see how this is implemented in the code.
- 7:06In this repository,
- 7:08the access folder contains our robot URDF model and the SMPLX model.
- 7:15The SMPLX model needs to be downloaded beforehand by yourself.
- 7:22The general motion retargeting folder contains the main algorithm,
- 7:28the retargeting configuration file, the core algorithm, and utility and visualization plugins.
- 7:36The script folder contains explained programs.
- 7:43It provides examples for retargeting data from different sources,
- 7:50plus conversion and visualization tools.
- 7:55In the general motion retargeting folder, focus on three frames.
- 8:00The IEK configures folder contains the IEK configuration file for the three supported data sources.
- 8:21In the LTS folder, two programs load BVH and SMPL data.
- 8:28They read the human motion and calculate the position and orientation of all key joints for each frame.
- 8:38The Lefenwender folder contains a BVH parsing library, plus some other utility functions.
- 8:48The configuration file has almost the same structure.
- 8:53Here, we specify the roots of the robot model and the human skeleton model.
- 9:01We also define the ground height, weather use, two IEK stages.
- 9:07This is one of GMR's important features and the scale table for key points.
- 9:14By applying different scale factors to different body parts,
- 9:20we can better align the human motion model with the robot model.
- 9:25The scale factor is applied to the position of each body part in the local coordinate system,
- 9:33whose origin is the human root.
- 9:37After that, the root position is scaled as a whole in the global coordinate system.
- 9:47Finally, there are two IEK match tables.
- 9:50Each key represents a joint.
- 9:54It defines the position and orientation tracking weights,
- 9:59plus the position and orientation of sets between the human and robot skeletons.
- 10:06In practice, we mainly adjust the tracking weights based on the task.
- 10:13When switching to a new dataset, the human scale table is usually the first thing we turn.
- 10:25The params.py file contains several configuration registers,
- 10:31the body model path, the IEK configure paths for different data sources,
- 10:38the robot space name, the robot space name, and the camera distance for visualization.
- 10:47The core algorithm is implemented in MotionRetarget.py,
- 10:53which defines the general motion retargeting class.
- 10:59During initialization, it loads the robot's model
- 11:04and prints the robot joints, bodies, and motors in the terminal.
- 11:11Then it loads the IEK configuration and applies the settings.
- 11:17Finally, it builds up the constraint list.
- 11:21Besides joint limits, there are two optional constraints.
- 11:27velocity limits, and collision avoidance.
- 11:32They are usually disabled by default.
- 11:34You can enable them in the configuration if you need it.
- 11:39The core method is the retargeting function.
- 11:45It defines the complete process for one motion frame.
- 11:51First, preprocess the input data, including scaling and offset compensation.
- 11:59Then we perform IEK in two stages.
- 12:02In the first stage, we usually tracking orientation only.
- 12:07The maximum number of iterations is 10.
- 12:11The goal is to quickly find a roughly correct joint configuration with sample constraints.
- 12:20In the second stage, we track both position and orientation.
- 12:26The maximum number of iterations is increased to 100,
- 12:31and the coverage threshold is reduced from 10 to the minor 3 to 10 to the minor 5.
- 12:40To avoid getting stuck when the target is unreachable.
- 12:45The server also stops if there is no improvement for five consecutive items and the error is still larger than 0.01.
- 12:59Why two stages?
- 13:02Throwing position and orientation together is computationally expensive,
- 13:09and more likely to get stuck in a local optimum.
- 13:14By allowing orientation first, we usually improve both convergence speed and solution quality.
- 13:23Now, let's look at how to use the tool.
- 13:27We use a BVH file in the NoKai format as an example.
- 13:33Just run a sample comment and specify the input and output file path, and the retargeting process starts.
- 13:44After it runs, we first see the motion played on the robot model.
- 13:51When playback finished, the corresponding robot motion data is generated.
- 14:00This visualization lets us check two things, whether the input human motion is correct,
- 14:09and whether the retargeting robot motion looks reasonable.
- 14:15If the reference motion is complex and the result looks not well,
- 14:22or you need higher accuracy for the hands or legs,
- 14:28we can modify the IEK config file for that data format.
- 14:34Adjust the constraints weights, try a few times, and the final result improves.
- 14:42After obtaining the retargeting motion data, we can start the imitation learning process.
- 14:51Next, I will introduce our code repository in five parts.
- 14:57Code structure, robot model, training code, training method, and deployment.
- 15:04The project has two main parts, script and source.
- 15:10The script folder mainly contains utility programs.
- 15:15It also contains the RSRL folder, which provides code for training, testing, and mode export.
- 15:25The imitation learning implementation is mainly in the source folder.
- 15:31Under source, we define an extension package called whole body tracking.
- 15:40Inside it, we implement the main training logic for training reference motion with the robot.
- 15:51The access folder contains the robot model files.
- 15:57The robots folder defines the robot configuration used in simulation.
- 16:03The tasks folder is the most important part.
- 16:09It defines the training environment and how the agent interacts with the robot and environment.
- 16:18It also contains the reward, observation, and termination configurations, which we will introduce later.
- 16:30The LTS folder contains basic utilities, such as motion data loading and model exporter.
- 16:41First, let's look at the robots folder.
- 16:45Open the dr02pro.py.
- 16:49Here we define the configuration object for the dr02 robot.
- 16:55We load the urdf file and configure the physical properties.
- 17:01One important thing, we do not directly use all the joint parameters in the urdf.
- 17:09Instead, we configure the joint properties again according to the training requirements.
- 17:17So, if you want to change torque limits, velocity limits, and position limits, stiffness k, damping d, or other joint parameters, change them here, not in the urdf file.
- 17:33We use randompd-accurator config to define robots joints, implemented in the actuator.py.
- 17:43One on top of the joint limit, PD gains, and joint delays provided by the delaypd-accurator.
- 17:55It also adds several types of randomization for PD parameter, peak torque, joint zero offset, and torque speed curve.
- 18:07The purpose of randomization is to improve the robustness of the trained policy, so the robot can better handle parameter difference on the real hardware.
- 18:25We use the classic PPO algorithm.
- 18:29PPO is very powerful, so we do not need to change much here.
- 18:33So, I will not go into the algorithm details.
- 18:37We will only cover the parts we need to modify.
- 18:41First, max iteration.
- 18:44We set it to 20,000.
- 18:47For sample motions, around 10,000 iterations may already give good results.
- 18:54But we usually set a larger number to make sure training is complete.
- 19:00The needed iterations mainly depend on motion complexity.
- 19:06Next, save iterative interval.
- 19:10We set it to 500, so a checkpoint is saved every 500 iterations.
- 19:18This keeps models from different training stages and makes it easy to resume if something goes wrong.
- 19:27Then, empirical normalization.
- 19:30It controls whether the input observations are normalized.
- 19:36In PPO training, this is usually enabled, so we set it to true.
- 19:42Next is the PPO network configuration, including the actor and critic structure, hidden layers, and activation function.
- 19:56By default, we use allure.
- 19:58You can also try other activation functions.
- 20:02However, for this task, different activation functions usually do not make a very significant difference.
- 20:12The remaining parameters mostly use the stand PPO configuration.
- 20:20In most cases, you do not need to change them.
- 20:24Next, let's look at the task environment configuration.
- 20:29If you have used our project to train quadrat robots for velocity tracking, the structure here will look familiar.
- 20:38Both projects use the RSRL framework.
- 20:42When where needed, I will compare the two, so the difference between imitation learning and other RL tasks will be easier to understand.
- 20:54First, the environment configuration program.
- 20:58The environment is composed of several configuration modules.
- 21:10First, the same.
- 21:12By default, we use a flat ground environment, which is the plane.
- 21:17For friction, we use the multiply combination mode.
- 21:21Both static and dynamic friction coefficients are 1.
- 21:26So the final contact friction is mainly determined by the robot fleet.
- 21:33The robot asset is temporarily set to missing.
- 21:37We want a general environment independent of a specific robot.
- 21:45The actual robot model is specified in the other configuration.
- 21:52We also configuration contact sensors.
- 21:56They are very useful in motion limitation.
- 22:00They provide contact information between the robot and the environment.
- 22:06For example, they tell us whether the feet touch the ground and whether the contact is normal.
- 22:14This helps reward calculation and also tell us whether the robot has loose balance and whether the episode should end.
- 22:25We also configure contact related parameters such as history length, air time tracking, and contact detection threshold.
- 22:37This affects reward calculation and terminal later.
- 22:42Next, the command configuration.
- 22:46The command in motion tracking differs greatly from that in velocity tracking.
- 22:53In velocity tracking, the command is relatively vague.
- 22:59It only tells the robot which direction to go and how fast.
- 23:06Usually containing the desired x, y velocities and desired yaw rate.
- 23:14In imitation learning, in contrast, the command is much more specific.
- 23:20The robot tracks the changes reference motion states to achieve complete motion expression.
- 23:31These motion states include not only the joint angles at the current moment but also the joint velocities.
- 23:42In the motion command class, we also use the joint, anchor, and key body positions and orientations from the reference motion.
- 23:52The reference data contains every body part of the robot.
- 23:58Our full model has about 40 rigid bodies but we do not use all of them during training.
- 24:07Instead, we select only 14 key body parts, mainly the shoulders, elbows, wrists, hips, knees, and anchors.
- 24:22With the position and orientation of these 14 parts, we can basically determine the robot's pose.
- 24:32Another important algorithm design in imitation learning.
- 24:37When initializing the robot, we randomly sample the starring frame from the reference motion.
- 24:49This is an algorithm design called RSI, reference state initialization.
- 24:57Implemented in the resample command function in the code.
- 25:02It is very useful for training complex motions.
- 25:07If every episode starts from the first frame, the robot has to learn the first half of the motion before that.
- 25:17Before that, before it can even get a chance to learn the second half.
- 25:24That is very inefficient.
- 25:28For example, when robot jumps, if the robot has not learned how to land yet but always start from the beginning of the jump,
- 25:42it may fall frequently at takeoff or forward landing.
- 25:47In that case, the policy may learn a simple but warm behavior, such as only waving at its arms without actually completing the jump.
- 26:03With RSI, the robot can directly learn different phases of the motion, which makes training more efficient.
- 26:15If a certain segment of motion is particularly difficult for the robot, you can also try increasing the sampling probability of that segment during training.
- 26:30So that the robot can learn faster.
- 26:34One more thing to note.
- 26:38The body order and joint order in the reference data are not the same as in the URDS.
- 26:47Instead, they follow the order generated after ISAC lab loads the robot.
- 26:56The general logic is to start from the base link and do a brand first, second, third over the robot structure.
- 27:08For example, it may first read the left and right hip joints, then the main body, and then the left and right shoulders.
- 27:22So, when you need to access a specific body or joint in the command during development, it is better to use a name-based index rather than a fixed index.
- 27:40This avoids data mismatches when the robot structure changes and makes the code easier to understand and maintain.
- 27:52In addition, we also apply a certain degree of domain randomization to the reference motion data inside the command, which further improves the robustness of the policy.
- 28:11Next, the action.
- 28:14In motion tracking, the action is the target joint position output by policy.
- 28:21They will control the robot.
- 28:23The action also needs a scale parameter.
- 28:27This configuration is in the flat environmentconfig.py.
- 28:33Again, the action order follows the ISAC lab joint order.
- 28:41So, during deployment, we need a reorder step, converting the simulation joint order into the order required by the real robot control interface.
- 28:58This ensures each action goes to the correct joint.
- 29:06Next, the observation.
- 29:08It has two parts, policy observation and privilege observation.
- 29:13The policy observation is the input to the actor network.
- 29:18It represents information we can get during real robot deployment.
- 29:24The privilege observation is the input to the critic network.
- 29:31It contains extra information only available during training.
- 29:37First, the policy observation.
- 29:40It mainly includes reference motion, base link, gravity, root angular velocity, joint position, joint velocity, and history actions.
- 29:53The reference motion is very important.
- 29:58It contains the reference joint position and velocities, which guide the policy toward the target motion.
- 30:09During training, the policy uses them to know what to do at each moment.
- 30:15During deployment, we also provide the informed motion so the robot can perform the movement.
- 30:26The base link gravity is the three-dimensional projection of the gravity direction in the base link frame.
- 30:35It helps the policy understand the robot's posture.
- 30:41For example, whether it is tearing or falling, a real robot gets similar information from its IMU.
- 30:52So this works in both training and deployment.
- 30:57During training, we also use noise to it, making the input more like real sentence measurement and improving deployment robustness.
- 31:13The history actions are the actions from previous time steps.
- 31:20They help the policy understand its recent motion trend and improve smoothness.
- 31:29Now, the privilege observation.
- 31:31Besides what we mentioned, it also contains the position and orientation of anchors and other bodies, plus the linear velocity of base link.
- 31:41These values are hard to get on the real robot, but they help the critic evaluate the current state.
- 31:51By giving the actor and critic different information, we improve training efficiency.
- 31:59At the same time, the policy does not depend on information the real robot cannot get during deployment.
- 32:08If you compare this code with the velocity tracking code, you will see a difference.
- 32:18For velocity tracking, the robot needs to keep walking or running.
- 32:23So, the observation usually contains gain phase, foot height, air time, and contact state.
- 32:33This helps the robot understand its walking state.
- 32:37For imitation learning, the privileged observation in sand contains bird-dee pose.
- 32:44This gives more accurate information for learning a new motion.
- 32:51And then, the event configuration.
- 32:54Events are mainly used for domain randomization during training.
- 32:59In the real world, the robots are affected by cables, assembles, errors, and different between components.
- 33:09So, the physical parameters of each robot may differ slightly.
- 33:15If we train with only one fixed set of parameters, the policy may become too specialized to simulation, causing a large performance gap on the real world.
- 33:31So, we often use domain randomization in reinforcement learning to make the robots more robust to different physical conditions.
- 33:43Here, we configure five types of events.
- 33:47The first four is the startup model.
- 33:52Means they are applying when each episode starts.
- 33:57We randomly change the friction coefficient, restitution coefficient, default joint positions, robot mass, and sand of mass positions within range.
- 34:14These are physical parameters that can significantly affect real-world motion.
- 34:21The large event uses the interval mode.
- 34:27The robot receives random external push during the episode, simulating disturbance such as collisions or unexpected bumps.
- 34:45Together with the observation noise.
- 34:50This randomization makes training close to the real robot and improves the robustness of the final policy.
- 35:00Next, rewards.
- 35:02In reinforcement learning, the reward quality finds the behavior we want.
- 35:08If it is well decided, the robot's behavior moves close to the target as training progresses.
- 35:17For imitation learning, rewards fall into two categories, tracking rewards and constraint rewards.
- 35:26Tracking rewards relate to motion tracking.
- 35:30They include tracking the center of mass or anchor position and orientation, tracking key body position and orientation, and their linear and angular velocity.
- 35:45The goal is to follow the reference motion as closely as possible.
- 35:52If all important body parts track the reference well throughout the motion, we consider the motion learned.
- 36:02But in practice, overall tracking reward alone may not always work well.
- 36:11If we only measure overall body tracking error, the vertical wall error of the feet may be small.
- 36:21So the policy may not pay enough attention to lifting the feet.
- 36:26The motion may look mostly right, but the feet never right lift the ground and simply slide.
- 36:34So for important motion features, we add extra rewards.
- 36:39For example, a foot-high tracking reward makes the policy pay more attention to foot-high and improve leg motion.
- 36:49Besides tracking rewards, we have constraint rewards.
- 36:55They usually have negative weight and penalize unwanted behaviors, such as exceeding joint position limit, exceeding torque limit, or self-collision.
- 37:10These constraints let the policy complete the target motion while satisfying the robot physical limit.
- 37:20In general, if the reference motion is simple or have good quality, imitation learning needs fewer rewards than velocity tracking.
- 37:31A good reference already provides strong guidance.
- 37:36If the motion is difficult or the reference is not very good, we may add more specific reward function to guide or constrain certain parts.
- 37:49Next, termination.
- 37:52Termination defines when an episode ends during training.
- 37:56In general, when the current state can no longer provide useful training data, we end the episode early.
- 38:06The first case is when the episode time limit is reached.
- 38:12Each episode has a maximum duration.
- 38:15When the simulation steps can't reach this limit, the episode ends regardless of the robot's current state.
- 38:25The second case is when the robot state has deviated too far from the target.
- 38:34For example, the robot's center of mass may move too far from the reference position.
- 38:42Its posture may also become abnormal.
- 38:46Or the feet may move too far away from their reference position.
- 38:51This indicates that the robot may lose balance or is about to fall.
- 39:00Since data from such states is usually not useful, we terminate the episode early.
- 39:08Termination for imitation learning is usually stricter than for velocity training.
- 39:16Early termination acts as extra supervision.
- 39:21It keeps the training data concentrated in valid motion widgets and prevents the policy from drifting too far from the reference.
- 39:34Once important point, once early termination triggers, all remaining rewards in the episode are set to zero.
- 39:47In some cases, we also use curriculum learning.
- 39:51For complex motion, it lets the robot move gradually from an easier version of the task to complete motion.
- 40:01For example, we first reduce the difficulty and let the robot learn the basic motion patterns.
- 40:09Then, we gradually increase the requirements until the robot platform the complex motion.
- 40:16This is very useful for difficult movements.
- 40:20But for most motions, if the reward is well decided and the reference has good quality,
- 40:29we can usually train a good policy directly.
- 40:33So, curriculum is not required for every task.
- 40:38After retargeting, we can get a .pkl file.
- 40:43Its meaning contains the two robots drawing and anchor motion data and is not enough for imitation learning.
- 40:52During training, we also need the relative position and orientation of each body with respect to the anchor.
- 41:04So, we compute them with World Kinematics or FK and save them into the data file in ADVICE.
- 41:13This avoids repeated FK computation during training and improves efficiency.
- 41:23After pre-processing, we can start training.
- 41:29We provide a training program with automatic recovery.
- 41:33If training runs long and is interrupted by norm values or other errors, this program will start automatically.
- 41:43This is very useful for humanoid training, which often takes a long time.
- 41:49During training, we can adjust settings by modifying the configuration parameters.
- 41:59We can also use TensorBoard to view reward and episode length, which makes monitoring easier.
- 42:08Finally, let's talk about policy export and deployment.
- 42:12After training, we use export onnix fast.py to export the policy as an onnix model.
- 42:22If you are using our deep robotics SDK 2 for deployment, place the training motion data in the state machine's motion data folder,
- 42:34and the policy file in the policy folder.
- 42:39We also need to modify the path configuration in MimicPolicyRunner.hpp under the RunPolicy folder.
- 42:51This ensures the program loads the motion data and policy correctly.
- 42:58After this step, we can run the trained imitation policy on simulation or on real robot.
- 43:07That is all for this video.
- 43:25We introduce the complete imitation learning pipeline of the DR-02 robot in two parts, motion retargeting and imitation learning training.
- 43:37Of course, with limited video time, it is impossible to cover every detail.
- 43:44Both projects are open source, and the GitHub links are in the video description.
- 43:51You are welcome to ask questions and discuss on GitHub, and you are welcome to download the code and explore more interesting humanoid robot applications.
- 44:03Thank you for your watching.
Обговорення
Лист, коли хтось коментує. Обліковий запис не потрібен.
Розсилка
Отримуйте наш безкоштовний інформаційний бюлетень з новими роботами, цінами та новинами робототехніки.