TuneNet: One-Shot Residual Tuning for System Identification and Sim-to-Real Robot Task Transfer
Adam Allevato Elaine Schaertl Short Mitch Pryor Andrea L. Thomaz
cs.RO

Unsupervised Domain Adaptation via Calibrating Uncertainties
    [
    December 30, 2023
============================================================




As researchers teach robots to perform more and more complex tasks, the need for realistic simulation environments is growing. Existing techniques for closing the reality gap by approximating real-world physics often require extensive real world data and/or thousands of simulation samples. This paper presents TuneNet, a new machine learning-based method to directly tune the parameters of one model to match another using an iterative residual tuning technique. TuneNet estimates the parameter difference between two models using a single observation from the target and minimal simulation, allowing rapid, accurate and sample-efficient parameter estimation. The system can be trained via supervised learning over an auto-generated simulated dataset. We show that TuneNet can perform system identification, even when the true parameter values lie well outside the distribution seen during training, and demonstrate that simulators tuned with TuneNet outperform existing techniques for predicting rigid body motion. Finally, we show that our method can estimate real-world parameter values, allowing a robot to perform sim-to-real task transfer on a dynamic manipulation task unseen during training. Code and videos are available online at <http://bit.ly/2lf1bAw>.




§ INTRODUCTION

Recent research has validated simulators for real-world robot behaviors and control policies. Several studies have shown the ability to adapt simulation-learned policies to the real world based on observations <cit.>, but these techniques require extensive real-world data collection. Even before collecting data in the real world, however, we can improve simulations by simply selecting more realistic simulator parameter values. While some approaches train over a large set of possible parameter values to create a robust policy <cit.>, we are interested in the problem of creating a single "canonical" simulation that behaves as realistically as possible, which can then be used for robust physics prediction or better task planning.

In this paper, we propose TuneNet, a residual tuning technique that uses a neural network to modify the parameters of one physical model so it approximates another. TuneNet takes as input observations from two different models (i.e. a simulator and the real world), and estimates the difference in parameters between the models. By estimating the parameter gradient landscape, a small number of iterative tuning updates enable rapid convergence on improved parameters from a single observation from the target model. TuneNet is trained using supervised learning on a dataset of pairs of auto-generated simulated observations, which allows training to proceed without real-world data collection or labeling.



Our primary contribution is the concept of residual tuning, which allows fast and accurate one-shot system identification, and the development and analysis of the TuneNet neural network model for applying iterative parameter updates. We show that TuneNet is fast and effective: it tunes more efficiently than other gradient-free optimization methods, and that it outperforms state-of-the-art techniques for predicting rigid body motion. Finally, we validate that TuneNet can tune simulations to match real-world environments, and use those simulations to conduct sim-to-real task learning by teaching a robot to complete a task that requires accurate dynamics prediction.




§ RELATED WORK


This paper focuses on tuning simulation parameters as a way to help rapidly close the reality gap. This places it at the intersection of system identification and sim-to-real learning.

Classical system identification <cit.> used maximum likelihood methods to estimate the parameters of a fixed model given observed behavior. For estimating parameters of complex non-differentiable models (such as physics engines), robotics researchers have used a variety of gradient-free <cit.> or gradient-approximating <cit.> optimization techniques. 
These techniques require sampling the model (e.g. performing simulation rollouts) many times with different parameter values, which is a computationally expensive process. TuneNet seeks to minimize the number of simulation rollouts during system identification. Research has shown the ability to perform robot system identification from a few observations using a neural network <cit.>, but cannot take advantage of previous parameter estimations, and the results have not been validated in a sim-to-real setting.

In contrast to system identification, recent work (<cit.>) has explored data-driven methods for simulation improvement by leveraging a combination of real-world data and domain randomization <cit.>. These adaptive approaches require huge numbers of randomized simulations to be repeated once the robot is in the target environment.


TuneNet also has similarities to techniques that learn a transformation or mapping from a simulated training environment to a target environment. These techniques leverage built-in priors in the form of physics simulators, while also providing a way to account for simulator inaccuracies. This may involve a neural network-based transformation over states <cit.> or actions <cit.>, learning a new real-world policy based on one learned in simulation <cit.>, or using a combination of a physics model and a data-driven residual to improve physics prediction <cit.> or policy learning <cit.>. All of these approaches require a substantial amount of real-world training examples from the target environment to learn a transformation or develop a new policy. In contrast, our approach learns to account for errors in parameter space rather than action or state space, and is pretrained in simulation, allowing a model to be adapted using a single observation from the target environment.

A recent related work is <cit.>, which trained a network to convert from randomized simulation images to non-randomized simulations, and showed that this network could also convert real-world pictures to simulations. <cit.> took a similar approach, using adversarial domain adaptation <cit.> and unlabeled data from the target environment to convert real images to simulated ones. Both of these works operate in the visual domain and focus on learning the arrangement of objects in an environment, whereas our approach focuses on learning better simulator physical parameters by observing the world state over time. Finally, <cit.> discovered physics parameters through robot interaction, but the possible parameter values are fixed and the approach does not take advantage of information that could be gleaned from an existing simulation.




§ ONE-SHOT RESIDUAL TUNING

In this section, we describe our approach for tuning a simulator to match real-world observations. We present the underlying theory first, followed by our algorithm and implementation.




 §.§ Tuning a Parameterized Model

Our goal is to generate a proposed model, f_ζ_P(s_t, a_t) = s_t+1, so that it approximates another (fixed) target model, g_ζ_T(s_t, a_t) = s_t+1, where ζ_P and ζ_T are physics parameters of those models. One way to develop this approximation would be to minimize the prediction error (some distance function d(·, ·)) over a dataset of N examples (<ref>), where L is the length of each example. 


    _ζ_P∑_n=1^N∑_t=1^L d(f_ζ_P(s_n_t, a_n_t),  g_ζ_T(s_n_t, a_n_t))


Unfortunately, we usually do not have access to the true system dynamics g_ζ_T. In addition, if the proposed model is an off-the-shelf simulator, it is not differentiable, and so we cannot easily calculate a gradient for <ref>. While we can directly estimate the parameters using a neural network (as in <cit.>), the approach would not generalize well outside the training set, and would be unable to iteratively improve a parameter estimate without additional data since it would encode a single mapping from states to parameter values.

In this work, we instead assume that there exists some set of parameters ζ_T' that will cause the proposed model to closely match the target model, f_ζ_T'≈ g_ζ_T, and seek to approximate it. This assumption takes advantage of the fact that f_ζ encodes at least a reasonable approximation of of g_ζ's dynamics, and allows us to use the proposed model as a prior during optimization. 




 §.§ TuneNet


Our model, TuneNet, estimates the parameter residual Δζ = ζ_T' - ζ_P ≈ζ_T - ζ_P between a single proposed model and a single target model, and then iteratively updates the proposed model parameters accordingly to match those of the target model. By using a network to estimate parameter deltas, we transform <ref> into a differentiable loss that can easily be used as a supervised learning objective. We can still calculate the quality of the world state estimation, but it does not appear in the loss.

We may be unable to directly observe the state of each model, and represent this with observation functions z_P and z_T applied to proposed and target models, respectively. Observations of length L are generated from each model using the current proposed parameter ζ_P and the true target parameter ζ_T (<ref> and <ref>).


    o_P = z_P(f_ζ_P(s_t, a_t)), t = 1… L


    o_T = z_T(g_ζ_T(s_t, a_t)), t = 1… L


TuneNet estimates the parameter error directly based on the two observations and approximates a function h, which is parameterized by some θ (in this work, the weights of a neural network): h_θ(o_P, o_T) = Δζ. The new optimization problem for training (over a dataset of length n) is given in <ref>, where λ is a weight regularization constant.

    _θ∑_n=1^N ( ζ_P_n + h_θ(o_P_n, o_T_n) ) - ζ_T_n + λθ^2


Our network consists of one independent fully connected layer for each observation, the outputs of which are concatenated and passed to additional connected layers which estimate the parameter error. We found that concatenating the two intermediate outputs performed better that other combination methods, such as calculating the difference. In this work, we use a physics-based simulator for the proposed dynamics model f_ζ, and the target model g_ζ is either another simulator or the real world.

We train TuneNet using a dataset where each datapoint consists of a pair of models with a known difference in physics parameters (see <ref>). The datasets are auto-generated purely in simulation, which removes the need for hand-labeling or real-world data and makes training faster, safer, and easier. Also, because pairs are generated from the same dynamics model (differing only by ζ), we know that during training, ζ_T = ζ_T' and the best-case reality gap during training is 0.

After training TuneNet, we apply it to a set of observations from a new target model and observations from an initial proposed model having parameters ζ_P (<ref>). As discussed below in <ref>, TuneNet excels at estimating smaller differences in ζ, so we tune iteratively in K steps to achieve the final ζ_P = ζ_P_k=K given a single target observation. The process can be described and implemented using a recursive approach, or an iterative one as listed in <ref>. The Resample function interpolates the values in o_T, if necessary, so that the length and sampling rate match those of o_P. The two observations are then passed to TuneNet to estimate the parameter difference between them. The algorithm adds the resulting estimate to the previous best guess for ζ_P, bringing it into closer agreement with ζ_T:


    ζ_P_k = ζ_P_k-1 + h_θ(o_P_k-1, o_T), k=1… K


Importantly, we are able to do this without collecting any additional observations from the target model, and only sampling the proposed model once per iteration (<ref>). After tuning, the tuned simulator f_ζ_P is ready to be used for other tasks such as object motion prediction and robot task planning. 





 §.§ Residual Tuning



By learning to estimate Δζ instead of ζ, an estimator naturally becomes better at estimating small deltas due to the nature of the difference transformation. Given uniformly distributed training data over some interval [d, u], the probability densities of parameters ζ_P and ζ_T are equal to some constant c = 1/u-d over the interval. However, the difference, Δζ, will be distributed according to P(Δζ = x) = -2/(u-d)^2x+2/u-d, making small delta values more common. As the parameter estimate becomes closer and closer to the true value, the network is able to leverage more and more training data. This behavior allows us to conduct iterative residual tuning by collecting observations from the proposed model using successively better ζ_P estimates. Estimating parameter deltas also allows TuneNet to tune to values that lie outside the ranges seen in training data, as opposed to other neural network approaches that often require a transformation or fine-tuning for a new output range.

Residual tuning can be seen as gradient descent in parameter space, using a neural network to approximate the gradient. While gradient-based optimization techniques such as momentum could potentially be combined with this approach, in this paper we show that TuneNet performs well using standard gradient descent.



§ EXPERIMENTS

We performed three experiments to test that TuneNet can efficiently tune an off-the-shelf simulator to match a target environment, including ones it has not encountered before (Exp. 1 and 2), that it can generate tuned simulations that can be used for object motion prediction (Exp. 2), that it can be used to estimate real-world parameters, even when trained purely in simulation (Exp. 3), and that we can use a simulator tuned with TuneNet as a platform for learning tasks different than the one used for data collection (Exp. 3). We implement all networks using PyTorch <cit.>. Network architecture details, layer sizes, and training hyperparmaeters are provided in the appendix.




 §.§ Experiment 1: System Identification in Simulation

We first performed a simulated experiment to validate TuneNet's ability to tune one model to match another. The tuned parameter was the mass of an object held in a robot's gripper—a classic system identification objective. To generate training data for the experiment, we use pairs of PyBullet[https://pybullet.orghttps://pybullet.org] simulations. Each simulation consists of a Kinova Jaco 7-DOF robot arm with a Robotiq 85 2-finger gripper at the end effector, moving in a circle as it holds an object (see appendix for task details). During this motion, we record the 7 raw joint torques over time, and provide this as the input observation signal. To make this task more difficult, in the test set, the target simulator has its object mass increased by an additional 1kg, putting the all correct mass values completely outside the range of values seen during training. This experiment therefore evaluates TuneNet's ability to complete more general tuning tasks, and ones that may take multiple iterations to complete.

After training, we applied TuneNet with K=9 iterations over the validation and test sets to measure the estimation accuracy (K was chosen empirically based on observed tuning behavior). We report the mean absolute error (MAE) of the estimated object mass over both the validation and test sets. We compare TuneNet's performance to several baselines: a prediction of 1kg for every data point (which would be the best our network could do if it was unable to tune values outside those seen in the training set) and a constant prediction of the mean parameter value in the test set. 

On this task, TuneNet achieved an MAE of ±0.011kg over the validation set, where both target and proposed masses were were in the training range (see <ref>). When evaluating on the test set, where the target masses were all outside the range used for training, 
TuneNet still achieved an MAE of ±0.198kg—higher than on the validation set, but still far better than either baseline of always predicting 1kg (MAE=0.504kg) or predicting the average test-set value (MAE=0.255kg). 






 §.§ Experiment 2: Bouncing Ball in Simulation

To further test TuneNet's ability to tune parameters, as well as its ability to predict rigid-body motion, we used it to tune the coefficient of restitution (COR) of a simulated bouncing ball. Our proposed and target dynamics models were again PyBullet simulations. For training, we recreated the simulated dataset used in the work of <cit.>: in each episode, a 0.5m-radius sphere is dropped onto a flat plane from a starting height in the range 4-5m, having COR∼U(0.3, 0.7). At each timestep, we recorded the xyz position of the ball as the world state. We used the same sampling and dataset parameters as <cit.>—800 simulations for training and 100 for testing, with a physics update rate of 60Hz and episode length of 400 frames. We also note that unlike in <cit.>, each example in our dataset consists of information for a pair of simulations. In this experiment, the observation functions z_P and z_T were identity, i.e., we had direct access to the world state ground truth. We refer to this case as GT (ground truth) in the rest of the paper.

We test over two datasets, GT Easy and GT Hard. GT Easy consists of simulations with proposed and target COR values in the range [0.3, 0.7], the same as in the training set (this is for a more fair comparison with <cit.>). In GT Hard, the target COR values are extended to the range [0, 1.0].

After training, we evaluated TuneNet by applying K=5 tuning iterations to tune a unique model for each run in the test set. For each run, we report the mean absolute error (MAE) between the final proposed model's COR and the target model's COR. We compare against four baselines: predicting the mean of the test set target parameters (Mean), our implementation of greedy entropy search <cit.> (EntSearch), the CMA-ES optimization method <cit.>, and a neural network that learns to directly predict parameters in one step (direct prediction). Details on baseline implementations are in the appendix. To test our tuned model's overall accuracy in object motion prediction, we record the ball's position from a rollout of the final proposed model, compare it to the target model, and report the MAE and percent error (trans err, cm, and trans err %) over all runs and timesteps.






<ref> compares the average tuning performance (measured by the MAE between the true and estimated parameters) as more and more simulation rollouts are used for estimation. Direct Prediction and Mean require 0 rollouts, since they are computed directly from the target observation. CMA-ES uses 10 rollouts per iteration, and the other algorithms use 1 rollout per iteration. <ref> quantifies the values in the table for various numbers of simulation rollouts, averaged across the entire training set. TuneNet's one-step prediction accuracy is slightly lower than direct prediction, but it achieves the best accuracy of all methods in less than 5 iterations. In contrast, EntSearch has difficulty converging to a good value, and CMA-ES requires far more samples to develop a good estimate.





<ref> shows the object motion prediction error for the bouncing ball dataset. We compare to <cit.>'s VRNN hybrid network, although we note that those results are from one-step prediction models, whereas our model uses the entire state history to tune and is reported averaged over the entire dataset. TuneNet GT outperforms all other approaches for position prediction, with an MAE of 7mm, or 1.08%. 



 §.§ Experiment 3: Tuning for Sim-to-Real Task Learning

Finally, we tested TuneNet for sim-to-real learning by estimating the COR of a bouncing ball again, but this time in the real world. Our task is to use a tuned simulator to bounce balls off an inclined plane into a hoop (a "bounce shot"), as seen in <ref>. This is a difficult task, as striking the rim of the hoop will often cause the ball to bounce away rather than passing through the hoop. 

Our hardware platform for evaluation consists of a Kinova Jaco 7DOF robot arm with a Robotiq 85 2-finger gripper (see <ref>), controlled using ROS[https://ros.orghttps://ros.org]. A camera is positioned opposite the robot for perception purposes.


We trained TuneNet on a visual version of the GT Easy dataset used in Experiment 2. For the target simulator in each episode, we rendered a 2D video using PyBullet's renderer, and applied an RGB-only OpenCV object tracker to calculate the position of the ball in each frame. The tuning problem remains challenging after using this object detector, since in addition to the presence of visual noise, 2D pixel coordinates do not directly correspond to z-height in 3 dimensions and our camera images are uncalibrated. The network input for each tuning task is the ground truth 3D position for the proposed model and the visually-derived 2D pixel position for the target model. This helps test TuneNet's ability to generalize and learn different transformations for each input channel. We refer to this network as TuneNet Obs in the rest of the paper.

For comparison purposes, we report TuneNet Obs performance in object prediction over the simulated dataset from Experiment 2 (<ref>). It still achieves position accuracy within 6%, and while it performs more poorly than the GT case, this is expected, since the network is operating on uncalibrated and noisy visual observations and the other approaches in the table have access to the true simulator state.



For the bounce shot task, we performed 10 independent tuning trials for 6 different ball types. In each trial, the robot first dropped the ball on a flat table and recorded a video of the resulting bounces. The video was resampled to 60 Hz, clipped to 400 frames, and processed using the same OpenCV object tracker as on the training set. TuneNet operated on the observation from one real-world drop and the ground truth state from an un-tuned simulator which started with a COR of 0 (no bounce). We used TuneNet (K=5) to tune the simulated COR, clamping to the range [0, 1], as values outside this range are physically meaningless. 

<ref> shows an example of TuneNet using K=5 iterative tuning rounds to match observations from a video of a dropped racquetball, beginning with a COR of 0. The first parameter updates are large, and successive iterations fine-tune the estimate because of the more accurate tuning behavior for small parameter deltas (see <ref>).

The tuned COR value was used to construct a new simulator, consisting of a dropped ball, inclined plane, and hoop that match our real-world task setup. The simulator was used to uniformly sample 100 shot heights from a range within the robot's reachable space, and the optimal height was chosen as the shot height that passed the ball as close to the center of the hoop as possible. The real robot then executes the shot from the optimal height. We repeat the task for all 10 independent trials and all 6 ball types (not all of which are round, see <ref>) and record the success or failure of the bounce shot.

<ref> shows the results of the bounce shot task and a representative execution. Overall, the robot succeeded at 62% of the bounce shots. The primary reason for failure was that during the pre-tuning data collection step, the ball bounced or rolled off the table or out of view of the camera. This resulted in a meaningless input observation, which caused in a low estimated COR and incorrect drop height. Indeed, when these "off table" trials are removed, the success rate increases to 87%, whereas the "off table" trials were only 18% successful, as shown in <ref>. Eliminating these examples where the ball bounced off the table in the observation drop, two of the six ball types were successful in every trial. Successful shots with all 6 balls can be found in the supplementary video.









§ DISCUSSION AND CONCLUSION




TuneNet is fast. Since each tuning iteration consists of a single network forward pass and a single simulation rollout, TuneNet reduces the number of parameter-space simulation samples required compared to existing gradient-free optimization, and it tunes significantly faster than techniques that alternate between domain randomization in simulation and real-world data collection <cit.>. Our dataset generation and training procedure is also fast due to being trained entirely in simulation, and completes in under 7 minutes using a single NVIDIA GTX 1080Ti. 

TuneNet is effective. Our results show that even though a simulation cannot perfectly model the real world, much of the reality gap can be closed by choosing good simulation parameters. We also note that TuneNet is compatible with recent approaches that learn data-driven transformations or residuals to improve simulations <cit.>, and envision a two-step approach where TuneNet first matches a real-world environment as closely as possible using parameter tuning alone, then additional unmodeled effects are accounted for using learned transformations or domain randomization.


That said, there are some limitations of our approach that suggest avenues for future work. For example, parameters may not be fully identifiable based on observations alone, as explored in several studies <cit.>. As discussed in <cit.> and <cit.>, the identifiable set of parameters may be coupled, which would result in multiple local minima in parameter space. This may prove to be an issue if the goal is to accurately measure system parameters, but as long as the tuned parameters enable accurate prediction and sim-to-real learning using the proposed model, which local minimum the algorithm converges to is less important. For example, in our study, the racquetball had high task success rates despite a technically inaccurate COR estimate (0.789±0.024 vs. regulation values of 0.68–0.72 <cit.>). We also note that <cit.> is concurrently studying the problem of modeling belief over coupled parameter values.







In this paper, we introduced TuneNet, a neural network-based technique to perform residual tuning between two models, and validated the approach for use in system identification and sim-to-real robotics tasks. TuneNet represents a new method for closing the reality gap, showing that a simulator can be matched to the real world with just one observation and minimal simulation sampling. We plan to use TuneNet to rapidly generate tuned simulators for new environments, developing strong models for object manipulation without extensive real-world practice.



§ ACKNOWLEDGMENTS

We thank Josiah Hanna and Scott Niekum for their helpful suggestions on this paper. This work was supported by the National Science Foundation (IIS-1564080, IIS-1724157) and Office of Naval Research (N000141612835, N000141612785).





§ APPENDIX




 §.§ TuneNet Architecture Implementation Details

We implement all networks using PyTorch <cit.>, and train them using stochastic gradient descent. Our TuneNet architecture for all experiments consists of fully-connected (FC) layers with ReLU activation functions for each of the feature extractors, with each feature extractor output size set to 32. The estimator therefore has an input size of 64. We model the estimator with two fully connected layers with a hidden size of 32, ReLU activation for the first layer, and a tanh activation for the final output. 



 §.§ Details for Experiment 1: End-effector Mass Identification

The object's mass is randomly chosen, m ∼ U(0kg, 1kg), for each training point. In each simulated episode, which runs for 5 seconds, the robot moves its end effector in a circle defined by the coordinates [-0.4, 0.2cos(τ), 0.2sin(τ)], τ = 1.2t. We collect 1000, 300, and 300 episodes for the training, validation, and test sets, respectively. We trained the model for 1000 epochs using a batch size of 50, a learning rate of 0.01, L2 regularization λ = 1e-3, and 1% learning rate decay every 50 epochs. During training, the input torques were normalized to the range [0, 1] but the outputs were not transformed. 



 §.§ Details for Experiment 2: Bouncing Ball COR Tuning

For both datasets, we trained TuneNet for 200 epochs, using a batch size of 50 and a learning rate of 1e-2, with learning rate decay of 1% per 5 epochs. The L2 normalization constant λ is set to 0.01. During training, the input and output channels were normalized to the range [0, 1]. 

For the Obs case, the visual OpenCV tracker uses hue, saturation, and value windows to threshold a camera image and isolate an object. It then calculates the y pixel position of the ball in each frame and normalizes the image pixel positions to the range [0, 1]. For each randomized simulation render, the PyBullet camera was placed at random polar coordinates r ∼U(5m, 10m), θ∼U(0, 2π), z ∼U(5m, 8m), and aimed at the point (0, 0, 2m). 



  §.§.§ Baseline Implementation Details

For CMA-ES, we use the open-source package [<https://github.com/CMA-ES/pycma>]. The inputs to CMA-ES are identical to those provided to TuneNet, with the initial proposed physics parameters being used as the initial guess for the CMA algorithm. The CMA tolerance was set to 0.1.

For Greedy Entropy Search (EntSearch in this paper), we re-implemented the algorithm provided in <cit.>. The underlying Gaussian Process (GP) sampling was implemented using the open-source Python package [<http://github.com/SheffieldML/GPy>], and we used an RBF GP kernel. Again, the initial proposed physics parameters were used as the initial guess for the algorithm. We discretize the parameter space into 50 bins, and use a gaussian process sampling population size of n=100. Because we do not calculate the value function for each policy, we cannot use the value as the stopping criterion as in <cit.>. Instead, we stop iterating when the predicted parameter value does not change for two consecutive timesteps. This stopping parameter was determined empirically for our experiment after being shown to outperform two other stopping criteria: no stopping (which performed poorly because of noise in the GP sampling), and stopping after the parameter estimate changed by less than a threshold ϵ > 0.

The initial guesses and simulated outcomes supplied to both CMA-ES and Greedy Entropy Search were identical to the inputs supplied to TuneNet, including all normalization transformations applied to the data.

