Sunday, December 5, 2021

AI & Art

 


When it comes to art, there is no consensus on what qualifies as art. There is a perpetual passionate debate about "What is Art?" amongst the art scholars and critics. So when it comes to calling something "Art", I stick to the basics: If you think it is Art then it is Art. 


There is an apparent ongoing paradigm shift in the art world with all the craze around NFTs. Renewing school-of-thought that the spirit of art could accommodate the utilitarian as well as aesthetic outlook. As for "the purpose of art", it is integral to the human experience.  I digress to steer this blog into the never-ending discussions on what qualifies as Art. This blog is about Artificial Intelligence. 

Having created a neural network that outputs "art" seems like a paradox to me. What is the epitome of creativity here? The art created or the code that creates a virtual "brain" that creates the artwork.  If we try to settle all the questions on that, it will take a lot of time and many assumptions. Thus, I believe, let us leave it to the thinkers as a subjective matter.

So after "Releasing" the album in my last blog post, I thought now it is time to hand over an easel and brush to another AI model. So I trained AI to create another artform. When it comes to painting I wanted my model to paint what I like to paint the most: Oil painting portraits. Well, we can't actually do it on canvas with real oil paints cos let's face it I have so many limitations on having a real-life robot and training it to do so. So for all the intents and purposes, I will stick to a virtual replica of an oil painting aka Image.


Oil On Canvas Portrait 

To do so, I built a Generative Adversarial Network (GAN). Generative modelling is an unsupervised learning task in machine learning that involves automatically discovering and learning the regularities or patterns in input data. GANs work by identifying the patterns, So I trained them on images of portraits. The orientation and poses in the dataset did very vastly which makes it difficult for the model to recognise the patterns. Despite knowing that, I was still willing to give it a try. As I basically love oil painted portraits and thought it would be awesome to see what a machine would process out of it. 

How It works!

Neural Networks are the basis of deep learning where the algorithms are inspired by the structure of the human brain. The Neural Network takes in data, train itself to understand the patterns in the data and gives out the output in a new set of similar data. Let us learn how a neural network processes data. A Neural Network consists of layers of Perceptrons, the fundamental component of a Neural Network. The network consists of three kinds of layers; An input layer, an output layer and sandwiched between those are one or more hidden layers.



Say we want to build a neural network that can classify images of cats and dogs. The input layer takes in the data in the form of images of cats and dogs, which is encoded as the numeric values of pixels in all three colour channels. The neurons in the input layer are connected to the consequent layer, so on and so forth, via channels. each of these channels is allotted some weights. Weights are a numeric value, which is then multiplied with corresponding input data, that is the pixels value in our example. This multiplied data value is passed on to the corresponding hidden layer. Each neurone in the hidden layer is associated with a value called bias. Which is then added to the input to the neuron from the previous layer and passed on to an activation function. The Activation function outputs the result which decides if the corresponding neuron will be activated or not. I like to think of it as the synapse in the human brain. If the corresponding neuron is activated the data is forwarded to the next layer. This unidirectional flow of data is called forward propagation. This goes on for as many hidden layers as the said neural network has. At the output, layer ends the neurons with the highest value fire up and this is the determinant of the prediction by the network. This prediction is in the form of probability and the output class getting higher probability is the final classification of the model. For an untrained neural network, this is absolutely arbitrary.

When we train a network it iterates the values of weights and biases in such a way that the final values are optimized to predict the right output. This is done by a process of bi-direction information flow that includes backpropagation. To train a neural network along with the training data the network is also fed the actual class of the image. In this way, with each iteration, the network gets to evaluate the errors. This comparison of the calculated values and the true values is indicative that there is a need to change the values of weights and biases. As this information feed propagates backwards through the network the weights are adjusted. This backward flow of information is called backpropagation. During the training, this forward and backward flow of information iterates over with multiple data points a number of times, until the error is significantly low and the predictions are mostly correct.

This approach is good for classifying data. To generate images, I will build a Generative Adversarial Network (GAN). It is a dexterous way of posing the problem as a supervised learning problem. It comprises two models, a Generator and a Discriminator.

Two models are trained, simultaneously, by an adversarial process. The generator ("the artist") learns to create images, that look like the dataset. While a discriminator ("the art critic") learns to tell real images apart from fakes. During training, the generator progressively becomes better at creating images that look real. Likewise, the discriminator becomes better at telling them apart. As the process reaches equilibrium, the discriminator can no longer distinguish between real and fake.

Generative modelling is an unsupervised learning task in machine learning. It involves automatically discovering and learning the regularities or patterns in input data. As GANs work by identifying the patterns in the data, I used portraits. However, glancing over the dataset gave me an idea that it was going to be a long shot. The orientation and poses in the dataset vary vastly. Keeping that in mind I was still willing to give it a try. Only because portraits are my jam. I basically love oil painted portraits.

The output of the Neural Network picked up some patterns in the portraits. As we can see in the slide below. My model with GAN worked quite well.


GAN Generated Portraits 

Check out my full project Kaggle notebook for this one. (here)

GANs are notorious for being data-hungry, so I would consider increasing the dataset. There were many inconsistencies in the data which is rather complicated for the GAN to learn. Incustencies in colour pallet and poses orientations. Cleaning the data for the portrait styles would certainly help. Training it longer i.e. for more epochs would also help. Lastly, one can always strive to make a more robust architecture for the Neural Networks.

Nonetheless, I am pretty pleased with the way it turned out. It has been a few weeks since I published this notebook. So,
I am delighted to tell you that it has a Kaggle's Gold medal now. This being my 15th Gold on Notebooks (and my 15th Notebook) I am now a Kaggle Notebooks Grandmaster!

Thanks for visiting my Blog; it’s always good to see you here!

Find me on the following: 

·         Twitter
·         Goodreads

Links to my RNN Projects:


2 comments:

  1. Hello Stranger,

    13 years ago, a girl dedicated her first post to Paulo Coelho. I wonder if she has still arrived at the place she's meant to be?

    I guess not.

    Went through all of your 135 blogs last night and I can definitely say that

    Till she has those sparkle in her eyes, she's got miles to go!

    Karnika, your notebooks are wonderful, but more than that is your imagination and thought process!

    ReplyDelete
  2. Hey Adamya, Thanks for your nice comment. :)

    ReplyDelete