{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"
"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "663IVxfrpIAb"
},
"source": [
"#◢ [ DeOldify-video\n",
"\n",
"##This Colab notebook colorizes video in four steps\n",
"1. Upload source media or specify media URL - YouTube, Twitter, MySpace, etc.\n",
"2. Extract single images from media\n",
"3. Process images with [DeOldify](https://github.com/jantic/DeOldify) \n",
"4. Rebuild the video from **colorized** images\n",
"\n",
"I'm on twitter [@tradica](https://twitter.com/tradica)\n",
"\n",
"\n",
"---\n",
"\n",
"\n",
"Thanks [@citnaj](https://twitter.com/citnaj) for creating DeOldify and thanks to Matt Robinson for his [notebook](https://colab.research.google.com/github/jantic/DeOldify/blob/master/DeOldify_colab.ipynb). It helped make DeOldify approachable.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ZjPqTBNoohK9"
},
"source": [
"\n",
"\n",
"---\n",
"\n",
"\n",
"#◢ [ Set Runtime type to Python 3/GPU\n",
"In the Runtime menu above be sure:\n",
"* Runtime Type = Python 3\n",
"* Hardware Accelerator = GPU **<-------------- IMPORTANT **\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "00_GcC_trpdE"
},
"outputs": [],
"source": [
"from os import path\n",
"import torch\n",
"print(torch.__version__)\n",
"print(torch.cuda.is_available())"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "gaEJBGDlptEo"
},
"source": [
"#◢ [ Git clone and install DeOldify"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "-T-svuHytJ-8"
},
"outputs": [],
"source": [
"!git clone -b FastAIv1 --single-branch https://github.com/jantic/DeOldify.git DeOldify\n",
"#!git clone https://github.com/jantic/DeOldify.git DeOldify"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cd DeOldify"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "BDFjbNxaadNJ"
},
"source": [
"#◢ [ Setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "Lsx7xCXNSVt6"
},
"outputs": [],
"source": [
"!pip install PyDrive\n",
"!pip install ffmpeg-python\n",
"!pip install youtube-dl"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "MsJa69CMwj3l"
},
"outputs": [],
"source": [
"import os\n",
"from pydrive.auth import GoogleAuth\n",
"from pydrive.drive import GoogleDrive\n",
"from google.colab import auth\n",
"from oauth2client.client import GoogleCredentials\n",
"from google.colab import drive\n",
"from IPython.display import Image\n",
"import fastai\n",
"from fastai import *\n",
"from fastai.vision import *\n",
"from fastai.callbacks.tensorboard import *\n",
"from fastai.vision.gan import *\n",
"from fasterai.dataset import *\n",
"from fasterai.visualize import *\n",
"from fasterai.loss import *\n",
"from fasterai.filters import *\n",
"from fasterai.generators import *\n",
"from pathlib import Path\n",
"from itertools import repeat\n",
"from google.colab import drive\n",
"from google.colab import files\n",
"torch.backends.cudnn.benchmark=True"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!mkdir 'models'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "uqJcwLG80fVe"
},
"outputs": [],
"source": [
"!wget https://www.dropbox.com/s/zqt6pzcmoztda0l/ColorizeVideos_gen2.pth?dl=0 -O ./models/colorize_gen2.pth"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#◢ [ 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"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"render_factor = 36 #@param {type: \"slider\", min: 5, max: 45}"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "z5rSDjZbTntY"
},
"source": [
"#◢ [ Specify URL\n",
"YouTube, Imgur, Twitter, MySpace, Reddit ... most work. NOTE: If this is ommitted, you can just upload the file later in the workflow"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"source_url = '' #@param {type:\"string\"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "z5rSDjZbTntY"
},
"source": [
"##◢ [ Not recommended to change the following (not really necessary)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"file_name = 'video.mp4'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"source_dir = './video/source/'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"source_path = source_dir + file_name"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dest_dir = './video/result/'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dest_path = dest_dir + file_name"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!mkdir file_dir"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "sUQrbSYipiJn"
},
"source": [
"#◢ DeOldify / Colorize"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "tzHVnegp21hC"
},
"outputs": [],
"source": [
"colorizer = get_video_colorizer2(render_factor=render_factor)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if source_url is not None and source_url !='':\n",
" colorizer.colorize_from_url(source_url, file_name)\n",
"else:\n",
" #UPLOAD File Here\n",
" source_media = files.upload()\n",
" os.system('ln -s /content/WORKFOLDER/' + list(source_media.keys())[0] + ' ' + source_path)\n",
" colorizer.colorize_from_file_name(file_name)"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "A5WMS_GgP4fm"
},
"source": [
"#◢ [ Download\n",
"* In the Menu on the left, click **Files**\n",
"* It's in /content/DeOldify/video/result/\n",
"* ( Or use this with its zero feedback :) )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "-PpnqBCUPw-Z"
},
"outputs": [],
"source": [
"#Find your video in Files > /content/WORKFOLDER/ANSWER/ (It's better than this)\n",
"files.download(dest_path)"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "X7Ycv_Y9xAHp"
},
"source": [
"---\n",
"#⚙ [ \n",
"* [/r/Nickelodeons/](https://www.reddit.com/r/Nickelodeons/)\n",
"* https://twitter.com/silentmoviegifs "
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "3CUeJf2XF-1X"
},
"source": [
"https://twitter.com/silentmoviegifs/status/1087282910288363522\n",
"If you click the date at the top of a tweet you can copy the URL from the browser"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"collapsed_sections": [],
"name": "DeOldify-video.ipynb",
"provenance": [],
"toc_visible": true,
"version": "0.3.2"
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}