A convolutional neural network for end-to-end driving in virtual track, using TensorFlow and Keras.
Comma.ai's approach to Artificial Intelligence for self-driving cars is based on an agent that learns to clone driver behaviors and plans maneuvers by simulating future events in the road. This paper illustrates one of our research approaches for driving simulation. One where we learn to simulate. Here we investigate variational autoencoders with classical and learned cost functions using generative adversarial networks for embedding road frames. Afterwards, we learn a transition model in the embedded space using action conditioned Recurrent Neural Networks. We show that our approach can keep predicting realistic looking video for several frames despite the transition model being optimized without a cost function in the pixel space.READ FULL TEXT VIEW PDF
Autonomous driving is one of the most recent topics of interest which is...
Predictions of driver's intentions and their behaviors using the road is...
Expert human drivers perform actions relying on traffic laws and their
In this paper, we train a recurrent neural network to learn dynamics of ...
This work addresses our research on driving skill modeling using artific...
We present a new two-stage pipeline for predicting frames of traffic sce...
The ability to accurately predict and simulate human driving behavior is...
A convolutional neural network for end-to-end driving in virtual track, using TensorFlow and Keras.
Deep Learning Project to Teach a Car to Drive Autonomously Using Only Camera Images.
Self-driving cars are one of the most promising prospects for near term Artificial Intelligence research. The state-of-the-art of this research leverages large amounts of labeled and contextually rich data, which abounds in driving. From a complex perception and controls perspective, the technology to correctly solve driving can potentially be extended to other interesting tasks such as action recognition from videos and planning. An approach for self-driving cars that is economically attractive while still expanding the AI frontier should be based on vision, which is also the main sensor used by a human driver.
Vision based controls and reinforcement learning had recent success in the literature    mostly due to (deep, recurrent) neural networks and unbounded access to world or game iteraction. Such interactions provide the possibility to revisit states with new policies and to simulate future events for training deep neural network based controllers. For example, Alpha Go 
used deep convolutional neural networks to predict the probability of winning the game from a given state using the outcomes of several games, lots of which were playing but previous iterations of Alpha Go itself. The Go game engine was also used for simulating possible unfoldings of the game and Markov Chain Tree Search. For learning to play Torcs or Atari  using only the game screen, it was also necessary to use several hours of game play.
For the controls problems where unbounded iteraction of a learning agent with the world is not easily affordable there are two possible solutions. The solutions are to either hand code a simulator or to learn to simulate. Hand coding a simulator involves domain expertise for defining rules of physics and modelling the randomness of the world. But for most cases, such expertise already encompass all the information for posing the related controls problem, for example flight simulators , robot walking , etc.
Here instead we focus on learning to simulate aspects of the world from examples of a human agent. We focus on generating video streams of a front facing camera mounted in the car windshield. Previous successful approaches for learning to simulate for controls were based on state space representations of the agent physics . Other vision only models focused on low dimensional  or videos with simple textures, such as those of Atari games  . Texture rich approaches were based on passive video prediction for action recognition  without the possibility of an external agent modifying the future of the video and without generating a compact representations of the data.
This paper contributes to this learned video simulation literature. No graphics engine or world model assumptions are made. We show that it is possible to train a model to do realistic looking video predictions, while calculating a low dimensional compact representation and action conditioned transitions. We leave controls on the simulated world for future work. In the next section we describe the dataset we used to study video prediction of real world road videos.
We are publicly releasing part of the driving data used in this paper. The dataset has the same video and sensors used in the comma.ai self-driving car test platform.
We mounted a Point Grey camera in the windshield of an Acura ILX 2016, capturing pictures of the road at 20 Hz. In the released dataset there is a total of 7.25 hours of driving data divided in 11 videos. The released video frames are
pixels regions from the middle of the captured screen. Beyond video, the dataset also has several sensors that were measured in different frequencies and interpolated to 100Hz. Example data coming from sensors are the car speed, steering angle, GPS, gyroscope, IMU, etc. Further detail about the dataset and measurement equipment can be found online in the companion website.
We also record the time stamps at which these sensors were measured and the time stamps the camera frames were captured. In our production pipeline the measurement times and simple linear interpolation are used to sync the sensors and camera frames. We are releasing the raw sensors and camera frames in HDF5 files for easy to use in machine learning and controls software.
In this paper we focus on the camera frames, steering angle and speed. We preprocessed the camera frames by downsampling them to and renormalizing the pixel values between -1 and 1. Sample images of this transformed dataset are shown in Fig. 1.
In the next section we define the problem investigated in this paper.
Let denote the -th frame of the dataset. denotes a frames long video. These frame are associated with control signals ,
corresponding to the ego speeds and steering angles of the car. Learning to simulate the road can be defined as estimating the functionthat predicts .
Note that this definition is high dimensional and the dimensions are highly correlated. In Machine Learning problems like those are known to converge slowly or underfit the data . For example, previous work  showed that when using convolutional dynamic networks without proper regularization, the model simply learns a transformation close to the identity while still getting low cost scores due to correlations in time. Previous approaches learned the function directly, but were demonstrated only in very simple, artificial videos . Recently, it was shown   that it is possible to generate videos with complex textures, but the referred work did not address the problem of action conditioned transitions and they do not generate a compact intermediate representation of the data. In other words, their models are fully convolutional with no downsampling and no low dimensional hidden codes. We believe that compact intermediate representations are important for our research because probabilities, filtering, and consequently controls, are ill defined in very high dimensional dense spaces .
As far as we know, this is the first paper that tries to learn video predictions from real world highway scenes. As such, in this first paper, we decided to learn the function in a piecewise manner, so we could debug its parts separately. First we learned an autoencoder to embed the frames into a Gaussian latent space , where the dimensionality 2048 was chosen experimentally and the Gaussian assumption enforced with variational autoencoding Bayes . This first step simplified the problem from learning transitions directly in the pixel space to learning in the latent space. Beyond that, assuming that an autoencoder is correctly learned respecting the latent space Gaussianity, we can generate realistic looking videos as long as the transition model never leaves the high density region of the embedding space. This high density region is a hypersphere of radius
, which in its turn is function of the dimensionality of embedding space and variance of Gaussian prior. We go into the details of the autoencoder and the transition model in the next section.
Due to the problem complexity we decided to learn video prediction with separable networks. We leave investigations of the end-to-end approach for future work. The proposed architecture is based on two models: an autoenecoder for dimensionality reduction and an action conditioned RNN for learning the transitions. Our complete model is depicted in Fig. 2.
To learn the data embedding we chose a model that enforced the probability distribution of the latent space to be Gaussian. Specially to avoid discontinuous regions of low probability inside a hypersphere centered in the origin. Such discontinuities could make it harder to learn a continuous transition model in the latent space. Variational autoencoders and related work   had recent sucess learning generative models with Gaussian priors in the latent and original data space. Unfortunately, the Gaussian assumption in the original data space does not hold for natural images and VAE predictions usually look blurry (see Fig. 3). On the other hand, generative adversarial networks (GAN)  and related work   learn the generative model cost function alongside the generator. They do so by alternating the training of generative and discriminator networks. The generative model transforms samples from the latent space distribution into data from a desired dataset. The discriminator network tries to tell samples from the desired dataset from images sampled by the generator. The generator is trained to ”fool” the discriminator, thus the discriminator can be considered a learned cost function for the generator.
For our purposes we need to learn not only the generator from the latent to the road images space. But also an encoder from road images back to the latent space. We need to combine VAE and GANs. Intuitively, one could simply combine the VAE approach with a learned cost function. In the literature Donahue et. al  proposed bidirectional GANs that learns both generation and encoding as bijective transformations. Lamb et. al. 
proposed discriminative generative networks that uses distances between features of a previously trained classifier as part of the cost function. Finally, Larsen et. al.
proposed to train a VAE alongside a GAN, where the encoder optimizes both the Gaussian prior in the latent space and the similarity between features extracted by the GAN discriminator network. The generator receives as inputs random samples from the latent space distribution and outputs of the encoder network. The generator is optimized to fool the discriminator and minimize the similarity between original and decoded images. The discriminator is still only trained to tell fake from legit images.
We used Larsen et. al.  approach to train our autoencoder. In Fig. 2 we show the schematic diagram of this model as part of our architecture. According to  the encoder (), generator () and discriminator () networks are optimized to minimize the following cost function:
In (1) is the Kullback-Liebler divergence between the distribution of the encoder outputs, , and a prior distribution, . This is the same VAE regularizer. Here the prior distribution is is a Gaussian and we use the reparametrization trick  to optimize that regularizer. Thus, during training we have and at test time , where and are outputs of the encoder network and
is a Gaussian random vector with the same number of dimensions asand .
is an error calculated using , the hidden activations of the -th layer of the discriminator network, . The activations are calculated using a legit image and its corresponding encoded-decoded version . Assuming and , we have . During training, is considered constant with respect to this cost to avoid trivial solutions.
Finally, is the generative adversarial network cost . That cost function represents the game between and . When training , both and are kept fixed and we have
is another random variable. The first r.h.t of (2) represents the log-likelihood of recognizing legit samples and the other two terms represents its log-likelihood to tell fake samples generated from both random vectors or codes . When training , we keep both and fixed and we have
which accounts for being able to fool . Following , the gradient of w.r.t is considered zero during training.
We trained this autoencoder for 200 epochs. Each epoch consisted ofgradient updates with a batch size of . Batches were sampled randomly from driving data as described in the previous section. We used Adam for optimization . The autoencoder architecture followed Radford et. al. 
, with the generator made of 4 deconvolutional layers each one followed by batch normalization and leaky-ReLU activations. The discriminator and encoder consisted of convolutional layers where each but the first layer was followed by batch normalization. The activation function was ReLU.is the output of the 3rd convolutional layer of the decoder, before batch normalization and ReLU are applied. The output size of the discriminator network is 1 and its cost function was binary cross-entropy. The output size of the encoder network is 2048. This compact representation is almost 16 times smallet than the original data dimensionality. For network sizes and further details, please check Fig. 2 and the companion code of this paper. Sample encoded-decoded and target images are shown in Fig. 3.
After training the autoencoder, we fix all its weights and use as preprocessing step for training the transition model. We describe the transition model in the next section.
After training the autoencoder described above we obtain the transformed dataset applying . We train to represent the transitions in the code space:
where are trainable weights, is the hidden state of the RNN and are the concatenated control speed and angle signal. We leave LSTMs, GRU and multiplicative iterations between and for future investigations. The cost function for optimizing the trainable weights is simply the mean square error:
It is easy to see that (5) is optimal because we impose a Gaussian constraint in the distribution of the codes
when training the autoencoder. In other words, MSE equals up to a constant factor the log-likelihood of a normally distributed random variable. Given a predicted codewe can estimate future frames as .
We trained a transition model with sequences of length of 15 frames. We used teacher forcing in the first 5 frames and fed the outputs back as new inputs in the remaining 10 frames. In other words, were calculated using and fed as input. We fed the outputs back as input. In the RNN literature feeding outputs back as input is informally referred as RNN hallucination. It is important to note that we consider the gradient of the outputs equal to zero when they are fed back as inputs to avoid trivial solutions.
We spent most of the effort of this research investigating autoencoding architectures that could preserve the road texture. As mentioned before we studied different cost functions. Although results were similar in terms of MSE, a learned cost function using generative adversarial networks had the most visually appealing results. In Fig. 3 we show decoded images with models trained using two different cost functions. As expected, MSE based neural networks generate blurred images. The main issues for our purposes is that blurring connects the lane marks into a single long lane. Also blurring reconstruction does not preserve leading car edges. This is not desired for several reasons, the main one is that it gets rid of one of the main clues used for visual odometry and leading car distance estimation. On the other hand MSE learns to generate curved lane markings faster than the adversarial based model. It is possible that learning to encode pixels with the car steering angle information should avoid this problem. We leave this investigation for future work.
Once we obtained a good autoencoder, we trained the transition model. Results of predicted frames are shown in Fig. 4 . We trained the transition model in 5Hz videos. The learned transition model keeps the road structure even after 100 frames. When sampling from the transition model with different seed frames we observed simulations of common driving events such as passing lanes, approaching leading cars and leading cars moving away. The model failed to simulate curves. When we initialized the transition model with frames of driving on a curve, the transition model quickly straightens the lanes and goes back to simulate going forward. Nevertheless, it is promissing that we could learn transitions for video generation without explicitly optimizing a cost function in the pixel space. Also, we believe that even more realistic simulations will be possible with more powerful transition models (deep RNNs, LSTM, GRU) and contextual encoding (sensor fusion of pixels plus steering angle and speed). The dataset we are releasing with this paper has all the sensors necessary to experiment with this approach.
This paper presented comma.ai initial research on learning a driving simulator. We investigated video prediction models based on autoencoders and RNNs. Instead of learning everything end-to-end here we first trained the autoencoder with generative adversarial network based cost functions to generate realistic looking images of the road. We followed up training an RNN transition model in the embedded space. Results from both autoencoder and transition model look realistic but more research is needed to successfully simulate all the relevant events for driving. To stimulate further research on this subject we are also releasing a driving dataset with video and several sensors such as car speed, steering angle, etc. We also release the code to train the networks we investigated here.
Proceedings of the 15th annual conference on Genetic and evolutionary computation, 2013.