VideoColorizerColab.ipynb
<a href="https://colab.research.google.com/github/jantic/DeOldify/blob/master/VideoColorizerColab.ipynb" target="_parent"></a>
#◢ DeOldify - Colorize your own videos!
FYI: This notebook is intended as a tool to colorize gifs and short videos, if you are trying to convert longer video you may hit the limit on processing space. Running the Jupyter notebook on your own machine is recommended (and faster) for larger video sizes.
####Credits:
Big special thanks to:
Robert Bell for all his work on the video Colab notebook, and paving the way to video in DeOldify!
Dana Kelley for doing things, breaking stuff & having an opinion on everything.
#◢ Verify Correct Runtime Settings
<font color='#FF000'> IMPORTANT </font>
In the "Runtime" menu for the notebook window, select "Change runtime type." Ensure that the following are selected:
#◢ Git clone and install DeOldify
!git clone https://github.com/jantic/DeOldify.git DeOldify
cd DeOldify
#◢ Setup
#NOTE: This must be the first call in order to work properly!
from deoldify import device
from deoldify.device_id import DeviceId
#choices: CPU, GPU0...GPU7
device.set(device=DeviceId.GPU0)
import torch
if not torch.cuda.is_available():
print('GPU not available.')
from os import path
!pip install -r requirements-colab.txt
import fastai
from deoldify.visualize import *
from pathlib import Path
torch.backends.cudnn.benchmark=True
import warnings
warnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")
!mkdir 'models'
!wget https://data.deepai.org/deoldify/ColorizeVideo_gen.pth -O ./models/ColorizeVideo_gen.pth
colorizer = get_video_colorizer()
#◢ Instructions
Type in a url hosting a video from YouTube, Imgur, Twitter, Reddit, Vimeo, etc. Many sources work! GIFs also work. Full list here: https://ytdl-org.github.io/youtube-dl/supportedsites.html NOTE: If you want to use your own video, upload it first to a site like YouTube.
The default value of 21 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 video is rendered. Lower resolution will render faster, and colors also tend to look more vibrant. Older and lower quality film in particular will generally benefit by lowering the render factor. Higher render factors are often better for higher quality videos and inconsistencies (flashy render) will generally be reduced, but the colors may get slightly washed out.
Selected by default, this places a watermark icon of a palette at the bottom left corner of the image. This is intended to be a standard way to convey to others viewing the image that it is colorized by AI. We want to help promote this as a standard, especially as the technology continues to improve and the distinction between real and fake becomes harder to discern. This palette watermark practice was initiated and lead by the company MyHeritage in the MyHeritage In Color feature (which uses a newer version of DeOldify than what you're using here).
Simply right click on the displayed video and click "Save video as..."!
The video player may wind up not showing up, in which case- make sure to wait for the Jupyter cell to complete processing first (the play button will stop spinning). Then follow these alternative download instructions
If a video you downloaded doesn't play, it's probably because the cell didn't complete processing and the video is in a half-finished state.
#◢ Colorize!!
source_url = '' #@param {type:"string"}
render_factor = 21 #@param {type: "slider", min: 5, max: 40}
watermarked = True #@param {type:"boolean"}
if source_url is not None and source_url !='':
video_path = colorizer.colorize_from_url(source_url, 'video.mp4', render_factor, watermarked=watermarked)
show_video_in_notebook(video_path)
else:
print('Provide a video url and try again.')
for i in range(10,40,2):
colorizer.vis.plot_transformed_image('video/bwframes/video/00001.jpg', render_factor=i, display_render_factor=True, figsize=(8,8))
#⚙ Recommended video and gif sources