Hello World: Realtime interactive training as an informative and performative tool
4.1 Introduction
In this thesis, the two key points that we prioritise when thinking about the design of our interactive generative systems, are Meaningful Human Control, as we describe in section 1.3: Meaningful Human Control; and Realtime Continuous Control, as we describe in section 1.4: Visual instruments: Realtime Continuous Control. In particular, we think of these systems that we are trying to build as visual instruments, where the user can be thought of as more of a performer that plays the system.
In the previous chapter, we examined two different approaches to this topic. The first of these studies looked at sketching, while the second looked at character-by-character generation of text. The second study that we presented, section 3.3: Realtime interactive text generation with RNN ensembles, achieved perfectly what we were hoping for, demonstrating the potential of such an approach. Our system provides both Meaningful Human Control, and Realtime Continuous Control. And we were able to gesturally conduct the generation of text, using our body in an expressive and performative manner, analogous to a visual instrument.
We began this inquiry in the previous chapter, working with data of relatively low dimensionality. Our MCTS agent selects actions from within a dozen or so options, and our interactive Char-RNN ensemble selects the next character from less than a hundred or so characters.
In this, and subsequent, chapters, we move onto and apply the same kind of thinking to data that has many orders of magnitude higher dimensionality. We work with pixel-based raster images.
In this chapter in particular, we investigate how image-based deep generative models learn. We develop a software system that performs realtime training on a live video feed, while allowing for the Realtime Continuous manipulation of a number of hyperparameters such as learning rate, momentum, gradient clipping thresholds, loss function and many more Footnote 1 . Observing the results of these hyperparameter manipulations, we are able to build a qualitative understanding of how they impact the training process.
Furthermore, an unplanned outcome of our system, is that it also provides great potential as a performative tool.
Manipulating hyperparameters in realtime while the model is training, produces aesthetically unique and interesting outputs, and effectively transforms the Deep Neural Network into a medium which we can play like a visual instrument.
In addition, the affordances granted by our software is not limited to the fact that we can manipulate hyperparameters in realtime while the model is training live. In fact the model is training on a live video feed. This introduces a second mode of interaction, a very expressive and performative mode of interaction. Namely, by manipulating our hands, body or objects in front of the camera while the model is training, we can observe the results this has on the system, and we can act accordingly. Any movements we make in front of the camera, effectively introduces new training examples into the training dataset. We can then make experimental gestures and movements in front of the camera, and observe how these new training examples influence the predictions that the model makes and the images generated as a result of this. Through this Realtime Continuous interaction with immediate feedback, we eventually build an understanding of how to meaningfully control this process, and we can leverage this new found knowledge and experience to use the system as a performative environment.
In this respect, combining both of these modes of interaction, we use our system not only for technical research, for building a qualitative understanding of the effects of hyperparameters or subtle changes to training examples. But we also used it for artistic, aesthetic and performative research. We will build upon this aspect of the software, focusing on these two modes of interaction that we just mentioned, more in the following chapter chapter 5: Learning to see: Digital puppetry through realtime video transformation.
Finally, due to the fact that our system demonstrates and sheds light on how Deep Neural Networks learn, and is especially accessible by a non-expert audience, the system itself has garnered interest from arts and cultural institutions. As a result, we have exhibited the system itself as an interactive video installation at events and venues including Ars Electronica (Linz, AT, 2017), International Documentary Film Festival Amsterdam / IDFA (Amsterdam, NL, 2017), and the Moscow Museum of Modern Art (Moscow, RU, 2018) (Fig. 4.1). The work has also been included in MIT's Open Documentary Lab docubaseFootnote 2.
4.2 Motivations
There are a few key moments that led to the development of this particular study that we present in this chapter.
In subsection 2.3.13: Hyperparameter search, we describe the importance of hyperparameters. These are variables that are not learnable via a typical training process, and they define or control the architecture of a DNN or various aspects of the optimisation process. These include variables such as the number of layers in a DNN, the activations functions and number of neurons in each layer etc. They also include variables such as the loss function or optimisation algorithm used, learning rate, momentum, gradient clipping thresholds, regulariser weights, and many many more.

An optimal configuration of hyperparameters is essential to ensure that training a DNN converges to a desired solution. However, as we mentioned, hyperparameters are not learnt via training, but have to be set manually. Typically, there are no clearly defined rules as to what values these hyperparameters should be set to. Instead, hyperparameter values are selected purely based on empirical experience, which may or may not be transferable from one domain or problem to another. For this reason, it is common to perform a hyperparameter search, whereby up to hundreds of models are trained on the same dataset, slightly varying hyperparameters by a small amount in each case. From these hundreds of models, the model which performs the best, i.e. produces the most accurate predictions on a validation dataset, is selected as the best model Footnote 3.
The difficulty and fragility of manual hyperparameter selection is a well known open problem in DL research. For this reason, under the umbrella of meta-learning, or learning to learn, researchers are investigating more robust, automated methods of hyperparameter selection (Andrychowicz et al., 2016; Finn et al., 2017; Zoph et al., 2018; Rusu et al., 2019).
In the meantime however, we are looking for ways to build a better qualitative understanding of how these hyperparameters affect training, and the solution that the model converges to. In particular, we are looking for ways of better understanding the effects of individual hyperparameters.
When appropriate, we do also use the “train hundreds of different models with randomised hyperparameters” approach. And while this may be the current best method for selecting the most quantitatively optimal model, we do not believe it is necessarily the best method for allowing a human to build a qualitative understanding of how the hyperparameters influence the outcomes. Based on our experience with visual instruments, including both the study that we presented in the previous chapter, and including our experience outside of the work that we present in this thesis, we believe that a system that provides Realtime Continuous Control, and allows for experimentation of parameters with immediate feedback, is an essential complement to build such a qualitative understanding.
Our curiosity in this direction is further reinforced by the results of the sketching MCTS agent that we discussed in the previous chapter. In particular, the capacity for the CNN classifier to provide so many false positives, led us to inquire more about how and what DNNs learn. This is already a very active area of research (Erhan et al., 2009; Simonyan et al., 2013; Zeiler & Fergus, 2013; Mahendran & Vedaldi, 2014; Dosovitskiy & Brox, 2015; Nguyen et al., 2015; Olah et al., 2017; Mordvintsev et al., 2018; Olah et al., 2018). And as we described in the previous paragraph, we believe that a system which allows Realtime Continuous experimentation will provide very valuable complementary insights.
Finally, at the risk of stating the obvious, the data that a model is trained on, defines what the model will learn, and will ultimately produce. Training a generative DNN on images of cats, will result in a model that produces images of cats; while training a generative DNN on images of dogs, will result in a model that produces images of dogs. This should come as no surprise. However, an interesting question arises when we consider much more subtle variations to the training examples that we provide to a model. In order to investigate this, we again seek a Realtime Continuous system that allows for subtle realtime manipulation of training examples, and provides immediate feedback.
On top of all of these, which we can summarise as technical points of inquiry, we have our usual additional agenda, which is to investigate deep visual instruments: new modes of performative, artistic expression, using Deep Learning models as a medium and instrument.
For all of these reasons, we develop the realtime training software that we describe in this chapter.
4.3 Background
The Deep Learning architecture that we use in this study, is a Variational Auto-Encoder (VAE) with Convolutional layers. The Convolutional layers provide the architectural details that makes the Neural Network suitable for 2D pixel-based image processing. We discuss these in more detail in subsection 2.3.15: Convolutional Neural Networks (CNN).
VAEs we discuss in subsection 2.3.17: Variational Auto-Encoders (VAE). However, below we will summarise a few points that we will build upon in this chapter, and we will refer back to them in later sections.
-
An Auto-Encoder (AE) is a type of deep architecture whereby the model tries to effectively compress and then decompress its inputs — which are in this case, images from a live video feed. This is accomplished by a bottleneck layer which has much smaller dimensionality in comparison to the AE's inputs. For example, a colour image of dimensions 256x256 pixels, might be compressed down to pass through a bottleneck layer of dimensionality 128. The aim of this compression is to encourage the network to identify and learn to extract salient features of the data, and learn more concise and optimal representations.
-
An AE can be thought of as consisting of two networks back-to-back. The first is an encoder network, which compresses an input to the bottleneck layer. We think of this as the latent representation . The second network is a decoder network, which decompresses the latent representation from the bottleneck layer, to an output . Given suitable training examples, architecture and hyperparameters, the VAE should be able to produce such that .
-
A Variational Auto-Encoder is a type of AE that is also a generative model. It learns the distribution of data. This enables us to sample new images from this latent distribution, or perform meaningful latent manipulations. We discuss these in more detail in section 2.1: Generative models.
-
What enables a VAE to be a generative model, is the parametrisation trick. This is a regulariser, an additional term in the loss function, that ensures the distribution of the bottleneck layer (also known as the latent distribution) converges to a desired distribution. Typically, this is a standard normal distribution . In other words, we can sample a random and feed this through the decoder to produce new images that resemble the training examples.
-
To be more precise, in a VAE, both the encoder and the decoder networks are probabilistic models. The encoder models the probability of , while the decoder models .
-
The loss function of a VAE consists of two components. The first component is the reconstruction loss, which ensures that the output of the VAE resembles the input . We will discuss this in the next point. The second component is the latent loss. This is the regulariser used for the parametrisation trick, which ensures that the latent distribution converges to the standard normal distribution . This is typically the KL divergence between the latent distribution, and the standard normal distribution.
-
Typically, the reconstruction loss is a pixel-wise L1, L2 or Cross Entropy loss. It is well known that these produce blurry results (I. Goodfellow et al., 2014; Theis et al., 2016; Larsen et al., 2016). One approach to address this has been a completely alternative approach to VAEs altogether, in the form of Generative Adversarial Networks (GAN) (I. Goodfellow et al., 2014). We discuss this in subsection 2.3.18: Deep Convolutional Generative Adversarial Networks (DCGAN), and in the next two chapters we will investigate GANs. More recently, there have also been attempts at addressing this within VAEs (S. Zhao et al., 2017; Dumoulin et al., 2017; Rezende & Viola, 2018; Shu et al., 2018). In the work that we present in this chapter, which came before these more recent studies, we take an alternative approach, which is unique to the domain of images. We implement a loss function based on Multi-Scale Structural Similarity Index Measure (MS-SSIM) (Z. Wang et al., 2004) to achieve perceptually significantly superior results.
-
We have also observed that the relative weight of the reconstruction loss and latent loss is very important to how the model performs. For this reason, we introduce a new hyperparameter, which is a weight multiplier on the KL divergence loss term (i.e. the latent loss). At the time of our work, this was not mentioned in the literature, and was later independently investigated and confirmed (S. Zhao et al., 2017; Higgins et al., 2017; Van Den Oord et al., 2017).
It is worth noting again, as we have mentioned above, theoretical improvements to VAEs have been suggested (S. Zhao et al., 2017; Dumoulin et al., 2017; Rezende & Viola, 2018; Shu et al., 2018). And in fact, GANs have also been proposed as an alternative, although they lack efficient inference capabilities to encode existing data points to latent representations, and we discuss this in subsection 2.1.3: Latent representation recovery. However, the method that we propose in this chapter, is not strongly tied to the VAE architecture that we demonstrate it with. Instead, our software is more of a shell that can sit around potentially any neural architecture with suitable adaptations. In fact we have tested our software with both unconditional and conditional DCGANs, namely pix2pix. Documentation of such an adaptation can be seen in Fig. 4.3. However, at the time of our research, available consumer GPU hardware did not provide satisfactory realtime interactive performance when training GANs, and generally dropped below 1fps. For this reason, in this chapter we focus on VAEs, with which we are able to achieve 30–60fps.

4.4 System description
We will begin by explaining what exactly our system does. Later in section 4.5: Experiments and results, we will discuss the affordances that this grants us.
In order to realise the above stated aims, we built a bespoke system that trains in realtime on a live camera feed, while allowing for the manipulation of a number of hyperparameters in realtime. Our system is built from the ground up in python using the Deep Learning framework Tensorflow (Abadi & Others, 2015) and PyQtGraphFootnote 4. for frontend and visualisation. PyQtGraph is an open-source Scientific Graphics and GUI Library based on Qt, designed for high performance, realtime applications.
Like many realtime systems, our system operates via an update loop. On a laptop with an Nvidia GTX 1070 our system runs at around 10-20 frames-per-second (fps); and 30fps–60fps on a desktop PC with an Nvidia GeForce GTX 1080 Ti. The exact figures depend on the hyperparameters and complexity of the Neural Network architecture that we set up.
When our application is launched, the model weights are initialised to random parameters using Xavier initialisation (Glorot & Bengio, 2010). Following the update loop detailed in Alg. 1, for every frame of the input video feed, our software performs one forward pass to run inference on the video input, it displays the generated images, and then runs one backwards pass to train and update the model weights. And this update loop is repeated indefinitely at realtime, interactive framerates.
This is a form of online learning, in which model parameters are updated dynamically, as new data streams in. Online learning is a well established area of research, and dates back to the earliest days of ML (Shalev-Shwartz, 2011). However, online learning is currently mostly limited to low dimensional data, using shallow models with convex objective functions. Applications of online learning with deep architectures is not common, although there is growing interest in the field (Sahoo et al., 2018).
It is important to underline how different this is in comparison to typical DL workflows. Within DL research, especially within the creative applications of DL, it is common practice to first train a model on some data, which can often take hours, days, weeks or even months depending on the amount of data and complexity of the architecture. And after this training phase, the model is used for inference.
With our method, every update loop of the application consists of one inference (or forward) pass, and one training (or backward) pass. Via a GUI, we can manipulate and experiment with a large number of hyperparameters while this inference-training loop is running, and we can observe the results in realtime. We do not argue that our method is capable of producing a more optimal model, compared to a traditional hyperparameter search consisting of training hundreds of models. However, we do claim, that our method is complementary, and can provide valuable insights into how these hyperparameters effect the training process and the solution that the model converges.
Fig. 4.4 shows a screenshot from our software. This is a full capture of the entire screen, although it excludes the GUI, as that is a separate window which we usually place on a second monitor. In the following pages, in order to save space on the page, we will crop the screenshots to show only areas relevant to the topic at hand.

In this screenshot, there are four panels showing images labelled Stimulus, Seeing, Reminiscing and Dreaming. We use these terms as metaphorical representations of the operations that are being performed in each panel. The details of these operations can be seen in Alg. 1, and we summarise them below.
-
The Stimulus panel shows , the live video feed that is presented to the model.
-
The Seeing panel shows , a straight reconstruction of the live video feed. In other words, the current image from the camera , is fed through the encoder and compressed into a latent representation . This latent representation is fed through the decoder and decompressed to produce the image . This is what the model is ‘seeing' in its ‘mind', as a result of being presented with this stimulus.
-
The live video feed's latent representation , is additionally perturbed by a small amount of noise to produce a new latent representation . Feeding through the decoder, a new image is generated and shown in the Reminiscing panel. Since is essentially a random position in the local neighbourhood of , and assuming that the space of latent representations is indeed well structured, we should expect the image generated as a result , to be somehow similar — structurally and/or semantically — to . We discuss the reasons behind this expectation in subsection 2.1.3: Latent manipulations. This is an image that the model is being ‘reminiscent‘ of, as a result of being presented with this stimulus.
-
The Dreaming panels shows a ‘random' image , generated by sampling a random from the latent distribution , and decoding through the model. This is the model ‘dreaming' random images that are not directly connected to the current stimulus, but is instead a result of the model's history and life experience.
The red graph at the bottom of the screenshot is a plot of the error. This is the loss calculated between and , as per the loss function currently selected via the GUI.
The cyan/blue graph we call knowledge gain. This is loosely based on Jürgen Schmidhuber's formal theory of curiosity, creativity, compression and beauty (Schmidhuber, 2006, 2007, 2009a, 2009b, 2010a, 2010b, 2012a). In this model, an agent's subjective view on the interestingness of a phenomena is measured as the first derivative of compression. In other words, an increase in the agent's ability to compress previously uncompressable data, is indicative of the agent learning about new regularities, and thus improving its model and knowledge of the world. In Hello World, we treat the decrease of error, as an improvement of the compressor, and thus an increase in knowledge gained about the world. We implement this by smoothing the error plot with a rolling window, and accumulating it's negative derivative. This is by no means an accurate metric, as it does not take into account changes in stimulus. For example, swapping a novel stimulus for a previously seen stimulus will also reduce the error, without an increase in knowledge. There are ways in which this could be taken into account. However, this is far outside the scope of our thesis, so we implement this simple metric as an approximate indicator of knowledge gain for situations where we know the stimulus to be relatively static.
4.4.1 Hyperparameters
One of our primary motivations in building this system, is to allow for the realtime manipulation of hyperparameters, while the system is training. The hyperparameters which our software makes available for manipulation can be grouped into two categories.
Architecture hyperparameters
define the architecture of the Neural Network. These hyperparameters can be modified while the system is running. However, this will reconstruct the computation graph, and the number of weights in the network is likely to change. Hence, changing any of these hyperparameters will result in the weights being reinitialised, and this will effectively reset the training. For this reason, we think of these as destructive edits. This is implemented in line 9 of Alg. 1. These hyperparameters include:
-
Dimensions of the bottleneck layer
-
Number of layers
-
For each layer, convolution hyperparameters such as kernel window size, filter depth, and stride. We detail these in subsection 2.3.15: Convolutional Neural Networks (CNN)
Non-destructive hyperparameters
do not affect the structure of the architecture, and can be modified in realtime without requiring a reinitialisation of the weights. In other words, the Neural Network can continue to train while we modify these values, and we can observe the results in realtime. Where these are boolean or multiple-choice options, our software constructs multiple paths in the computation graph for each of the options, and seamlessly switches between them at runtime depending on the options selected by the user. In other words, there is a path in the computation graph for each loss function, optimisation algorithm, and any other option that is provided to the user. We implement the real valued hyperparameters as tf.Variable objects, and we feed their values from the GUI at runtime. These non-destructive hyperparameters include:
-
Activation functions for each of the layers (tanh, sigmoid, ReLU, or Leaky ReLU)
-
L1 and/or L2 regularisation amount on the weights
-
Reconstruction loss (L1, L2, Cross Entropy, or MS-SSIM)
-
A weight multiplier for the latent loss KL Divergence
-
An option to toggle between a variational and a normal auto-encoder
-
Optimiser (SGD with momentum, RMSProp, Adagrad, Adadelta, or Adam)
-
Values for optimisation hyperparameters associated with the selected optimiser. These include learning rate, momentum, , etc.
-
Values for gradient clipping thresholds, both on L2 normals and per component
-
Batch size and options for exponentially decaying memory and data augmentation
-
Noise amounts, injected at input and/or in latent space
-
Video input device (USB cameras, network IP cameras, video files, or folders of images)
4.4.2 Batch size, exponentially decaying memory and augmentation
As we have previously mentioned and detailed in Alg. 1, with every update, the model is trained on a single image, which is the current image from the video feed . In this case, we observe that the model converges to reconstruct the current image very quickly, provided that the video feed does not change dramatically. However, the model ‘forgets' previous images it has seen, and is unable to reconstruct images that were presented to it just a few seconds earlier. For example, if we present to the system an object , and hold it still for a few seconds, the images generated will initially be very blurry, but the model will quickly learn to produce sharp images of . If we then present an object , the images generated will again initially be very blurry, but the model will quickly learn to produce sharp images of . If we then present object again, the images generated will be blurry again, as the model will have forgotten about and will need to relearn.
In other words, the network is constantly over-fitting to the live feed, and not learning to generalize.
To overcome this, we introduce an exponentially decaying memory. This a fixed size buffer of length (e.g. ). With every update, we store the current image into a random location in the memory buffer, overwriting the current contents at that location. During training, instead of using a batch size of 1 and training on only the live image , we use a batch size of (e.g. =2–4) where one element of the batch is , and the remaining elements are sampled randomly from the memory buffer. We feed this batch of images to the model to produce a batch of output images, which we use to calculate the loss and gradients.
Using this approach, the model is always being trained on the live video feed, as well as a random selection of older images. And due to the random-in-random-out nature of the memory buffer, the system has a higher probability of being exposed to recent images, and older images are more likely to be eventually over-written.
Finally, we include options to augment the images during training, by taking random crops and/or applying random brightness and contrast adjustments to them before they are fed into the model. While we observe this to improve generalization, for aesthetic reasons, we decide not to use this as it unsurprisingly introduces too much ‘jumping around' in the random samples.
4.5 Experiments and results
We will now share some of the experiments that we conducted. These can be grouped into two categories which reflect the primary modes of interaction. These are hyperparameter manipulations, and video feed manipulation. We will begin by sharing our experiments in hyperparameter manipulation.
4.5.1 Optimiser and associated hyperparameters
The optimisation algorithm determines how the parameter space is navigated with regards to the gradients from the loss function. We implemented a number of optimisers as listed above, and we experiment with them, switching between them, and playing with their respective hyperparameters in realtime, and observing the results.
Explosions and oscillations
Two important phenomena to discuss, are explosions and oscillations.
Explosions occur when the optimiser completely shoots past a minima, and escapes the valley, into some unknown territory in the parameter landscape. The model is no where near a solution. Furthermore, the optimiser is unable to bring it back, and the system is generally unstable and out of control. This is typically when the gradient updates being applied are way too large.
Oscillations occur when the gradient updates are still large enough that the optimiser shoots past a minima, and cannot converge. However, the updates are not large enough for the optimiser to escape the valley and explode. Instead, the optimiser oscillates around the minima, back and forth inside the valley, without ever reaching the minima.
The visual manifestation of these can be seen in Fig. 4.5, and we will explain this image in more detail shortly.
Learning rate
A very simple way of making the optimiser explode, is by increasing the learning rate hyperparameter. This increases the step size that the optimiser takes with each gradient update. As a result, increasing the learning rate will first result in oscillations, as the optimiser consistently shoots past the minima and then returns, oscillating around the minima like a pendulum. As learning rate is increased further, the optimiser is likely to escape the valley into uncontrollable territories, and it will eventually explode.
Momentum
A tightly coupled hyperparameter, is momentum. This introduces, as the name implies, momentum to the equation. This is typically visualised as a ball rolling around on a hilly landscape. Higher values for momentum, equates to the optimiser preserving more of its velocity from the previous gradient update. This helps smooth the trajectory in parameter space, and can aid escaping local minima. This can be thought of as a heavy ball such as a cannonball, rolling around on the hilly landscape, unaffected by wind resistance. Whereas lower values of momentum can be thought of as a ping pong ball, losing much of its energy to wind resistance, rolling around on the same hilly landscape.
Increasing momentum can dramatically increase the step size if the optimiser is already moving in the direction of the gradient, as the velocity from the previous updates accumulate. This is analogous to a ball accelerating down the slope of a hill.
For this reason, increasing momentum is also a very simple way to make the optimiser explode. Generally speaking, it is beneficial to have momentum, as this will smooth the trajectory, and can help the optimiser escape from local minima. However, increasing momentum will need to be paired with decreasing learning rate, in order to balance out the accumulations of velocity across updates, and to prevent explosions.
Stable oscillation points
One of the interesting experiments that we tried, is to adjust learning rate and momentum in such a fine balance, that the system starts oscillating. It is stable, however, it is right at the edge of stability.
Without a Realtime Continuous interface that provides immediate feedback, such a configuration of values would be very difficult to find. However, we are able to find such configurations very quickly, within a few seconds in fact. We map our hyperparameters to faders on a midi controller, and with one finger on each fader, we do not need to take our eyes off the screen. We can slide our respective fingers forwards and backwards, and manipulate both hyperparameters simultaneously, to find the balance of values such that the system approaches, but does not pass, this tipping point into exploding.
There will of course be many such stable oscillating points, high learning rate and low momentum, vs low learning rate and high momentum, and everywhere in between. And each configuration will behave slightly differently. Through the relative balance of these hyperparameters, we can control the amplitude and speed of the oscillation.
The impact of novel inputs
Having found a stable oscillating point, we then introduce novel inputs to the video feed. This is typically a large, sudden movement in front of the camera, such as waving an arm. A novel input such as this, will introduce a large loss. And a large loss will introduce a large gradient. For this reason, if the system was already oscillating, in a stable manner but close to the edge of the valley, this large gradient that comes from the sudden movement is likely to cause the system to escape the valley, and ultimately explode.
Furthermore, here the differences in behaviour between the different optimisers become very noticeable.
Stochastic Gradient Descent (SGD), unsurprisingly, is the most likely to explode in a situation like this. This is because the step sizes in SGD are not dynamic. They are directly related and fixed, to the gradient, learning rate and momentum. If the optimiser is already oscillating at the edge of tipping while the video feed is relatively still, and the gradients are small, then it is very expected that it will explode if the gradients suddenly grow.
Optimisers such as RMSProp, AdaGrad, and Adam on the other hand, implement adaptive measures to counteract such incidents. Adam in particular, we observed to be not only the most stable, but also the quickest to converge. Building on RMSProp and AdaGrad, the Adam optimiser uses exponential moving averages to estimate the first and second moments of the gradient, to dynamically adjust both the learning rate and momentum, per parameter (D. Kingma & Ba, 2014). For this reason, even if we increase learning rate, and make sudden big movements in front of the camera, the Adam optimiser is likely to counteract massive gradients, and try to prevent large oscillations or explosions. And on the flip side, when movements in front of the camera are very subtle, and the gradients are very small, the Adam optimiser is likely to counteract by increasing the step size, and thus converges quicker.
Interestingly, and perhaps unsurprisingly, even though SGD was the most unstable of the optimisers, it was also the easiest for us to play with and meaningfully control. We were very quickly able to build a qualitative understanding of the behaviours of learning rate and momentum with SGD. We were also able to very quickly bring the SGD optimiser to an oscillating stable point. And upon exploding, we were able to bring it back under control, and back to convergence. Probably due to the non-linear complexity of the Adam optimiser, we were not able to develop as much control over the Adam-specific decay hyperparameters and .
Gradient clipping
Two more hyperparameters which are key to controlling this optimisation process, are the gradient clipping hyperparameters. These rescale the gradient if the gradient gets larger than a certain threshold, and can be a very computationally cheap and effective method for preventing explosions, or controlling oscillations (Pascanu et al., 2013). We implement two methods of gradient clipping, L2 norm (i.e. rescaling the gradient if its L2 norm is greater than the threshold), and per component (i.e. clipping each component of the gradient independently if it is larger than the threshold). We found it difficult to qualitatively assess the differences in behaviour between clipping per component or L2 norm. However, we know that theoretically, per-component clipping is likely to change the direction of the gradient, and this is not a desirable behaviour. For this reason, we generally use L2 norm clipping.
An optimiser experimentation session
Fig. 4.5 shows a selection of frames from an experimentation session where we play with the optimisation hyperparameters learning rate, momentum, and gradient clipping threshold, in a manner that we describe above. We have these three hyperparameters mapped to faders on a hardware midi controller, so that we do not need to take our eyes off the screen, and we can manipulate all three hyperparameters simultaneously.

The loss function that we use is L2, and the optimiser is SGD with momentum. The live video feed is a webcam focused on our face and shoulders, similar (but not identical) to the setup in Fig. 4.4.
At the start of the session, the model is initialised randomly with Xavier initialisation (Glorot & Bengio, 2010), learning rate and momentum are set to ‘reasonable' values 0.0003 and 0.5 respectively. The first two rows show the model converging, and by the middle of the 3rd row, the model has converged, reconstructing the video feed accuratelyFootnote 5.
Towards the end of the 3rd row, we decrease learning rate to zero. This effectively pauses any gradient updates and the model stops learning. As a result, when we move to the left of the screen, the model is unable to reconstruct these novel inputs, and our head disappears. By the start of the 4th row, we restore the learning rate, and the model is able to reconstruct our head in this new location on screen.
In rows 4 to 6, we increase learning rate and momentum, until the system is oscillating wildly. This is difficult to observe in this image where the frames are spaced roughly 1-2 seconds apart. In reality, at every update, the output is wildly different to the previous in terms of colours and brightness, but some aspect of the composition is somehow always preserved. We can easily observe that the generated image is oscillating around an image that would be the image from the live video feed. The output flashes alternately brighter and darker, or between opposing colours, while it tries but fails to converge on the desired image from the camera.
Towards the end of row 7 and beginning of row 8, we push momentum further causing the system to explode, and the structure of the generated image is entirely lost. At every update, the output is flashing crazy colours and shapes at this point.
Towards the end of row 8 and beginning of row 9, we introduce gradient clipping to slow the system down and bring it back under control. We lower momentum and learning rate to reasonable values, and in the last 2 rows, we can see that the system is stable again, however it is oscillating. By controlling the gradient clipping, momentum and learning rate, we can control the amplitude and speed of the oscillation.
It is worth pointing out, that we do not perform any kind of colour correction, brightness, contrast or any other kinds of post processing on the images generated. These images are the raw, unprocessed outputs from the model. The model is trying to reconstruct its input as accurately as possible. The colour variations, extreme saturation, over and under exposure of the images generated, are a result of the optimiser overshooting desired minima, and entering remote territories in parameter space. Having Realtime Continuous Control over this system via a number of faders on a midi controller, we are able to meaningful control the system, and steer it towards desired directions, and in effect, we can play it like a visual instrument.
4.5.2 Reconstruction loss
As we discussed in subsection 2.3.17: Variational Auto-Encoders (VAE), the loss function of a VAE consists of two terms, a reconstruction loss which ensures that the output of the VAE resembles the input , and a latent loss which ensures that the latent distribution converges to a standard normal distribution .
The reconstruction loss is some function which returns a similarity metric between two images. Typically in ML and DL applications, functions such as L1, L2 or Cross Entropy (CE) are common, and this is known to produce blurry outputs when used with images (I. Goodfellow et al., 2014; Theis et al., 2016; Larsen et al., 2016; Dumoulin et al., 2017).
In addition to the three loss functions mentioned above, we also implement Multi-Scale Structural Similarity Index Measure (MS-SSIM) (Z. Wang et al., 2004). MS-SSIM is a perceptually motivated metric that compares patches of local neighbourhoods on multiple scales, and is very commonly used in image processing applications such as image and video compression. It is also differentiable, which makes it suitable for use within our gradient based optimisation process. However, MS-SSIM is very rare in the DL literature. In the case that it does appear within DL research, it is generally used for the evaluation and validation of DNN generated images. For example, measuring a deep generative model's diversity (Odena et al., 2017) or evaluating the results of up-scaling or image restoration models (Ledig et al., 2017; Dong et al., 2016; Lim et al., 2017; Johnson et al., 2016; Liang et al., 2017). MS-SSIM is generally not used as a loss function, even though it has been shown that it is superior to the de facto L2 loss, for DNN based image processing applications (H. Zhao et al., 2015). We are not entirely sure why MS-SSIM is not used as a loss function. One possible explanation might be that perhaps a majority of DL researchers prefer to investigate mathematically and theoretically robust solutions that can apply across multiple domains, as opposed to incorporating very domain-specific, perceptually motivated models. Though this is just a speculation. In our case however, since we are focusing on images in this section, we are happy to use metrics optimised for images.
A qualitative comparison of using these four loss functions can be seen in Fig. 4.6, although it is more noticeable in the accompanying video. This image shows six screenshots captured during the training of four different models. All four models have identical architecture and hyperparameters, with the only difference being the loss functions used. The L2 loss, one of the most common loss functions in Machine Learning, clearly performs the worst and produces very blurry reconstructions of the input. CE loss performs almost equivalent to L2 in terms of final quality. However, it converges slower than L2, as can be seen in the first three screenshots. L1 loss performs noticeably better than both, converging quicker and settling on a higher quality reconstruction. However, it still produces blurry images. MS-SSIM performs significantly better than all three. This is not only in terms of final image quality, producing the sharpest image which we can see in the bottom right screenshot. But it also converges the quickest, producing a recognizable image within a few seconds, as can be seen in the first screenshot.
Interestingly, we can also see that the models first learn about the luminance of pixels, and only once the models are able to predict luminance patterns, do they start to learn about colour. This is not a behaviour that we have explicitly programmed. It is entirely an emergent property of the Neural Network optimisation. The speed at which the four different models learn about colour, follows the same patterns as we describe above. By iteration 293, colour has just started to appear in the MS-SIM model while the other models are still monochromatic. The L1 model follows shortly behind, and by iteration 502, has full colour while L2 and CE are still mostly monochromatic.

4.5.3 Latent loss and variational reparametrisation
The second term of the VAE loss, is the latent loss, which consists of the KL divergence between a standard normal and the latent distribution. This ensures that the latent distribution converges to a standard normal.
As we have briefly touched upon above, we noticed that the performance of the VAE depends heavily on the relative weights between the reconstruction loss, and the latent loss. In other words, there is a decision and compromise that can be made, whether we prefer the VAE to produce more accurate reconstructions (), or more believable random samples (). This can be controlled through changing the balance of the loss terms. Prioritizing latent loss, leads to poorer reconstructions. However, the latent space is more structured and disentangled, and random samples are of higher quality. Prioritizing reconstruction loss, leads to higher quality reconstructions. However, the latent space is less structured, and potentially sparse. It may not be distributed in a standard normal distribution as we desire. Thus, random samples are of a lower quality and do not always accurately resemble the training examples.
Furthermore, this balance is already dependent on and biased by the dimensionality of the input and the latent layers. This is to say that, the reconstruction loss is already weighted by the input layer's dimensionality , as seen in eqn. (2.12). And the latent loss is already weighted by the latent layer's dimensionality , as seen in eqn. (2.13).
As a result of this, if we decide for example to increase the dimensionality of the latent layer, in order to observe the impact on the model's expressive powerFootnote 6, we will not in fact be observing the effects of an isolated change. This is because, not only has the model's architecture changed as a result of this, but the loss function has changed dramatically as well, the latent loss is weighted more heavily in comparison to before.
To address both of these issues, we implement the solution that we discuss in subsection 2.3.17: Variational Auto-Encoders (VAE). We normalise both the reconstruction loss and latent loss, and we multiply the latent loss by a new hyperparameter .
This hyperparameter, is an additional hyperparameter that we can manipulate in realtime. Through realtime experimentation, we found that a value in the range 0.01–0.1 provides a subjectively satisfactory compromise, with higher values prioritizing higher quality random samples, and lower values prioritizing higher quality reconstructions. We also verified this through thorough offline traditional hyperparameter search.
We also implement a pathway in the computation graph that bypasses the variational reparametrisation altogether. This effectively toggles between a Variational Auto-Encoder, and a normal Auto-Encoder. Disabling the variational component and switching to a normal AE results in the model ceasing to be a generative model. In other words, it no longer captures the distribution of the data. The model is still able to reconstruct the live video feed. However, the distribution of its latent layer is no longer a standard normal. In fact, in this case we do not have any knowledge as to how the latent layer is distributed. Furthermore, this distribution is not structured such that we can exploit the properties that we discuss in subsection 2.1.3: Latent manipulations.
In the following section subsection 4.5.4: Video feed manipulations, we will discuss our experiments in video feed manipulations. And we will share our observations with regards to the Reminiscing panel, which, as we briefly explained in section 4.4: System description, is a random sample from the local neighbourhood of the live video feed. As a result, in a well structured space of latent representations, we would expect the image in the Reminiscing panel, to be somehow similar to the live feed.
In a non-Variational, normal Auto-Encoder, this is not the case. The images may be distributed anywhere in the unbounded, infinite space of the bottleneck layer. Only in the Variational Auto-Encoder do we observe this.
4.5.4 Video feed manipulations
So far we have only discussed realtime manipulation ofhyperparameters. However, there is an additional mode of interaction which we have not yet discussed. That is the act of simply moving or manipulating objects in front of the camera.
In this section, to save space on the pages, we tightly crop screenshots around the Stimulus, Seeing and Reminiscing panels, as we will be focusing on these. In all of these example, we are using MS-SSIM loss, and the Adam optimiser. For this reason, the reconstructions are much sharper than our previous experimentations. We are also using a batch size of for training, where the second image is randomly selected from the exponentially decaying memory buffer. This ensures that the model doesn't ‘forget' immediately, and doesn't over-fit to the live video feed.




4.6 Conclusions
In this chapter, we present a system that trains in realtime on a live video feed. While the system is training, we are able to manipulate a number of hyperparameters in realtime via a GUI, and immediately observe the results.
Manipulating for example , a weight multiplier on the latent loss term, we were able to immediately observe the results. With this realtime control and immediate feedback, we were able to identify a range for that we found provided a desirable balance between reconstruction quality, and random sample quality. We were able to use this range as a starting point for a traditional offline hyperparameter search, which we confirmed as 0.01–0.1. In this case provides sharper reconstructions at the cost of lower quality random samples, and provides blurrier reconstructions but higher quality random samples. We discuss this in more detail in subsection 4.5.3: Latent loss and variational reparametrisation.
Manipulating the reconstruction loss function in realtime also proved to be very useful. We saw that our MS-SSIM converged much quicker than L1, L2 and Cross Entropy. It also provided much sharper images. L2 and Cross Entropy performed the worst, both in terms of final image quality, and speed of convergence. We provide more details and images for comparison in subsection 4.5.2: Reconstruction loss.
Perhaps the most useful hyperparameters to manipulate in realtime were the optimisation parameters. These include learning rate, momentum, gradient clipping thresholds, and optimiser function. Unsurprisingly, we found that the more advanced Adam Optimiser, was quickest to converge, and was also the most robust in terms stability. The simplest optimiser SGD with momentum, was a lot more unstable. However, because of the simplicity of the momentum-based SGD optimisation algorithm, we found that it was the easiest to learn how to control.
And this is where perhaps the biggest surprise of this particular study came. Our initial aim with this study, was to observe how DNNs train in realtime, and hopefully build a qualitative understanding of the hyperparameters. We realised however, that the system that we had developed had incredible performative potential. We were able to build a qualitative understanding of the optimisation parameters such that we could play with them in realtime, and control the outputs generated by the Neural Network in a meaningful manner. We were able to bring the system into oscillatory states, bordering between stable and unstable. We were able to push the system to explode, and bring it back under control again. We discuss all of these experiments in subsection 4.5.1: Optimiser and associated hyperparameters.
The most important finding of our experience with this system, was that we were able to generate images with the system that we did not know the system was able to create. And we were able to explore this space in a Realtime Continuous manner, with Meaningful Human Control, and use the system as a performative instrument.
In the next chapter, we build upon the system that we developed in this study, and we investigate ways of providing more control over the aesthetics.
Footnotes
-
A full list can be seen in subsection 4.4.1: Hyperparameters ↩
-
Alternatively, the top N models may be used as an ensemble. However, this is outside the scope of this thesis so we will not dig deeper into this. ↩
-
We are using L2 loss, and for this reason the results are blurry. We will discuss this in more detail in the next section. ↩
-
subsection 2.3.7: Universal function approximators, expressive power. ↩