Files
Praveenhalder-ComfyUI-DeOldify/VideoColorizerColab.ipynb
T

8.2 KiB

Open In Colab

#◢ [ DeOldify-video

##This Colab notebook colorizes video in four steps

  1. Upload source media or specify media URL - YouTube, Twitter, MySpace, etc.
  2. Extract single images from media
  3. Process images with DeOldify
  4. Rebuild the video from colorized images

I'm on twitter @tradica


Thanks @citnaj for creating DeOldify and thanks to Matt Robinson for his notebook. It helped make DeOldify approachable.


#◢ [ Set Runtime type to Python 3/GPU In the Runtime menu above be sure:

  • Runtime Type = Python 3
  • Hardware Accelerator = GPU <-------------- IMPORTANT
In [ ]:
from os import path
import torch
print(torch.__version__)
print(torch.cuda.is_available())

#◢ 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 PyDrive
!pip install ffmpeg-python
!pip install youtube-dl
!pip install tensorboardX
In [ ]:
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
from google.colab import drive
import fastai
from fasterai.visualize import *
from pathlib import Path
from itertools import repeat
from google.colab import drive
from google.colab import files
torch.backends.cudnn.benchmark=True
In [ ]:
!mkdir 'models'
!wget https://www.dropbox.com/s/zqt6pzcmoztda0l/ColorizeVideos_gen2.pth?dl=0 -O ./models/ColorizeVideos_gen2.pth

#◢ Render Factor

Determines resolution at which video is rendered. Higher is generally better (not always however!). Default is carefully chosen and should work for most scenarios

In [ ]:
render_factor = 36  #@param {type: "slider", min: 5, max: 45}

#◢ Specify URL

YouTube, Imgur, Twitter, MySpace, Reddit ... most work. NOTE: If this is ommitted, you can just upload the file later in the workflow

In [ ]:
source_url = '' #@param {type:"string"}

#◢ Additional Parameters

It's not recommended to change the following (not really necessary)

In [ ]:
file_name = 'video.mp4'
source_dir = './video/source/'
source_path = source_dir + file_name
dest_dir = './video/result/'
dest_path = dest_dir + file_name
In [ ]:
!mkdir file_dir

#◢ DeOldify / Colorize

In [ ]:
colorizer = get_video_colorizer(render_factor=render_factor)
In [ ]:
if source_url is not None and source_url !='':
    colorizer.colorize_from_url(source_url, file_name)
else:
    #UPLOAD File Here
    source_media = files.upload()
    os.system('ln -s /content/WORKFOLDER/' + list(source_media.keys())[0] + ' ' + source_path)
    colorizer.colorize_from_file_name(file_name)

#◢ Download

  • In the Menu on the left, click Files
  • Click refresh button if you don't see the 'DeOldify' folder.
  • Rendered video should be in /DeOldify/video/result/

#⚙ Some great video and gif sources