Open In App

Colorize Images Using Deoldify

Deoldify is the project used to colorize and restore old images from Black and white format. It was developed by Jason Antic. Deoldify uses GAN architecture to colorize the image. It contains a generator that added color to the critic (Discriminator), the goal of which to criticize the coloring generated by the generator. It proposed a special type of GAN training method called No-GAN.

Architectural Details

The author uses the following deep learning concepts in these models. These concepts are:



No-GAN

This is a new type of GAN training that is developed by the authors of Deoldify. It provides the benefits of GAN training while spending minimal time doing direct GAN training. Instead, we spent most time training generator and critic separately with more straight-forward, fast, and reliable conventional methods.

The steps are as follows:  



All the important GAN training only takes place in a very small fraction of time. There’s an inflection point where it appears the critic has transferred all the useful knowledge to the generator. There appears to be no productive training after the model achieved the inflection point. The hard part appears to be finding the inflection point and the model is quite unstable, so the author has to create a lot of checkpoints. Another key thing about No-GAN is that you can repeat pre-training the critic on generated images after the initial GAN training, then repeat the GAN training itself in the same fashion.

There are 3 types of models that are trained by Deoldify:

Implementation




# Clone deoldify Repository
! git clone https://github.com/jantic/DeOldify.git DeOldify
  
# change directory to DeOldify Repo
cd DeOldify
  
# For Colab
! pip install -r colab_requirements.txt
# For Local Script
! pip install -r requirements.txt
  
# import pytorch library
import torch
# check for GPU
if not torch.cuda.is_available():
    print('GPU not available.')
# necessary imports
import fastai
from deoldify.visualize import *
import warnings
warnings.filterwarnings("ignore"
                        category=UserWarning, message=".*?Your .*? set is empty.*?")
# download the artistic model
!mkdir 'models'
!wget https://data.deepai.org/deoldify/ColorizeArtistic_gen.pth -
  ./models/ColorizeArtistic_gen.pth
  
# use the get image colorizer function with artistic model
colorizer = get_image_colorizer(artistic=True)
  
# Here, we provide the parameters such as source URL, render factor etc.
'&crop=smart&auto=webp&s=a5f2523513bb24648737760369d2864eb1f57118' #@param {type:"string"}
render_factor = 39  #@param {type: "slider", min: 7, max: 40}
watermarked = False #@param {type:"boolean"}
  
if source_url is not None and source_url !='':
    image_path = colorizer.plot_transformed_image_from_url(url=source_url, 
          render_factor=render_factor, compare=True, watermarked=watermarked)
    show_image_in_notebook(image_path)
else:
    print('Provide the valid image URL.')

DeOldify Results (Original B/W Image Credit here)

DeOldify Stable Results

References:


Article Tags :