In [1]:
#@title Check GPU
#@markdown Run this to connect to a Colab Instance, and see what GPU Google gave you.
gpu = !nvidia-smi --query-gpu=gpu_name --format=csv
print(gpu[1])
print("The Tesla T4 and P100 are fast and support hardware encoding. The K80 and P4 are slower.")
print("Sometimes resetting the instance in the 'runtime' tab will give you a different GPU.")
In [2]:
from google.colab import drive
drive.mount('/content/drive')
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.
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.
In [3]:
#@title Check GPU
#@markdown Run this to connect to a Colab Instance, and see what GPU Google gave you.
gpu = !nvidia-smi --query-gpu=gpu_name --format=csv
print(gpu[1])
print("The Tesla T4 and P100 are fast and support hardware encoding. The K80 and P4 are slower.")
print("Sometimes resetting the instance in the 'runtime' tab will give you a different GPU.")
In [0]:
from os import path
import torch
In [5]:
!git clone https://github.com/jantic/DeOldify.git DeOldify
In [6]:
cd DeOldify
In [7]:
!pip install -r colab_requirements.txt
In [0]:
import fastai
from deoldify.visualize import *
from pathlib import Path
torch.backends.cudnn.benchmark=True
In [9]:
!mkdir 'models'
!wget https://www.dropbox.com/s/336vn9y4qwyg9yz/ColorizeVideo_gen.pth?dl=0 -O ./models/ColorizeVideo_gen.pth
In [10]:
!wget https://media.githubusercontent.com/media/jantic/DeOldify/master/resource_images/watermark.png -O ./resource_images/watermark.png
In [11]:
colorizer = get_video_colorizer()
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.
If you get a 'CUDA out of memory' error, you probably have the render_factor too high. The max is 44 on 11GB video cards.
In [14]:
source_url = 'https://www.youtube.com/watch?v=pwfwtHWtFkc' #@param {type:"string"}
render_factor = 12 #@param {type: "slider", min: 5, max: 45}
watermarked = False #@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.')
In [0]:
for i in range(10,45,2):
colorizer.vis.plot_transformed_image('video/bwframes/video/00001.jpg', render_factor=i, display_render_factor=True, figsize=(8,8))
In [0]:
#Save video to drive
#Append render_factor to end of file name, try multiple values
In [0]:
!mkdir "//content/drive/My Drive/kontext/deold/3"
In [0]:
!cp video/result/video.mp4 {'"//content/drive/My Drive/kontext/deold/3/exp_'+str(render_factor)+'.mp4"'}