Skip to main content

The Maracanazo in color: generative adversarial networks to colorize photos and video

How GANs work, with a generator and a discriminator that learn by competing, what they are used for and how the model that colorized footage of the 1950 World Cup decider was trained.

Generative adversarial networks train two competing networks: one generates images and the other tries to spot the fakes. This article explains that mechanism through a hands-on case, colorizing photos and footage of Uruguay’s 1950 Maracanazo with AI, and covers their use in data augmentation, privacy and image translation, plus the technical details of the DeOldify model.

On July 16, 1950, Uruguay beat Brazil at the Maracanã stadium and won the World Cup, in the match that went down in history as the Maracanazo. In July 2022, 72 years later, I used artificial intelligence to colorize photos and video footage of that match. This article explains the technique behind it, generative adversarial networks, their most common applications and how the model I used was trained.

What generative adversarial networks (GANs) are

Within artificial intelligence there is a (not so) new concept: generative adversarial networks, or GANs.

The original paper was published by Goodfellow et al. in 2014 and explains the idea behind the concept. A GAN is a model for creating new “things,” and to do that, two models are trained.

Both are deep neural networks trained through backpropagation. The first is the generator and the second is a discriminator, which tries to guess whether the sample it receives is real or fake (produced by the first model).

An example makes it concrete. Imagine each model is a person: one is trying to learn to forge paintings by a particular artist, and the other is trying to tell whether the painting in front of them is a forgery or the real thing. Both the expert and the forger find out whether the expert guessed right, so both keep getting better: the forger paints more and more convincing pictures, and the expert gets better at spotting them. That “adversarial” mechanism is what makes both of them learn.

What GANs are used for

Besides being a very innovative idea, GANs have a wide range of applications. As an unsupervised generative model, a GAN can create new items from a set of similar ones, whether that is photos of faces, melodies or anything else. A now classic example is This Person Does Not Exist, which shows a hyper-realistic face of a person who doesn’t exist every time you reload the page. There are versions for art, cats and other subjects too.

GANs were originally unsupervised, with images generated from noise (the generator never sees the real data; it learns from the discriminator’s answers), but supervised versions came later. In those, the network gets some prior input, such as a rough sketch, and generates the image from it. Another well-known case built on the same principle turns photos of horses into zebras.

This opened up a world of possibilities in image-to-image translation, for example:

  • Satellite images to street maps like Google Maps.
  • Daytime images to nighttime.
  • Photos to artistic paintings.
  • A photo of a young person to how they might look when older.
  • Restoring damaged photos.
  • Black-and-white images to color.

It didn’t stop there: GANs were also trained to generate realistic images from a natural-language description of what the image should show. That idea led to other architectures that paved the way for DALL·E, Parti and Imagen. None of those three is a GAN: DALL·E 2 and Imagen are diffusion models, and Parti is autoregressive. Since then, diffusion has become the dominant technique for text-to-image generation.

The most obvious use of GANs is data augmentation. Getting data to train data science models is usually expensive and difficult, so this approach can turn a relatively small dataset into a much larger one. More data has been shown to improve performance.

A typical use case is quality control: generating fake but realistic images, through alterations, of industrial parts, for example.

GANs can also help with privacy. A company may not want to (or may be legally barred from) sharing customer data because it is confidential or sensitive (financial or medical records, for instance). Yet sometimes that data needs to be shared with third parties, such as researchers. Synthetic data lets the company share the general shape of the information without exposing any exact confidential record.

The Maracanazo in color: photos and video

I believe the images I colorized are original, since I looked not only for iconic Maracanazo photos but also for less familiar ones, although they probably won’t surprise many people. Others have already colorized images from the last World Cup Uruguay won, though I assume they did it by hand, with image editing software, rather than with artificial intelligence.

What may be a bit more original and less common is seeing footage from that era in color. I used a pre-trained model available through a Python library called DeOldify (its repository is now archived) and two videos published on YouTube: Uruguay champion 1950, the goals and “The day Brazil cried, Uruguay world champion 1950” (no longer available). Credits and rights to the videos and their music belong to their respective owners.

How the model was trained (for the technically curious)

Training this model has a few features that set it apart from training a “traditional” GAN.

With video, the key is stabilizing the output so there are no odd jumps or artifacts. Keep in mind that the model actually colorizes frame by frame, with no handling of time, so an object painted green one second could easily turn yellow the next.

A related point is the use of ResNet-101 as the generator’s backbone. This network has an initial convolutional layer followed by four stages of 9, 12, 69 and 9 convolutional layers. The architecture has proven “easier” to train than other very deep networks because, being residual, it has shortcuts that skip layers (which avoids problems such as vanishing gradients), while still performing very well on tasks like image classification.

The clever part is that instead of training it like an ordinary GAN, the generator is first trained the conventional way. It is fed color training images converted to black and white, and a loss function adjusts the weights so it learns to produce the color images from the black-and-white ones.

Next, the discriminator is trained: it is fed images produced by the generator along with real images, and trained as a standard binary classifier.

Finally, using only 1% to 3% of the ImageNet images, the generator and discriminator are trained together with the traditional GAN approach. This part of the training closely resembles a two-player minimax game: the generator tries to maximize the chance that the discriminator makes a mistake, and the discriminator tries to minimize its error.

The final model, built in PyTorch, is close to 900 MB. When the video quality is poor, the colors come out a bit “washed out,” but it does its job very well, and when the black-and-white footage is good quality, the results are flawless.

Héctor Cotelo
Data & Analytics Consultant

¿Listo para dar
el próximo paso?

Inicia tu camino
Otras publicaciones

Before asking how to use AI in a utility, it is worth asking whether the data is ready to support better decisions.

Six connected stages take a public power finance function from assessment to adoption, so AI can support better, faster and more traceable decisions.

Affordability, capital investment and resilience are now moving together. Utilities need scenarios to make decisions before the future becomes clear.

Quanam, a digital transformation, data and AI consultancy headquartered in Montevideo, Uruguay, is Certified in the Claude Partner Network. Its team holds Claude certifications, part of a path guided by one conviction: AI delivers more when people work alongside it.

Leave a Reply