DeepFlag: Designing Flags with AI

Using StyleGAN2-ADA to generate novel flags

Jaeseok (Jay) Park
6 min readJan 3, 2021
Examples of flags generated by DeepFlag

This article describes the passion project I undertook during my time at Metis Data Science Bootcamp (cohort Fall 2020).

What’s the Deal with Flags?

For the vast majority of us, flags are not something we think about daily. But as an exercise, let’s look at the national flag of the United States.

Just a few lines and colors. And some stars.

No matter which part of the world you’re from, this image will likely conjure up various emotions and thoughts regarding the United States, be it memories of the Invasion of Iraq in 2003, Team USA in various sporting events, or American brands like Coca-Cola. Similarly, flags and symbols such as the Nazi Swastika and The Rising Sun Flag hold so much adverse meaning in the present day that they’re considered extremely offensive or even illegal in many countries. So much for a few lines and colors.

In addition to serving a symbolic purpose, flags have numerous practical applications as well, such as at sea. For example, international maritime signal flags have been used to convey messages between ships for centuries. It is also customary and sometimes legally required to fly the country's flag that the ship is docked in (called a “courtesy flag”; see lower-right picture). Flying the host country flag below another flag, or flying it upside down, can be extremely disrespectful and can even indicate a willingness to fight!

Left: signal flags spelling out “NC,” communicating distress (image source). Right: flags and their positions indicate that this vessel is a British civil ship docked in a French port (image source).

In fact, there is an entire scholarly field dedicated to the studying of flags, called vexillology.

vexillology /ˌveksəˈläləjē/
noun
the study of flags

Perhaps because of their importance, designing and choosing new flags continues to be a difficult process. The 2015–2016 New Zealand flag referendums, for example, was a long, arduous process that ultimately resulted in New Zealand keeping their original flag, a bewildering process that satisfied few people.

Can you identify the New Zealand national flag? (image source)

Choosing a new flag is difficult not just due to the designing process but also by its inherently political nature. While I currently cannot offer any remedies for navigating politics, I was curious if artificial intelligence could provide inspiration and fresh ideas in the designing phase of new flags.

Utilizing Generative-Adversarial Networks (GANs)

Readers of this article may be aware of a website called “This Person Does Not Exist,” created by Phillip Wang.

ThisPersonDoesNotExist utilizes GANs to make fake faces like the ones above.

The machine learning algorithm for generating these faces uses a framework called a generative-adversarial network (GAN). Briefly, GANs are composed of two modules: the Generator and the Discriminator. The Generator is fed hundreds to tens of thousands of example images, which generate novel images based on perceived patterns. On the other hand, the Discriminator attempts to distinguish between the fake images generated by the Generator and real example images. Both modules use the other to progressively make themselves better through applying loss functions and adjusting weights through backpropagation (if this jargon doesn’t make sense to you, take away that the two networks are continuously “learning” from their mistakes and updating parameters).

To train my DeepFlag algorithm, I web-scraped ~1500 flags of various nation-states, provinces, municipalities, organizations (e.g., NATO), and some custom-made flags (e.g., LGBT flag). Also, I did some manual curation of the dataset to EXCLUDE flags that had prominent lettering, such as the flag of Simi Valley, California. The specific GAN I used was StyleGAN2-ADA developed by researchers at NVIDIA. The primary reason I chose this algorithm is that StyleGAN2-ADA works well with a relatively small number of training images (hundreds to thousands), rather than the tens of thousands required to train a traditional GAN.

While I did have a brand-new laptop (2020 MacBook Pro, 13-inch), training the GAN on my local computer would have been unbearably slow, if it completed at all. Fortunately, Google Colab offers an easy way for laypeople to take advantage of cloud computing. While the base version is free, I signed up for Google Colab Pro (~$10/mo) to gain easier access to the NVIDIA Tesla P100 GPU and the NVIDIA V100 GPU (Colab randomly assigns you a GPU between the K80, P100, or the V100; going Pro virtually guaranteed the P100 for me, and gave me access to V100 from time to time). With the P100, I was able to get preliminary training results within about 7–10 hours or so, which is quite fast for GAN training.

Google Colab Pro gives you access to GPUs that could be prohibitively expensive for many.

Generating Flags with DeepFlag

Tweaking the parameters for training was difficult, and sometimes slight alterations to the parameters led to wildly different results. Nevertheless, I was eventually able to get the algorithm to generate a few reasonable rough drafts for new flags. I was never able to get to a point where the GANs generated 100% realistic flags, for reasons which I will speculate on later.

I tentatively classified the chosen flags into three categories.

  1. Flags that are very similar to existing flags.
These generated flags (left) are very similar to existing national flags (right)

2. Flags that are distinct from existing flags but can be considered reasonable flag designs. Since I could not get the GANs to generate perfect lines and circles, I took artistic liberty and imagined what the actual flags might look like.

The generated flags (left) have been reimagined and cleaned up (right)

3. Flags that are interesting or aesthetically pleasing to look at in their own right. “Flag Art,” so to speak. Some of these are absolutely mesmerizing to look at.

Mesmerizing/disturbing/interesting works of art

Discussion and Conclusions

Why is DeepFlag unable to generate ultra-realistic flags as in the case of ThisPersonDoesNotExist? Some hypotheses:

  1. While the training has been carried out for ~2 weeks under various settings, the module may still be undertrained.
  2. Popular GAN subjects such as human/animal faces have many common features that tie all subjects together (e.g., eye, nose, roundish face) while abstract flag designs have no common feature unifying them, perhaps except that the vast majority are squared or rectangular.

The second point is bolstered by another recent flag-generating GAN project by Erin Davis, which I discovered after the completion of my project. Erin generated Japanese municipal flags using StyleGAN2. What makes Japanese municipal flags special is that the overwhelming majority of the flags have a simple symbol in the middle on a single-color background (see examples). This likely allowed the GAN to easily pick up this feature and incorporate it into the generator.

DeepFlag also picked up many of the features that are commonly present in various flags. Such common features include:

  • Use of bright, saturated colors
  • A majority (~85%+) of the flags utilizing blue and/or red
  • A prominent symbol in the middle of the flag
  • The tricolor design (both horizontal and vertical)
  • Use of stars

In conclusion, this project used GANs to generate novel flags, with some surprising and unexpected consequences. Although the training process was arduous, I was surprised by how well Google Colab worked. Finally, I developed a new appreciation for flags and their designs, as well as being immersed in the fascinating field of vexillology. I should perhaps now dare call myself an amateur vexillologist.

Jay’s LinkedIn profile

GitHub repository for this project

Acknowledgments

--

--

Jaeseok (Jay) Park
Jaeseok (Jay) Park

Written by Jaeseok (Jay) Park

Data scientist, biologist, and lifetime learner. An Avid reader of The Economist. Cambridge, MA

No responses yet