Files
Praveenhalder-ComfyUI-DeOldify/ImageColorizerColab.ipynb
T
2019-04-21 00:11:42 -07:00

7.0 KiB

Open In Colab

#◢ DeOldify - Colorize your own photos!

####Credits:

Special thanks to:

Matt Robinson and María Benavente for pioneering the DeOldify image colab notebook.

Dana Kelley for doing things, breaking stuff & having an opinion on everything.


#◢ Verify Correct Runtime Settings

IMPORTANT

In the "Runtime" menu for the notebook window, select "Change runtime type." Ensure that the following are selected:

  • Runtime Type = Python 3
  • Hardware Accelerator = GPU
In [ ]:
from os import path
import torch

#◢ Git clone and install DeOldify

In [ ]:
!git clone -b FastAIv1 --single-branch https://github.com/jantic/DeOldify.git DeOldify
#!git clone https://github.com/jantic/DeOldify.git DeOldify 
In [ ]:
cd DeOldify

#◢ Setup

In [ ]:
!pip install -r requirements.txt
In [ ]:
import fastai
from fasterai.visualize import *
from pathlib import Path
torch.backends.cudnn.benchmark=True
In [ ]:
!mkdir 'models'
!wget wget https://www.dropbox.com/s/zkehq1uwahhbc2o/ColorizeArtistic_gen.pth?dl=0 -O ./models/ColorizeArtistic_gen.pth
In [ ]:
colorizer = get_image_colorizer(artistic=True)

#◢ Instructions

source_url

Type in a url to a direct link of an image. Usually that means they'll end in .png, .jpg, etc. NOTE: If you want to use your own image, upload it first to a site like Imgur.

render_factor

The default value of 35 has been carefully chosen and should work -ok- for most scenarios (but probably won't be the -best-). This determines resolution at which the color portion of the image is rendered. Lower resolution will render faster, and colors also tend to look more vibrant. Older and lower quality images in particular will generally benefit by lowering the render factor. Higher render factors are often better for higher quality images, but the colors may get slightly washed out.

How to Download a Copy

Simply right click on the displayed image and click "Save image as..."!

Pro Tips

  1. You can evaluate how well the image is rendered at each render_factor by using the code at the bottom (that cell under "See how well render_factor values perform on a frame here").
  2. Keep in mind again that you can go up top and set artistic to False for the colorizer to use the 'Stable' model instead. This will often tend to do better on portraits, and natural landscapes.

Troubleshooting

If you get a 'CUDA out of memory' error, you probably have the render_factor too high. The max is 45 on 11GB video cards.

#◢ Colorize!!

In [ ]:
source_url = '' #@param {type:"string"}
render_factor = 35  #@param {type: "slider", min: 7, max: 45}

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)
    show_image_in_notebook(image_path)
else:
    print('Provide an image url and try again.')

See how well render_factor values perform on the image here

In [ ]:
for i in range(10,46,2):
    colorizer.plot_transformed_image('test_images/image.png', render_factor=i, display_render_factor=True, figsize=(8,8))

#⚙ Recommended image sources