Safe end-to-end imitation learning for model predictive control

03/27/2018 ∙ by Keuntaek Lee, et al. ∙ Georgia Institute of Technology 0

We propose the use of Bayesian networks, which provide both a mean value and an uncertainty estimate as output, to enhance the safety of learned control policies under circumstances in which a test-time input differs significantly from the training set. Our algorithm combines reinforcement learning and end-to-end imitation learning to simultaneously learn a control policy as well as a threshold over the predictive uncertainty of the learned model, with no hand-tuning required. Corrective action, such as a return of control to the model predictive controller or human expert, is taken when the uncertainty threshold is exceeded. We validate our method on fully-observable and vision-based partially-observable systems using cart-pole and autonomous driving simulations using deep convolutional Bayesian neural networks. We demonstrate that our method is robust to uncertainty resulting from varying system dynamics as well as from partial state observability.



There are no comments yet.


page 2

page 9

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

I Introduction

As the deployment of deep neural networks as controllers for physical robotic systems becomes more prevalent, the issue of safety within artificial intelligence becomes an increasingly important concern. Recently the use of end-to-end imitation learning to develop neural network control policies has surged in popularity, due in large part to the ease with which deep models can learn complex dynamics and infer global state from local data while bypassing the need for significant parameter tuning. In contrast, traditional approaches to vision-based control rely on methods such image segmentation and object detection, classification, labeling, and filtering; often, these methods require significant engineering and tuning. In addition, collecting the large datasets required by these methods is a difficult process, and it is often impossible to collect and process a dataset in a manner that is complete enough to account for every possible scenario.

The challenge, therefore, is to design a system capable of taking an appropriate action or making an appropriate prediction given novel data at test time, ideally with as little hand-tuning as possible. The ability to effectively handle novel data is key to introducing safety in intelligent control and is a particular weakness of current end-to-end methods of control.

It is easy to imagine situations in which novel data could be presented to a learned model at test time. For example, malfunctioning sensors could pass unusual signals to a control system; changes in the environment could significantly affect system dynamics, such as in the case of robots that move from a smooth floor to a carpeted area; or, as is our motivation in this paper, a camera-based controller could encounter obstacles of a heretofore unseen type.

(a) Top: A sequence of input images for training. Bottom: A sequence of input images with novel obstacle at test time

Output mean and variance of control

Fig. 1: Increased output variance from the Bayesian neural network due to a novel test-time input

Bayesian models – that is, models that output predictive distributions, rather than point estimates – have long been considered invaluable in machine learning for a number of reasons. An estimate of model uncertainty can help to minimize risk, develop rejection criteria, compensate for extreme priors, and combine models

[1]. In the context of end-to-end learning, especially for autonomous vehicles and mobile robots, uncertainty estimates provide an easily interpreted safety measure. By training models that can provide predictive uncertainty, we obtain a valuable indication of whether the model is able to produce a usable output; if it is not – that is, if the uncertainty is high (Fig. 1) – we can take an appropriate action to compensate for the model’s lack of knowledge. In the context of end-to-end learning for autonomous driving such an action could include, for example, the return of control to a human driver.

Deep neural networks (DNN), popular due to their ability to model extremely complex functions, have enjoyed great success in a number of fields, including model-free reinforcement learning and model-based control. However, while deep networks have been a revolutionary change to many engineering applications, their particular weakness is that they provide point estimates instead of a predictive distribution. While undeniably effective, the use of DNNs results in a loss of the properties that make Bayesian methods so powerful. As described in detail below, recent work on efficient deep Bayesian neural networks has helped to bridge this gap.

In this paper, we present an approach that combines deep end-to-end learning with Bayesian networks to learn high-speed model predictive control (MPC) while exploiting the predictive uncertainty of a Bayesian convolutional network to provide a measure of safety. Our approach combines MPC with imitation learning and reinforcement learning (RL) methods to successfully perform complex tasks in both fully-observable and vision-based partially-observable scenarios while effectively handling novel data at test time. Our approach is fully end-to-end; aside from the initial selection of network structure, comparatively little engineering or hand-tuning is required for success.

The rest of the paper is organized as follows: In Section II, we discuss work related to our method that appears in the literature. Section III briefly introduces key background material. In Section IV, we define the problem of safe learning for MPC and present our solution. Results of experiments are presented in Section V, followed by a discussion of future directions in Section VI. We conclude with Section VII.

Ii Related Work and Contributions

Imitation and end-to-end learning are popular in the literature for a variety of tasks including the control of autonomous robots. The DAgger meta-learning algorithm and its variants are popular due to the fact that these methods provide a regret bound that is linear in the time horizon [2], contrary to earlier approaches with larger worst-case regret. Earlier work, based on DAgger, specifically addressed the problem of learning a MPC policy for high-speed autonomous navigation [3], but did not account for safety and robustness in the learned model. In [4]

, the authors develop an extension to the DAgger algorithm for end-to-end learning of MPC sequence policies with structured recurrent neural networks but do not address the problem of safe MPC. In addition, partially-observable states and vision-based tasks are not considered. In contrast, our work imposes no algorithmic structure on the neural network, avoids recurrent networks and the resulting difficulties in training, and successfully completes complex tasks without full state observability. The NVIDIA PilotNet project

[5] does consider vision-based vehicle control with end-to-end learning and learns to recognize diverse obstacles and objects, but is not a probabilistic method and does not seem to explicitly handle truly novel test inputs. Combining uncertainty measurement into the autonomous driving task, [6] investigated a predictive approach for collision risk assessment; however, this is a classification task rather than a regression task and cannot provide a learned controller for continuous action spaces.

The work most similar to our own is the DropoutDAgger approach [7], a probabilistic extension to DAgger which uses the Dropout method of Bayesian approximation first presented in [8] to obtain a predictive distribution from a neural network. The output variance is then used as a threshold to determine whether to return control to an expert controller, similar to the method presented herein. However, in [7]

both the dropout probability and the uncertainty threshold are selected manually; the tasks and experts considered are based on RL; and the case of partially observable environments and vision-based tasks is not considered at all. In contrast, our work uses more principled methods to select dropout probabilities and the uncertainty threshold work. In addition, we work in the MPC task domain rather than in the RL domain, which is more challenging due to the requirements for reactive, high-frequency control but is well-suited to deployment on real autonomous vehicles. Finally, our method specifically addresses vision-based tasks using Bayesian convolutional neural networks.

Given the prior work in the area of end-to-end learning for control the contributions of this paper are summarized as follows:

  1. We introduce the DropoutVGG Net, which combines VGG Net [9], the dropout technique for Bayesian approximation [8], and Concrete Dropout [10] for selection of the dropout probabilities in our neural network.

  2. We use Cross-Entropy RL to optimally select an uncertainty threshold for return of control from a learned model to a MPC expert policy.

  3. Our formulation considers both the aleatoric and epistemic uncertainty of our neural network policy.

  4. We demonstrate that our method is robust to uncertainty from varying system dynamics as well as uncertainty from partial state observability.

  5. Use a model predictive controller as expert for a demonstration and successfully learn safe MPC using end-to-end learning with a Bayesian convolutional neural networks.

  6. We demonstrate our results on cart-pole balancing and autonomous driving tasks in both fully and partially observable cases.

Iii Technical Background

In this section we briefly review key ideas used in our method. Our formulation consists of an autonomous expert model predictive controller, a deep Bayesian neural network policy trained with imitation learning, and a reinforcement learning module to optimize the uncertainty threshold.

Iii-a Differential Dynamic Programming for Trajectory Optimization

Iterative LQG/Differential Dynamic Programing (iLQG/DDP) [11] is a dynamic programming method which provides locally optimal solutions to the optimal control problem. When used as the underlying optimizer for a model predictive controller, DDP provides real-time performance for complex, high-speed tasks; it also provides improved robustness relative to other methods due to the ability to calculate and return explicit trajectory-local feedback and feedforward gains.

Let the state of the system under consideration be with controls . We then consider the following optimal control problem.


Here is the value function, the time horizon is , and we have terminal cost with running cost . Let nominal state and control sequences be given by ) and , respectively, so that we can define the state and control sequence updates and such that and . DDP provides an efficient iterative method to compute the trajectory updates. To begin, note that discretization and linearization of the dynamics about the nominal trajectory results in the discrete, time-varying linear system


where we have defined and . Applying the Bellman principle to 1 and discretizing, we obtain


The prime notation on and derivatives indicates evaluation at . Taking a quadratic expansion of the right hand side of 4 and then noting that and have a linear relationship so that we can perform the minimization in 4 over , we obtain the optimal control update law


where the first and second derivatives of are


It is important to note that the optimal control update is given by a feedback control law with feedback gain and feedforward gain .

For each iteration of DDP, updates along a trajectory are computed using the dynamic programming methodology, starting at the terminal time and computing optimal updates backward along the trajectory. The equations for this backward pass are computed by substituting 5 into the quadratic expansion of 4 and grouping terms of corresponding order to obtain


After the backward pass is complete, a forward pass finds the new nominal control and state trajectories using the computed gains and the nonlinear dynamics, respectively. The backward and forward passes are iterated until the maximum number of iterations is exceeded or until convergence. DDP is summarized in Algorithm 1 . In our work, we apply DDP as part of the model predictive control algorithm by performing a small number of DDP iterations at each time step, applying the first control of the resulting optimal sequence to the plant, obtaining a new state estimate, and repeating until the task is complete.

Input :  : initial state, : control sequence,
: time horizon, : time step size,
: max iterations, : learning rate
: transition function,
: running and terminal cost functions
Output :  : optimal control sequence,
: optimal state trajectory,
: control gains
1 for  to  do
3       Calculate , at using 3
4 end for
5for  to  do
9       for  to  do
10             Calculate and derivatives at using 6
11             Calculate and at
12             Calculate and derivatives at using 7 - 9
14       end for
15      for  to  do
20       end for
21      return , , ,
22 end for
Algorithm 1 Differential Dynamic Programming

Iii-B Epistemic and Aleatoric Uncertainty

As indicated in [12], uncertainty in machine learning models can come from two sources: incomplete data and incomplete knowledge of the environment. The former, called epistemic uncertainty is the result of a data set that is either not large enough or does not cover enough of the “search space”. Such uncertainty could be explained away by access to unlimited data and can be reduced by the collection of additional data. The latter source, called aleatoric uncertainty, is the result of our inability to completely sense all aspects of the environment. While such uncertainty could not be explained away with access to more data – or even with access to unlimited data – it could be explained away with access to unlimited sensing.

Note that in both cases, completely explaining away the uncertainty requires access to something we cannot possible obtain, i.e., either unlimited data or unlimited sensing capability. It is therefore useful to consider using these sources of uncertainty in an engineering or machine learning context. Epistemic uncertainty measures what our model doesn’t know; given data, we should be able to train a model that can output this type of uncertainty. Aleatoric uncertainty measures noise that is inherent in the environment, i.e., it measures what cannot be explained by data. Again, given data, we should be able to train a model to output this type of uncertainty as well. In principle, the total predictive uncertainty would be the combination of the two. As shown in [12], it is sometimes possible to use just one of these measures to develop a reasonable model; however, the more principled approach of combining these predictive uncertainty estimates often results in a superior model.

Iii-C Bayesian Approximation with Dropout

Bayesian learning methodologies in and with neural networks have a long history [13]. Currently, at least two popular methods of Bayesian learning with neural networks appear frequently in literature. The first, which essentially produces predictive distributions resulting from a distribution over neural network structure, is the Dropout approach introduced in [8]

. The second, in which predictive distributions are obtained due to probability distributions over network weights, is the Weight Uncertainty approach introduced in

[14]. The two approaches are similar in a number of ways, not least of which is the need to impose a variational approximating distribution over network weights and perform Monte Carlo sampling. We discuss the dropout technique, which we elect to use in our work; the alternative approach requires doubling the number of parameters in the network, making it difficult to use for real-time MPC for vehicles with only onboard computation given very large convolutional neural networks.

Dropout has traditionally been used as a regularization method to prevent overfitting while training DNNs [15]

. It does so by effectively annihilating connections between neurons, resulting in a network that is much simpler, i.e., has fewer effective model parameters and is thus less prone to overfitting training data. This is achieved by randomly sampling a binary

dropout mask for each layer

from a Bernoulli distribution with probability of success

and applying this mask to the weights of layer . For example, a simple two-layer feedforward network is represented by the equation



is an component-wise activation function and the network has outputs

, inputs , weight matrices and , and bias (output bias has been neglected for clarity). Binary dropout masks and can be sampled component-wise from Bernoulli distributions with success probability and for layers and , respectively, and applied to the network resulting in a structurally simpler model with some connections removed.


Dropout as a method of Bayesian approximation differs from the traditional approach in two respects. First, as presented in [8], dropout in this context is randomly applied at test time as well as during training. This means that the predictive output for a single forward pass with a single input is the result of a network that is structurally simpler than the original. Since the random nature of the dropout masks means that the same test-time input will result in a different output each time the input is passed through the network, several samples of the output corresponding to the same input result in a distribution that estimates epistemic uncertainty. In addition, the dropout probability for each layer can be learned along with the network weights during training using the Concrete Dropout approach [10].

Aleatoric uncertainty is not learned via sampling, but instead learned by using the so-called heteroscedastic loss function (described below) and splitting the output layer of the network (Fig. 2) such that one channel is trained to output a predictive mean and the other the aleatoric uncertainty [12]. By combining the uncertainty obtained via sampling with that obtained during training, an accurate representation of total model uncertainty is obtained.

Iii-D Batch Imitation Learning

Let be the state, observation, and admissable control spaces of the task under consideration, respectively. Our goal is to determine a neural network policy that is able to minimize the expected accumulated cost over a discrete finite time horizon :


where , , and running (immediate) cost for consistency with the notation introduced earlier.

is the joint distribution of

, , and for the policy for .

This cost may be unavailable or impossible for a learned model to optimize directly. Instead, imitation learning assumes that an expert capable of optimizing this cost is available. The goal of imitation learning is to learn a policy that minimizes the deviation between the cost of the learned model and that incurred by the expert policy


where and

denotes the selected neural network policy. In batch imitation learning, as used in this work, this is reduced to a supervised learning problem in which the model is trained to learn from data, consisting of observation-action or state-action pairs, generated by the expert.

End-to-end learning offers a number of advantages; our primary motivation in this work is that end-to-end methods avoid the need for burdensome manual engineering and unprincipled parameter tuning.

Iv Safe End-to-End Learning for Model Predictive Control of Autonomous Vehicles

We wish exploit end-to-end learning to train a neural network policy to perform MPC for autonomous vehicle control. The trained model must be safe; in our framework, safety is introduced by returning control to an expert controller when the learned model is unable to produce a suitable output. Such a framework is useful for long-term missions in which it is infeasible or impossible to continuously use an expert. This could be the case, for example, when the power and computational requirements of an iterative optimal controller or the natural limitations of a human expert become a burden on the system.

As noted above, our probabilistic policy is a deep Bayesian neural network using the dropout technique. We apply dropout to all weight-containing layers in our models. At test time we perform Monte Carlo sampling of the output by repeatedly passing in the same input, thereby estimating epistemic uncertainty by calculation of the sample distribution. The linear output layers of our models are split, with one channel trained to calculate aleatoric uncertainty. In order to do so, we train the model with the heteroscedastic loss introduced in [12]


where the network predicts and the true target is . We recognize this as being essentially equivalent to the scalar Gaussian log likelihood of independent data samples.

Our expert controller in all tasks considered herein is a real-time MPC controller operating between 40Hz and 60Hz which applies the DDP trajectory optimization algorithm in a receding horizon fashion. In all cases, the MPC-DDP expert has access to full state information, i.e., is assumed to have perfect knowledge of the state during the generation of training data. The learned model may have only partial state information depending on the specific task, each of which is discussed in subsequent sections.

In keeping with the motivation to avoid manual selection of model parameters and hyperparameters, the dropout probability for each layer is trained along with network weights using the Concrete Dropout approach. In contrast to competing methods, our framework also avoids hand-tuned specification of the uncertainty threshold above which the MPC-DDP expert regains control of the system.

Iv-a Reinforcement Learning of the Uncertainty Threshold

High predictive uncertainty generated by the Bayesian network is indicative of a novel test-time input, i.e., data of a type very different from the distribution of the training data. When the output uncertainty is high, the learned model is incapable of producing a useful control; we therefore return control of the system to the MPC-DDP controller. The threshold above which the switch from learned model to expert controller is manually selected in earlier works; here, we propose selecting the threshold in a principled manner with reinforcement learning.

In imitation learning, an expert will generally be more successful and obtain a larger reward (or lower cost) than a learned model for the same task. As a result, naive application of RL to learn the uncertainty threshold will result in a policy that immediately hands control to the expert, i.e., it will learn a threshold value of 0 so that the expert’s action is always queried for maximum reward. Our approach therefore encourages the use of the learned model for as long as possible.

The choice of RL algorithm is important; our choice is motivated by the observation that the switch from the Bayesian neural network policy to the MPC-DDP expert is best viewed as a rare discrete event. The Cross-Entropy Method (CEM) [16] applied to reinforcement learning is well-suited to such cases. We use CEM to attempt optimization of the uncertainty threshold for switching from the neural network policy to the MPC-DDP expert as summarized in Algorithm 2.

Our results, discussed below, demonstrate that our framework converges to a threshold that allows the learned model to perform the task while switching back to the expert while still allowing the expert enough time to recover from or handle the unusual inputs.

Input :  : initial state,
: episodes & rollouts per episode,
: maximum time steps for task completion,
: initial distribution of the threshold,
: immediate & terminal reward functions,
: min & max number of candidates,
: set of best candidate solutions,
: NN and MPC-DDP policies
Output :  : optimized mean value of the threshold,
: sum of rewards
1 for  to  do
2       Reset the environment and
4       Obtain samples
5       for  to  do
6             ,  actor
7             Execute actions from until an adversarial input occurs at time step
8             for  to  do
9                   Execute actor action
10                   actor if uncertainty
13             end for
15             Increment if
16             sort by descending
20       end for
21      Repeat from Step 3 if
24 end for
return ,
Algorithm 2 Cross-Entropy Method to optimize switching uncertainty threshold

V Experiments

We validate our framework for safe learning of model predictive control on two different tasks:

  1. Cart-pole swing-up with full and partial state observability

  2. Vision-based rally car driving with obstacle avoidance

For vision-based tasks, we introduce the DropoutVGG Network. This Bayesian extension to VGG Net [9] uses the dropout technique as described above. In addition, we split the output layer and train the network to output aleatoric uncertainty as shown in Figure 2.

Fig. 2: DropoutVGG Net

For all tasks, we provide positive terminal reward in the CEM algorithm if the task was completed successfully by the Bayesian network model or by the MPC-DDP controller.


In order to encourage use of the learned model, we provide a positive immediate reward for every time step for which the learned model is used.


V-a Cart-Pole Swing-Up

For the cart-pole swing-up task, the MPC-DDP expert was provided a system dynamics model identical to that used in the popular OpenAI Gym simulator [17]. This system consists of a weighted pole balanced on a cart. The goal is to swing up and balance the pole only by applying a horizontal force to the cart. The terminal reward is typical of that used in OpenAI Gym; that is, we provide the reward in 15 if at the terminal time :


where is the horizontal position of the cart and is the pole angle.

Fig. 3: Feedforward Bayesian network with dropout

V-A1 Fully Observable Case

In fully observable case, both the expert and the Bayesian neural network have perfect information regarding the complete system state . A convolutional model is not required as no vision-based control is performed; we instead use a simple feedforward Bayesian network (Fig. 3).

After training the neural network with the DDP expert, we allow the learned model to attempt the task. The mass of the system is changed at an arbitrarily selected time to create a disturbance; the learner must revert control to the DDP controller before the angle of the pole falls outside the required limits and must do so in time for the DDP controller to recover.

(a) Total rewards per CEM episode
(b) Threshold per CEM episode
(c) Changed the cart mass to 0.1.
(d) Changed the cart mass to 0.2.
(e) Changed the cart mass to 0.3.
Fig. 4: Results of learning a switching threshold for the cart-pole swing-up task in the fully observable case for three different scenarios: a change of the cart mass to 0.1, 0.2, and 0.3 from 1.0, respectively. Bottom figures show success/failure trials per sample of the uncertainty threshold where we see that learned optimal thresholds are located between the success and failure margins.

V-A2 Partially Observable Case

In the partially observable case, the neural network can estimate and but velocities and are not directly accessible. DropoutVGG is trained with inputs consisting of (third-person view) gray-scale images of the cart-pole system and observations of the expert control; the learned model must use image information to infer the velocity components of the state in order to produce a usable control signal.

(a) Training data
(b) Test with adversarial inputs
Fig. 5: Partially observable case of cart pole system.

The goal and limits of the task are as the same as in the fully observable case. In this case, however, a disturbance is created when the input image is randomly corrupted with the addition of a new object that was not present in the training data.

(a) Total rewards per CEM episode
(b) Threshold per CEM episode
(c) Total reward per uncertainty threshold
(d) Success per uncertainty threshold
Fig. 6: Results of learning a switching threshold for a cart pole swingup task in partially observable case. Interpretation is similar to Fig. 4.

Interestingly, we found that the predictive uncertainty of the neural network grows when larger objects corrupt the input image. Tests with color images also showed extreme sensitivity to the color of the new object; we hope to investigate this further, but for our current results the image was converted to grayscale before being passed to the neural network.

V-B Autonomous Navigation and Obstacle Avoidance

(a) AutoRally simulation
(b) Onboard view from the simulated vehicle
Fig. 7: AutoRally simulation environment

Autonomous driving is a more realistic and significantly more complex task than cart-pole swing-up. Here, we demonstrate the success of our framework on the autonomous navigation and obstacle avoidance task using the simulator provided by the AutoRally project [18]. This software 7 simulates driving a 1/5th scale autonomous vehicle on a track and is capable of providing simulated color images from onboard cameras. We again use DDP as the expert controller; in this experiment, the DDP controller uses a data-driven adaptive dynamics model based on Sparse Spectrum Gaussian Processes (SSGP) [19].

DropoutVGG is trained with observations consisting of pixel RGB images from the vehicle’s left camera as well as the corresponding steering angle produced by the MPC-DDP expert as it navigates around the track at a speed of 5 m/s. The goal is to train the network to learn to steer the vehicle; we do not learn the throttle (acceleration) in this experiment. The learned model is not provided with any direct information about the vehicle state; it may only access the camera image. As usual, no disturbances or unusual inputs are given to the neural network in the training phase.

In the absence of unusual test-time inputs, the Bayesian network easily learns to steer the vehicle based only on vision. However, when a previously unseen obstacle comes into view (Fig. 1) the predictive uncertainty increases significantly, indicating potential failure of the learned model. Our method successfully trains the learned model to pass control back to the DDP expert in time to avoid the obstacle.

(a) Total rewards per CEM episode
(b) Threshold per CEM episode
(c) Total reward per uncertainty threshold
(d) Success per uncertainty threshold
Fig. 8: Results of learning a switching threshold for an autonomous navigation and obstacle avoidance task in partially observable case, only using images.

Vi Future Work

As demonstrated above, the dropout approach for Bayesian approximation is a good fit for safe end-to-end learning for control. However, sampling the network enough times to obtain accurate epistemic uncertainty estimates is time-consuming if done sequentially. It may be parallelized but this is difficult for networks with a large number of weights. We plan to investigate schemes for efficient sampling through Bayesian networks in a future work. On a more theoretical note, we found during our experiments with the AutoRally simulator that the predictive uncertainty increases far later than would be ideal; a promising avenue of research is to investigate recurrent or generative models capable of propagating predictive uncertainty into the future in order to obtain better behavior, especially in high-speed tasks. Another future direction is the extension of the current work to online imitation learning. As noted above, our current framework uses batch imitation learning, essentially reducing the problem to a simple supervised learning problem. However, as shown in [2], the DAgger algorithm and its variants can significantly reduce the regret bounds relative to this type of algorithm. We continue to investigate the best way to combine our framework – especially the RL component – with the DAgger methodology.

Vii Conclusion

We have presented herein a fully end-to-end framework for safe learning of model predictive control. Our approach successfully trains a Bayesian neural network to perform complex vision-based MPC with access to a dataset containing image observations and corresponding controls from an expert based on differential dynamic programming. This approach allows the learned model to effectively know when it will be unable to safely complete the task and return control to an expert capable of doing so. Our framework requires no manual parameter tuning; instead we propose the use of a reinforcement learning method to learn uncertainty thresholds in a principled manner. We validate our method on cart-pole swing-up and autonomous driving tasks.