{ "cells": [ { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "view-in-github" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "663IVxfrpIAb" }, "source": [ "#◢ DeOldify - Colorize Your Own Photos!\n", "\n", "##Use this Colab notebook to colorize black & white photos in four simple steps.\n", "1. Specify photo URL- make sure it's a direct link to the photo (with extension of .jpg, .png, etc).\n", "2. Select 'Render Factor'. Generally, older and lower quality photos will render bettter with lower render factors (14-21 range) while higher quality photos will do better on higher render factors.\n", "3. Colorize your photo with DeOldify\n", "4. Save a copy to your device by right clicking on the rendered image and selecting save.\n", "\n", "---\n", "\n", "####**Credits:**\n", "\n", "Special thanks to:\n", "\n", "Matt Robinson and María Benavente for pioneering the DeOldify image colab notebook. \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" ] }, { "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", "torch.backends.cudnn.benchmark=True" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!mkdir 'models'\n", "!wget wget https://www.dropbox.com/s/zkehq1uwahhbc2o/ColorizeArtistic_gen.pth?dl=0 -O ./models/ColorizeArtistic_gen.pth" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "tzHVnegp21hC" }, "outputs": [], "source": [ "colorizer = get_image_colorizer(artistic=True)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "z5rSDjZbTntY" }, "source": [ "#◢ Image URL\n", "\n", "Any direct link to an image should do (will end with extension .jpg, .png, etc). NOTE: If you want to use your own image, 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": {}, "source": [ "#◢ Render Factor\n", "\n", "The default value of 35 has been carefully chosen and should work -ok- for most scenarios (but probably won't be the -best-). This determines resolution at which the photo is rendered. Lower resolution will render faster, and colors also tend to look more vibrant. Older and lower quality photos in particular will generally benefit by lowering the render factor. Higher render factors are often better for higher quality photos." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "render_factor = 35 #@param {type: \"slider\", min: 7, max: 46}" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "sUQrbSYipiJn" }, "source": [ "#◢ Run DeOldify" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "if source_url is not None and source_url !='':\n", " !wget $source_url -O \"family_TV.jpg\"\n", " colorizer.plot_transformed_image_from_url(path=\"test_images/image.jpg\", url=source_url, render_factor=render_factor)\n", "else:\n", " print('Provide an image 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 image will be in /DeOldify/result_images/" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "X7Ycv_Y9xAHp" }, "source": [ "---\n", "#⚙ Recommended image sources \n", "* [/r/TheWayWeWere](https://www.reddit.com/r/TheWayWeWere/)" ] } ], "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 }