{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"
"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "663IVxfrpIAb"
},
"source": [
"#◢ DeOldify - Not just for photos!\n",
"\n",
"##Use this Colab notebook to colorize black & white videos in three simple steps.\n",
"1. Specify media URL - YouTube, Twitter, Imgur, etc.\n",
"2. Run DeOldify to extract single images from your video or gif. Behind the scenes, the code does the following:\n",
" * Extracts single images from the specified media file.\n",
" * Processes the images with [DeOldify](https://github.com/jantic/DeOldify).\n",
" * Rebuilds the video from **colorized** images.\n",
"3. Download the video to your device to view! \n",
"\n",
"_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._\n",
"\n",
"---\n",
"\n",
"####**Credits:**\n",
"\n",
"Use of this tool is thanks to,\n",
"\n",
"[@citnaj](https://twitter.com/citnaj) for creating DeOldify.\n",
"\n",
"[@tradica](https://twitter.com/tradica) for initial video and CoLab work.\n",
"\n",
"Matt Robinson for his [notebook](https://colab.research.google.com/github/jantic/DeOldify/blob/master/DeOldify_colab.ipynb) which helped make DeOldify approachable.\n",
"\n",
"Dana Kelley for doing things, breaking stuff & having an opinion on everything."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ZjPqTBNoohK9"
},
"source": [
"\n",
"\n",
"---\n",
"\n",
"\n",
"#◢ Verify Correct Runtime Settings\n",
"\n",
"** IMPORTANT **\n",
"\n",
"In the \"Runtime\" menu for the notebook window, select \"Change runtime type.\" Ensure that the following are selected:\n",
"* Runtime Type = Python 3\n",
"* Hardware Accelerator = GPU \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\n",
"!pip install tensorboardX"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "MsJa69CMwj3l"
},
"outputs": [],
"source": [
"import fastai\n",
"from fasterai.visualize import *\n",
"from pathlib import Path\n",
"from google.colab import drive\n",
"from google.colab import files\n",
"torch.backends.cudnn.benchmark=True"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#◢ Stable vs Experimental Model\n",
"\n",
"For most use cases, stick with the \"Stable\" model. If you are feeling wild, try out the \"Experimental.\" Please note, depending on the source file, it may improve the vibrancy of colors, or it may make everyone look like they just took the Trump Train from LoompaLand.\n",
"\n",
"_The \"experimental\" model is just that, experimental and prone to unannounced updates. Feedback is sometimes welcome._"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stable = True #@param {type:\"boolean\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!mkdir 'models'\n",
"if stable:\n",
" !wget https://www.dropbox.com/s/ztgygpaz1z3jkjg/ColorizeImagesStable_gen.pth?dl=0 -O ./models/ColorizeImagesStable_gen.pth\n",
"else:\n",
" !wget https://www.dropbox.com/s/9ne9su2mc5t0m38/ColorizeImagesArtistic_gen.pth?dl=0 -O ./models/ColorizeImagesArtistic_gen.pth\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#◢ Render Factor\n",
"\n",
"Default has been carefully chosen and should work for most scenarios. Determines resolution at which video is rendered. Lower resolution tends to be less flashy and complete faster. Higher resolution can be more colorful (not always in a good way!). "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"render_factor = 21 #@param {type: \"slider\", min: 5, max: 45}"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "z5rSDjZbTntY"
},
"source": [
"#◢ Specify URL\n",
"\n",
"YouTube, Imgur, Twitter, Reddit ... files of type .gif, .gifv and .mp4 work. NOTE: If you want to use your own source material, upload it first to a site like Imgur. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"source_url = '' #@param {type:\"string\"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "z5rSDjZbTntY"
},
"source": [
"#◢ Additional Parameters\n",
"\n",
"It's not necessary to change the following, just run them as-is."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"file_name = 'video.mp4'\n",
"source_dir = './video/source/'\n",
"source_path = source_dir + file_name\n",
"dest_dir = './video/result/'\n",
"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": [
"#◢ Run DeOldify"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "tzHVnegp21hC"
},
"outputs": [],
"source": [
"colorizer = get_video_colorizer(render_factor=render_factor, artistic=!stable)"
]
},
{
"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",
" print('Provide a source url and try again.')"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "A5WMS_GgP4fm"
},
"source": [
"#◢ Download\n",
"\n",
"* In the menu to the left, click **Files**\n",
"* If you don't see the 'DeOldify' folder, click \"Refresh\"\n",
"* By default, rendered video will be in /DeOldify/video/result/"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "X7Ycv_Y9xAHp"
},
"source": [
"---\n",
"#⚙ Recommended video and gif sources \n",
"* [/r/Nickelodeons/](https://www.reddit.com/r/Nickelodeons/)\n",
"* https://twitter.com/silentmoviegifs "
]
}
],
"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
}