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
First, you need to have Jina installed
!pip install jina
There is a jina demo server available for us to play with.
= 'grpc://dalle-flow.jina.ai:51005' server_url
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.
= 'a rainy photo of the seattle space needle in the background and buildings in the foreground from a hotel window at night' prompt
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
= Document(text=prompt).post(server_url, parameters={'num_images': 2}).matches
da =(10,10), show_index=True) da.plot_image_sprites(fig_size
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.
= 2
fav_id = da[fav_id]
fav 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
= fav.post(f'{server_url}', parameters={'skip_rate': 0.3, 'num_images': 4}, target_executor='diffusion').matches
diffused =(10,10), show_index=True) diffused.plot_image_sprites(fig_size
Select the image you like most by setting the variable dfav_id
. We can look at it individually.
= 1
dfav_id
= diffused[dfav_id]
fav fav.display()
Finally, submit to the server for upscaling to 1024x1024px.
%%time
= fav.post(f'{server_url}/upscale')
fav 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.
This is an automated list of software versions used during the writing of this article.
Software Version
Ubuntu 20.04.4 LTS
Python 3.8.5