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.")


Tesla P100-PCIE-16GB
The Tesla T4 and P100 are fast and support hardware encoding. The K80 and P4 are slower.
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')


Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly

Enter your authorization code:
··········
Mounted at /content/drive

Video Colorizer

◢ 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

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 [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.")


Tesla P100-PCIE-16GB
The Tesla T4 and P100 are fast and support hardware encoding. The K80 and P4 are slower.
Sometimes resetting the instance in the 'runtime' tab will give you a different GPU.

In [0]:
from os import path
import torch

◢ Git clone and install DeOldify


In [5]:
!git clone https://github.com/jantic/DeOldify.git DeOldify


Cloning into 'DeOldify'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 2021 (delta 10), reused 12 (delta 7), pack-reused 2003
Receiving objects: 100% (2021/2021), 69.33 MiB | 37.38 MiB/s, done.
Resolving deltas: 100% (888/888), done.

In [6]:
cd DeOldify


/content/DeOldify

◢ Setup


In [7]:
!pip install -r colab_requirements.txt


Collecting fastai==1.0.51
  Downloading https://files.pythonhosted.org/packages/44/cc/dcc702cf43bb8c908d172e5be156615928f962366a20834c320cbca2b9d0/fastai-1.0.51-py3-none-any.whl (214kB)
     |████████████████████████████████| 215kB 2.8MB/s 
Collecting tensorboardX==1.6
  Downloading https://files.pythonhosted.org/packages/5c/76/89dd44458eb976347e5a6e75eb79fecf8facd46c1ce259bad54e0044ea35/tensorboardX-1.6-py2.py3-none-any.whl (129kB)
     |████████████████████████████████| 133kB 8.5MB/s 
Collecting ffmpeg
  Downloading https://files.pythonhosted.org/packages/f0/cc/3b7408b8ecf7c1d20ad480c3eaed7619857bf1054b690226e906fdf14258/ffmpeg-1.4.tar.gz
Collecting ffmpeg-python==0.1.17
  Downloading https://files.pythonhosted.org/packages/3d/10/330cbc8e63d072d40413f4d470444a6a1e8c8c6a80b2a4ac302d1252ca1b/ffmpeg_python-0.1.17-py3-none-any.whl
Collecting youtube-dl>=2019.4.17
  Downloading https://files.pythonhosted.org/packages/6c/93/aacfa17b0ce61d5c3786da825e085639d3430e8f81f3531a3dc738c9c80c/youtube_dl-2020.3.8-py2.py3-none-any.whl (1.8MB)
     |████████████████████████████████| 1.8MB 11.7MB/s 
Collecting jupyterlab
  Downloading https://files.pythonhosted.org/packages/36/d6/9e6a8a04f4fc337fbc05065d1ba4ba3460a09ee41355410bcd6d8be8841a/jupyterlab-2.0.1-py3-none-any.whl (7.7MB)
     |████████████████████████████████| 7.7MB 21.0MB/s 
Requirement already satisfied: opencv-python>=3.3.0.10 in /usr/local/lib/python3.6/dist-packages (from -r colab_requirements.txt (line 7)) (4.1.2.30)
Requirement already satisfied: pillow in /usr/local/lib/python3.6/dist-packages (from -r colab_requirements.txt (line 8)) (7.0.0)
Requirement already satisfied: torch>=1.0.0 in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.4.0)
Requirement already satisfied: packaging in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (20.3)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (3.2.0)
Requirement already satisfied: fastprogress>=0.1.19 in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (0.2.2)
Requirement already satisfied: dataclasses; python_version < "3.7" in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (0.7)
Requirement already satisfied: spacy>=2.0.18 in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (2.2.4)
Requirement already satisfied: bottleneck in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.3.2)
Requirement already satisfied: torchvision in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (0.5.0)
Requirement already satisfied: numexpr in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (2.7.1)
Requirement already satisfied: pyyaml in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (3.13)
Requirement already satisfied: nvidia-ml-py3 in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (7.352.0)
Requirement already satisfied: typing in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (3.6.6)
Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (0.25.3)
Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (4.6.3)
Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (2.21.0)
Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.4.1)
Requirement already satisfied: numpy>=1.15 in /usr/local/lib/python3.6/dist-packages (from fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.18.2)
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from tensorboardX==1.6->-r colab_requirements.txt (line 2)) (1.12.0)
Requirement already satisfied: protobuf>=3.2.0 in /usr/local/lib/python3.6/dist-packages (from tensorboardX==1.6->-r colab_requirements.txt (line 2)) (3.10.0)
Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from ffmpeg-python==0.1.17->-r colab_requirements.txt (line 4)) (0.16.0)
Collecting jupyterlab-server~=1.0.0
  Downloading https://files.pythonhosted.org/packages/3c/ea/ae83699c4217d5668f62402445bbe4da11cc63898fbe7a57d8fed6281a04/jupyterlab_server-1.0.7-py3-none-any.whl
Requirement already satisfied: jinja2>=2.10 in /usr/local/lib/python3.6/dist-packages (from jupyterlab->-r colab_requirements.txt (line 6)) (2.11.1)
Requirement already satisfied: tornado!=6.0.0,!=6.0.1,!=6.0.2 in /usr/local/lib/python3.6/dist-packages (from jupyterlab->-r colab_requirements.txt (line 6)) (4.5.3)
Requirement already satisfied: notebook>=4.3.1 in /usr/local/lib/python3.6/dist-packages (from jupyterlab->-r colab_requirements.txt (line 6)) (5.2.2)
Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from packaging->fastai==1.0.51->-r colab_requirements.txt (line 1)) (2.4.6)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->fastai==1.0.51->-r colab_requirements.txt (line 1)) (2.8.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.1.0)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib->fastai==1.0.51->-r colab_requirements.txt (line 1)) (0.10.0)
Requirement already satisfied: blis<0.5.0,>=0.4.0 in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (0.4.1)
Requirement already satisfied: preshed<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (3.0.2)
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (46.0.0)
Requirement already satisfied: thinc==7.4.0 in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (7.4.0)
Requirement already satisfied: srsly<1.1.0,>=1.0.2 in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.0.2)
Requirement already satisfied: wasabi<1.1.0,>=0.4.0 in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (0.6.0)
Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (2.0.3)
Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.0.2)
Requirement already satisfied: catalogue<1.1.0,>=0.0.7 in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.0.0)
Requirement already satisfied: plac<1.2.0,>=0.9.6 in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.1.3)
Requirement already satisfied: tqdm<5.0.0,>=4.38.0 in /usr/local/lib/python3.6/dist-packages (from spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (4.38.0)
Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas->fastai==1.0.51->-r colab_requirements.txt (line 1)) (2018.9)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests->fastai==1.0.51->-r colab_requirements.txt (line 1)) (2.8)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.24.3)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests->fastai==1.0.51->-r colab_requirements.txt (line 1)) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->fastai==1.0.51->-r colab_requirements.txt (line 1)) (2019.11.28)
Collecting jsonschema>=3.0.1
  Downloading https://files.pythonhosted.org/packages/c5/8f/51e89ce52a085483359217bc72cdbf6e75ee595d5b1d4b5ade40c7e018b8/jsonschema-3.2.0-py2.py3-none-any.whl (56kB)
     |████████████████████████████████| 61kB 9.1MB/s 
Collecting json5
  Downloading https://files.pythonhosted.org/packages/96/0b/e35ce1df75f15147b03cd0c87835b6351a63c87e2924fdf5910520b0f9c5/json5-0.9.3-py2.py3-none-any.whl
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.6/dist-packages (from jinja2>=2.10->jupyterlab->-r colab_requirements.txt (line 6)) (1.1.1)
Requirement already satisfied: nbconvert in /usr/local/lib/python3.6/dist-packages (from notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (5.6.1)
Requirement already satisfied: nbformat in /usr/local/lib/python3.6/dist-packages (from notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (5.0.4)
Requirement already satisfied: jupyter-client in /usr/local/lib/python3.6/dist-packages (from notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (5.3.4)
Requirement already satisfied: traitlets>=4.2.1 in /usr/local/lib/python3.6/dist-packages (from notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (4.3.3)
Requirement already satisfied: ipython-genutils in /usr/local/lib/python3.6/dist-packages (from notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.2.0)
Requirement already satisfied: terminado>=0.3.3; sys_platform != "win32" in /usr/local/lib/python3.6/dist-packages (from notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.8.3)
Requirement already satisfied: ipykernel in /usr/local/lib/python3.6/dist-packages (from notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (4.6.1)
Requirement already satisfied: jupyter-core in /usr/local/lib/python3.6/dist-packages (from notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (4.6.3)
Requirement already satisfied: importlib-metadata>=0.20; python_version < "3.8" in /usr/local/lib/python3.6/dist-packages (from catalogue<1.1.0,>=0.0.7->spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (1.5.0)
Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.6/dist-packages (from jsonschema>=3.0.1->jupyterlab-server~=1.0.0->jupyterlab->-r colab_requirements.txt (line 6)) (19.3.0)
Requirement already satisfied: pyrsistent>=0.14.0 in /usr/local/lib/python3.6/dist-packages (from jsonschema>=3.0.1->jupyterlab-server~=1.0.0->jupyterlab->-r colab_requirements.txt (line 6)) (0.15.7)
Requirement already satisfied: entrypoints>=0.2.2 in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.3)
Requirement already satisfied: defusedxml in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.6.0)
Requirement already satisfied: testpath in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.4.4)
Requirement already satisfied: mistune<2,>=0.8.1 in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.8.4)
Requirement already satisfied: bleach in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (3.1.3)
Requirement already satisfied: pandocfilters>=1.4.1 in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (1.4.2)
Requirement already satisfied: pygments in /usr/local/lib/python3.6/dist-packages (from nbconvert->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (2.1.3)
Requirement already satisfied: pyzmq>=13 in /usr/local/lib/python3.6/dist-packages (from jupyter-client->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (17.0.0)
Requirement already satisfied: decorator in /usr/local/lib/python3.6/dist-packages (from traitlets>=4.2.1->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (4.4.2)
Requirement already satisfied: ptyprocess; os_name != "nt" in /usr/local/lib/python3.6/dist-packages (from terminado>=0.3.3; sys_platform != "win32"->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.6.0)
Requirement already satisfied: ipython>=4.0.0 in /usr/local/lib/python3.6/dist-packages (from ipykernel->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (5.5.0)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/dist-packages (from importlib-metadata>=0.20; python_version < "3.8"->catalogue<1.1.0,>=0.0.7->spacy>=2.0.18->fastai==1.0.51->-r colab_requirements.txt (line 1)) (3.1.0)
Requirement already satisfied: webencodings in /usr/local/lib/python3.6/dist-packages (from bleach->nbconvert->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.5.1)
Requirement already satisfied: pickleshare in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0->ipykernel->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.7.5)
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0->ipykernel->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (4.8.0)
Requirement already satisfied: simplegeneric>0.8 in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0->ipykernel->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.8.1)
Requirement already satisfied: prompt-toolkit<2.0.0,>=1.0.4 in /usr/local/lib/python3.6/dist-packages (from ipython>=4.0.0->ipykernel->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (1.0.18)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/dist-packages (from prompt-toolkit<2.0.0,>=1.0.4->ipython>=4.0.0->ipykernel->notebook>=4.3.1->jupyterlab->-r colab_requirements.txt (line 6)) (0.1.8)
Building wheels for collected packages: ffmpeg
  Building wheel for ffmpeg (setup.py) ... done
  Created wheel for ffmpeg: filename=ffmpeg-1.4-cp36-none-any.whl size=6084 sha256=eedfd29d8228a9f879498ddbd842582eca6c00d0201842437fb4d7b622bba31f
  Stored in directory: /root/.cache/pip/wheels/b6/68/c3/a05a35f647ba871e5572b9bbfc0b95fd1c6637a2219f959e7a
Successfully built ffmpeg
Installing collected packages: fastai, tensorboardX, ffmpeg, ffmpeg-python, youtube-dl, jsonschema, json5, jupyterlab-server, jupyterlab
  Found existing installation: fastai 1.0.60
    Uninstalling fastai-1.0.60:
      Successfully uninstalled fastai-1.0.60
  Found existing installation: jsonschema 2.6.0
    Uninstalling jsonschema-2.6.0:
      Successfully uninstalled jsonschema-2.6.0
Successfully installed fastai-1.0.51 ffmpeg-1.4 ffmpeg-python-0.1.17 json5-0.9.3 jsonschema-3.2.0 jupyterlab-2.0.1 jupyterlab-server-1.0.7 tensorboardX-1.6 youtube-dl-2020.3.8

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


--2020-03-22 11:53:00--  https://www.dropbox.com/s/336vn9y4qwyg9yz/ColorizeVideo_gen.pth?dl=0
Resolving www.dropbox.com (www.dropbox.com)... 162.125.9.1, 2620:100:601f:1::a27d:901
Connecting to www.dropbox.com (www.dropbox.com)|162.125.9.1|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: /s/raw/336vn9y4qwyg9yz/ColorizeVideo_gen.pth [following]
--2020-03-22 11:53:01--  https://www.dropbox.com/s/raw/336vn9y4qwyg9yz/ColorizeVideo_gen.pth
Reusing existing connection to www.dropbox.com:443.
HTTP request sent, awaiting response... 302 Found
Location: https://uc963dc41e79b51807c12675b81d.dl.dropboxusercontent.com/cd/0/inline/A0bJVxxWY2tP491ddMx-a5GLuCvD8I0bb9fL67C7KIur5GBkvUWgLj02BPl1-O_xMLklcd9rgITwXFm4VI8qjW-J-HHw3zQMx3Ouwb3xmJjBxw/file# [following]
--2020-03-22 11:53:01--  https://uc963dc41e79b51807c12675b81d.dl.dropboxusercontent.com/cd/0/inline/A0bJVxxWY2tP491ddMx-a5GLuCvD8I0bb9fL67C7KIur5GBkvUWgLj02BPl1-O_xMLklcd9rgITwXFm4VI8qjW-J-HHw3zQMx3Ouwb3xmJjBxw/file
Resolving uc963dc41e79b51807c12675b81d.dl.dropboxusercontent.com (uc963dc41e79b51807c12675b81d.dl.dropboxusercontent.com)... 162.125.9.6, 2620:100:601f:6::a27d:906
Connecting to uc963dc41e79b51807c12675b81d.dl.dropboxusercontent.com (uc963dc41e79b51807c12675b81d.dl.dropboxusercontent.com)|162.125.9.6|:443... connected.
HTTP request sent, awaiting response... 302 FOUND
Location: /cd/0/inline2/A0bzlagT69B0pDhb4kWcZvE6OdIHeNCurVKEF_BeO5NjidQtoKDgiryEmiU3NKjOq0ZtfLCBPf8C6Yff4P0PwlTyXmLrEuOmJVOoK06ELoeDxQRC7Ag2_kTL4CcvLOfC8kYepWuDK1a-VcFlmX-4VdFJg_9ecLXJnkTNwZymRJb-3yMwt3N9OkF-O6NIs50XdVFtVS1buouze17Dsjnaq7xN_c00zptJ4ezFpZEVre7iKMcxIw61twqaNi6vafSUANAsNkbyRAdBsD5H6YWVxpdFqzy6mKiX36Vs_P0wklFL3w_Aa-TNvl93Kom9YC5q8_-UfIJmKy_XVr998Xrh0lrd/file [following]
--2020-03-22 11:53:02--  https://uc963dc41e79b51807c12675b81d.dl.dropboxusercontent.com/cd/0/inline2/A0bzlagT69B0pDhb4kWcZvE6OdIHeNCurVKEF_BeO5NjidQtoKDgiryEmiU3NKjOq0ZtfLCBPf8C6Yff4P0PwlTyXmLrEuOmJVOoK06ELoeDxQRC7Ag2_kTL4CcvLOfC8kYepWuDK1a-VcFlmX-4VdFJg_9ecLXJnkTNwZymRJb-3yMwt3N9OkF-O6NIs50XdVFtVS1buouze17Dsjnaq7xN_c00zptJ4ezFpZEVre7iKMcxIw61twqaNi6vafSUANAsNkbyRAdBsD5H6YWVxpdFqzy6mKiX36Vs_P0wklFL3w_Aa-TNvl93Kom9YC5q8_-UfIJmKy_XVr998Xrh0lrd/file
Reusing existing connection to uc963dc41e79b51807c12675b81d.dl.dropboxusercontent.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 874066230 (834M) [application/octet-stream]
Saving to: ‘./models/ColorizeVideo_gen.pth’

./models/ColorizeVi 100%[===================>] 833.57M  27.9MB/s    in 32s     

2020-03-22 11:53:34 (26.0 MB/s) - ‘./models/ColorizeVideo_gen.pth’ saved [874066230/874066230]


In [10]:
!wget https://media.githubusercontent.com/media/jantic/DeOldify/master/resource_images/watermark.png -O ./resource_images/watermark.png


--2020-03-22 11:53:35--  https://media.githubusercontent.com/media/jantic/DeOldify/master/resource_images/watermark.png
Resolving media.githubusercontent.com (media.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...
Connecting to media.githubusercontent.com (media.githubusercontent.com)|151.101.0.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9210 (9.0K) [image/png]
Saving to: ‘./resource_images/watermark.png’

./resource_images/w 100%[===================>]   8.99K  --.-KB/s    in 0s      

2020-03-22 11:53:35 (193 MB/s) - ‘./resource_images/watermark.png’ saved [9210/9210]


In [11]:
colorizer = get_video_colorizer()


/usr/local/lib/python3.6/dist-packages/fastai/data_block.py:442: UserWarning: Your training set is empty. If this is by design, pass `ignore_empty=True` to remove this warning.
  warn("Your training set is empty. If this is by design, pass `ignore_empty=True` to remove this warning.")
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py:445: UserWarning: Your validation set is empty. If this is by design, use `split_none()`
                 or pass `ignore_empty=True` when labelling to remove this warning.
  or pass `ignore_empty=True` when labelling to remove this warning.""")
Downloading: "https://download.pytorch.org/models/resnet101-5d3b4d8f.pth" to /root/.cache/torch/checkpoints/resnet101-5d3b4d8f.pth

◢ Instructions

source_url

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.

render_factor

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.

watermarked

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).

How to Download a Copy

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

Pro Tips

  1. If a video takes a long time to render and you're wondering how well the frames will actually be colorized, you can preview how well the frames will be rendered at each render_factor by using the code at the bottom. Just stop the video rendering by hitting the stop button on the cell, then run that bottom cell under "See how well render_factor values perform on a frame here". It's not perfect and you may still need to experiment a bit especially when it comes to figuring out how to reduce frame inconsistency. But it'll go a long way in narrowing down what actually works.
  2. If videos are taking way too much time for your liking, running the Jupyter notebook VideoColorizer.ipynb on your own machine (with DeOldify installed) will generally be much faster (as long as you have the hardware for it).

Troubleshooting

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

  1. In the menu to the left, click Files
  2. If you don't see the 'DeOldify' folder, click "Refresh"
  3. By default, rendered video will be in /DeOldify/video/result/

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.

◢ Colorize!!


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.')


[youtube] pwfwtHWtFkc: Downloading webpage
[youtube] pwfwtHWtFkc: Downloading MPD manifest
[dashsegments] Total fragments: 77
[download] Destination: video/source/video.f136.mp4
[download] 100% of 76.17MiB in 00:51
[dashsegments] Total fragments: 42
[download] Destination: video/source/video.mp4.f140
[download] 100% of 6.20MiB in 00:19
[ffmpeg] Merging formats into "video/source/video.mp4"
Deleting original file video/source/video.f136.mp4 (pass -k to keep)
Deleting original file video/source/video.mp4.f140 (pass -k to keep)
100.00% [12057/12057 20:51<00:00]
Video created here: video/result/video.mp4

See how well render_factor values perform on a frame here


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))

Save to drive


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"'}