Delving into Delusion

Creating Art with Artificial Intelligence

 June 06, 2022      Stardate: 75894.7     Tagged as: Python

I was surfing YouTube and watched a video by Vox about art created by Artificial Intelligence. In the beginning, AI was used to label an image but soon some very creative people wanted to reverse the process and have AI create an image from labels. I think most people know that deep-learning Neural Nets and other tech have exploded allowing deep fakes and other applications…including one of the original desires to create art from labels or “prompts”. They provided a link to a page of available AI art tools - https://pharmapsychotic.com/tools.html.

A couple hours later I was wasting time again and reading through Reddit/r/pics and saw picture of the space needle at night in the rain…and I thought, “I wonder if I can get an Neural Net(NN) to create a piece of art with similar style and content.”

Here is the original image. Source: reddit user u/johnstone13

Python Script

First, you need to have Jina installed

!pip install jina

There is a jina demo server available for us to play with.

server_url = 'grpc://dalle-flow.jina.ai:51005'

The next step is quite important. You need to craft the “prompt” or labels that the AI will use. I admit I goofed around with this part for 30 minutes, adjusting the adjectives and sentence until it produced a desirable result.

prompt = 'a rainy photo of the seattle space needle in the background and buildings in the foreground from a hotel window at night'

Submit the prompt to the server which generates 4 candidates, 2 from DALL·E-Mega and 2 from GLID3 XL. This takes about 3 minutes.

%%time
from docarray import Document

da = Document(text=prompt).post(server_url, parameters={'num_images': 2}).matches
da.plot_image_sprites(fig_size=(10,10), show_index=True)

There is an index value in the upper-left of each of the four results. Select your favorite result and place the index in the fav_id below.

fav_id = 2
fav = da[fav_id]
fav.display()

Now we submit the selected candidate to the server for diffusion. This will give 4 images based on the given image. You may allow the model to improvise more by giving skip_rate a near-zero value, or a near-one value to force its closeness to the given image. The whole procedure takes another couple minutes.

%%time

diffused = fav.post(f'{server_url}', parameters={'skip_rate': 0.3, 'num_images': 4}, target_executor='diffusion').matches
diffused.plot_image_sprites(fig_size=(10,10), show_index=True)

Select the image you like most by setting the variable dfav_id. We can look at it individually.

dfav_id = 1

fav = diffused[dfav_id]
fav.display()

Finally, submit to the server for upscaling to 1024x1024px.

%%time

fav = fav.post(f'{server_url}/upscale')
fav.display()

So here is the final image. This is my AI computer-generated art inspired by the original photo above.

Note that all images generated by the AI have a large amount of randomness involved, so even if you use the exact same prompts you will receive different results.

You can take this code, change the prompts to anything, and generate your own images. There is a huge range of possible outputs. from realistic to surrealism.

Software Versions

This is an automated list of software versions used during the writing of this article.

SoftwareVersion
Ubuntu 20.04.4 LTS
Python 3.8.5