Collaborative creativity with Monte-Carlo Tree Search and Convolutional Neural Networks

We investigate a human-machine collaborative drawing environment in which an autonomous agent sketches images while optionally allowing a user to directly influence the agent's trajectory. We combine Monte Carlo Tree Search with image classifiers and test both shallow models (e.g. multinomial logistic regression) and deep Convolutional Neural Networks (e.g. LeNet, Inception v3). We found that using the shallow model, the agent produces a limited variety of images, which are noticably recogonisable by humans. However, using the deeper models, the agent produces a more diverse range of images, and while the agent remains very confident (99.99%) in having achieved its objective, to humans they mostly resemble unrecognisable 'random' noise. We relate this to recent research which also discovered that 'deep neural networks are easily fooled' \cite{Nguyen2015} and we discuss possible solutions and future directions for the research.


Introduction
The aim of this research is to create an autonomous, collaborative, 'creative' agent that can sketch images in realtime, while optionally allowing a user to intervene and physically influence the agent, affecting how and what it decides to draw. To be more specific, our objective is to allow the agent to take random actions, and sketch any path (i.e. follow any trajectory) that resembles a predetermined, desired object class. E.g. everytime we ask the agent to draw a 'cat', it should draw a different picture of a cat. Note, the objective for the agent is not to sketch an image that resembles a specific target picture, as in that case, no matter how the agent meanders, it would always converge back to the specified target picture. Similarly, we stay away from any number of target pictures and instead turn to Deep Learning to exploit latent representations that might be useful in aiding the agent. We also allow a user to optionally interact with the agent, and exert forces on it to push and pull it around, causing the agent to diverge onto a new trajectory that might lead to a new picture -which still resembles the desired class (e.g. it sketches a different 'cat' picture). The output images would all be varied, and in effect be collaborations between the user and the agent. The entire system could be seen as a realtime collaborative drawing environment between a human and a 'creative' autonomous agent. This research is presented as work in progress. At this stage we have mixed results (discussed in Section 4) where the system shows potential, but also demonstrates weaknesses relating to the Deep Learning models.
While this is the context for our research, computational models of creativity -such as those described in [6] -or methods of evaluating machine creativity -such as those described in [32] are currently not within the scope of this study. Instead, we focus on investigating the opportunities provided by Deep artificial Neural Networks (DNNs) -in particular Convolutional Neural Networks (CNN) -combined with agent-based AI methods -such as Monte Carlo Tree Search (MCTS)for the task of driving collaborative drawing agents.
Deep convolutional architectures saw initial success in image classification in the late 1980s [21], and they are now consistently providing state of the art results in this field [19,38,16,37]. An active area of research is focused on trying to understand and visualise the internal workings of CNNs, and use them for generative purposes [42,25,26,33,28,12]. Additionally, CNNs have also been used with great success to drive AI agents, such as those playing Atari games, Doom or Go [27,15,18,34]. In these latter cases, the CNNs have effectively acted as the agent's 'eyes', breaking down the raw input (i.e. screen pixels or state of the Go board) into more abstract, meaningful representations which can be used by the agent. These researchers have also used MCTS [7] to guide the agents, and allow them to make more optimical decisions based on the meaningful representations provided by the CNN. It is based on this direction of research, and within the artistic, 'artificially creative' context outlined above that our study takes place.

Method
The agent, similar to a LOGO Turtle [31], can move forwards (leaving a trail as it moves), or rotate clockwise or counter-clockwise. We use MCTS to simulate many alternative actions and paths at every timestep, and at the end of each simulation, the entire trajectory of the agent -including the previous history as well as the simulation -is fed into an image classifier. The classifier evaluates how much the agent's trajectory resembles the desired class, and that score is used as the reward backpropagated by MCTS to choose the final action. This is described in more detail in the sections below.
We tested three classifiers trained on two datasets: i) the MNIST dataset of hand-written digits [23], and ii) the ImageNet dataset of millions of labeled images classified into one thousand classes [10].
We developed our application in openFrameworks [24], a C++ creative development toolkit very popular amongst artists and creative coders. We used ofxMSAmcts, our own open-source C++ MCTS implementation (i.e. addon) for openFrameworks [2]. We built, trained and saved the image classifiers in python using TensorFlow [1], and loaded the trained models into C++/openFrameworks using ofxMSATensorFlow, again our own open-source TensorFlow openFrameworks wrapper (addon) [3].

MCTS Agent
The MCTS procedure is summarised in Appendix A and a more detailed survey can be found in [7]. In our implementation, our agent can move forward with a number of different speeds (n speeds ) to choose from, ranging from s min to s max . It can rotate in r inc increments ranging from −r max to +r max , giving it n rot = 2r max /r inc number of different rotations to choose from. Thus at each timestep, the agent has n a = n speeds * n rot total number of actions to choose from. An example configuration is: n speeds := 2, s min := 0, s max := 2, n rot := 7, r max := 30, with n a = 14.
The state s at any timestep, is the full trajectory (stored as a vector path) that the agent has followed (i.e. sketched) up to that point in time. The state s which is reached after the agent takes an action a, is the full image that will be drawn once the agent takes that action. The MCTS simulations end after a maximum rollout depth (e.g. D = 100), after which the final simulated drawn image (rasterized as a bitmap image) is fed into an image classifier, and the probability score for the desired class is retrieved and backpropagated as the reward for reaching that state. In our application we also visualise all of the 'imagined' paths (i.e. all simulations).

MNIST -Multinomial logistic regression
The first classifier we train is a multinomial logistic regression trained on the MNIST dataset, a linear transformation followed by a softmax activation [5]. We formulate this as x is a vector containing the flattened input image pixels, and W and b are respectively the weights matrix and bias vector to be learnt through training. We train using stochastic gradient descent and backpropagation trying to minimise the cross-entropy [5] between y, the predicted probability distribution of our model, and y , the true distribution, i.e. the training data.
The model completed training in a few seconds (on CPU) and unsurprisingly it doesn't generalise very well, scoring about 90% on the validation data. As expected, it is very restrictive on the types of inputs it can classify and does not provide much translational, rotational or scale invariance as the softmax operates directly on a linear transformation of the flattened raw pixel data.

MNIST -Convolutional Neural Network (LeNet)
The second classifier we train is a deep Convolutional Neural Network (CNN) similar to the LeNet architecture [22]. CNNs are deep architectures inspired by the visual cortex, and consist of a hierarchy of stacked feature maps, where each layer extracts features from the layer below using two-dimensional convolution kernels which are also learnt during training. We use two convolutional stacks, each stack consisting of 5x5 convolution kernels followed by an element-wise rectified linear unit (ReLU (x) = max(0, x) [17]), followed by a 2x2 max-pool layer. The first convolutional stack learns 32 feature maps while the second stack learns 64 feature maps. After the two convolution stacks, we use a dense fully connected layer with 1024 neurons, followed by a softmax to convert the results to a normalised probablity distribution. Similar to the multinomial logistic regression, we train with stochastic gradient descent and backpropagation to minimise the cross-entropy. We use dropout regularization with a probability of 50% [36].
The model trained in a couple of minutes (again on CPU). It scored 99.2% accuracy on the validation data and unsurprisingly proved to be much more successful in classifying images, with higher resilience to noise, translation, scale and rotation compared to the multinomial logistic regression.

ImageNet -Inception-v3
For the final classifier, we download and use a pre-trained model of Google's state of the art image classification architecture Inception-v3 [39], trained on ImageNet. This is a deep CNN reaching as low as 3.58% error in the 2012 ImageNet validation set for Top-5 error.

Results and conclusion
The overall system architecture seems to work and shows potential.
Using MNIST with the shallow model -multinomial logistic regression -proved very effective and positive results were obtained. Example output can be seen in Fig. 1 (a), where the agent has clearly sketched the desired image which was the digit '3'. Running this multiple times with different objectives provided similar results, demonstrating that the MCTS + Image Classifier system works on the whole.
However, we found that the deep CNNs were not ideal for generative applications in this manner, as they provide too many false positives. As discriminative models trained to classify images, they can classify natural images correctly with very high accuracy and confidence, but they also incorrectly classify unnatural images such as noise and abstract shapes, with equally high confidence. In other words, the class manifolds successfully represent the desired natural images, but also include undesired unnatural images as well. In retrospect this is not too surprising, as these networks are designed to function under very high noise with high degree of translational, rotational and scale invariance, and the training data does not contain any unnatural images.
Ultimately, the tendency of these deep models to identify false positives, cause the agent to wander around the screen randomly, sketching out images that appear to humans as unrecognisable 'random' noise, but are classified by the network with very high (99.99%) confidence to be the desired class. This can be seen in Fig. 1 (b) and (c). Interestingly, even though the system produces what appears to humans as random noise, it's not only the top prediction of the network which classifies the outputs as the desired class, but the top 5 predictions as well. E.g. in Fig. 1 (b) the desired class is 'meerkat'. The top 5 predictions of the network are 'meerkat' (99.999%), 'mongoose', 'hyena', 'Egyptian cat', 'cheetah' -all small, cat-like animals. In Fig. 1 (c) the desired class is 'white wolf'. The top 5 predictions are 'white wolf' (97.8%), 'timber wolf', 'Arctic fox', 'Samoyed', 'west highlands white terrier' -all white/light grey dogs.
In summary, the failure of the system -i.e. the output not resembling the desired class in our eyesis not a failure of the whole system, or of MCTS, or the way MCTS and the classifier are integrated. But it is a failure of the deep CNN classifier, in that it's easily susceptible to false positives. This also confirms recent research that deep CNNs can easily be fooled [30]. Though this previous research demonstrated this using evolutionary algorithms, and in a very non-realtime, non-interactive manner, as opposed to our realtime agent based methods. There are also recent examples of overcoming this problem of generating unnatural images, by using natural image priors [28,29] or adversarial networks [13,33]. Both approaches we are planning to try in future research.
At every timestep, we also visualise all of the MCTS rollouts (Fig. 3). From a conceptual and aesthetic point of view this can be thought of as visualising the possible trajectories 'imagined' by the agent, which is in part the motivation for this research. Figure 1: Agent trying to sketch (a) the digit '3' using Multinomial Logistic Regression trained on MNIST as the classifier, (b) a 'meerkat' using Google's pre-trained state of the art Inception-v3 model as image classifier, (c) a 'wolf' using the same system. Interestingly, the output of the latter two looks like random noise to us, but the classifier evaluates both images with extremely high confidence to be the desired class. See Fig. 3 for full screenshot including confidence values and simulations. MCTS is a probabilistic approach to searching a decision tree. At its core, it treats actions like slot machines in a multi-armed bandit. Below we briefly discuss our implementation. A detailed explanation and survey can be found in [7].

A Monte Carlo Tree Search
We represent our problem as a discrete-time Markov Decision Process (MDP) [4]. At a particular timestep the system is in a state s. The agent can take an action a (out of a number of available actions na) to arrive at a new state s , and will be given a reward Ra(s, s ) for doing so. Instead of trying to simulate every possible action at every timestep, MCTS uses a heuristic to only partially expand what might be the most promising branches of the decision tree. At every timestep, many simulations are run, but only from carefully chosen nodes of the decision tree. The algorithm decides which node to expand and runs a simulation from it based on a balance between exploiting known rewards for nodes already fully expanded, vs exploring nodes which have not yet been fully explored, i.e. with unknown rewards.
An overview of MCTS can be seen in Fig. 2 and summarised as i) Select a node to expand by starting at the current root node and recursively stepping through fully expanded child nodes until an expandable node is reached (i.e. a non-terminal node with unvisited children), ii) Expand the selected node (i.e. pick one of its unvisited children), iii) Run a simulation (i.e. rollout) from the new child node until an outcome is reached, iv) Backpropagate a reward value ∆ based on the outcome of the simulation, back up the tree, accumulating statistics for each node.
At each timestep, this procedure of {selection-expansion-simulation-backpropagation} is repeated many times to partially expand the decision tree, until a predefined criterion is met. This is usually an allocated time budget (e.g. maximum milliseconds per timestep) or an upper bound on the number of simulations per timestep, or a domain-specific interruption criterion. Once the search is terminated, a final decision is made by choosing an action according to a criterion based on the search statistics. E.g. The most visited child node (Robust Child) or child with highest rewards (Max Child), more examples can be found in [7].
The tree policy decides which node to select and expand, and we use the Upper Confidence Bound 1 applied to Trees (UCT), formulated as v nc where v is the value of the child node, nc is the number of times the child node has been visited, k is the exploration parameter (theoretically equal to √ 2 but usually chosen empirically) and nt is the total number of simulations for the node considered. The default policy decides how to choose actions during the simulation (i.e. rollout). We use a random rollout, i.e. actions are selected randomly from the na available actions.
In a typical two-player zero-sum game such as tic-tac-toe, MCTS simulations will run until they reach a terminal state, where the outcome is either a win, lose, or draw. In these situations, usually a simple reward value ∆ = 1 is backpropagated if the agent wins, ∆ = −1 if the agent loses, and ∆ = 0 if the result is a draw. Since each simulation iteration combinatorially increases the size of the decision tree, in situations where the tree is very deep -such as in the game of Go [34] -it is not feasible to run simulations until a terminal state is reached. In these cases it is common to prematurely end the simulation after a predefined maximum rollout depth D, and then evaluate or approximate the reward value ∆ using a heuristic on the simulation end-state. This approximated reward value is then backpropagated as before.