|
@@ -14,81 +14,71 @@
|
|
|
"cell_type": "markdown",
|
|
|
"metadata": {
|
|
|
"colab_type": "text",
|
|
|
- "id": "V-nHLm4jWpnV"
|
|
|
+ "id": "663IVxfrpIAb"
|
|
|
},
|
|
|
"source": [
|
|
|
- "# DeOldify on Colab #\n",
|
|
|
+ "#◢ DeOldify - Colorize Your Own Photos!\n",
|
|
|
"\n",
|
|
|
- "This notebook allows you to colorize your own images using Google Colab!\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",
|
|
|
- "Special thanks to the that made this possible!\n",
|
|
|
+ "---\n",
|
|
|
"\n",
|
|
|
- "Original Author: Matt Robinson, <matthew67robinson@gmail.com>\n",
|
|
|
+ "####**Credits:**\n",
|
|
|
"\n",
|
|
|
- "Additional Contributions: Maria Benavente"
|
|
|
+ "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": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "cell_type": "markdown",
|
|
|
"metadata": {
|
|
|
- "colab": {
|
|
|
- "base_uri": "https://localhost:8080/",
|
|
|
- "height": 119
|
|
|
- },
|
|
|
- "colab_type": "code",
|
|
|
- "id": "-dSDNbBNb-N8",
|
|
|
- "outputId": "4ef40df9-46dd-44a4-b54a-e720a3eee232"
|
|
|
+ "colab_type": "text",
|
|
|
+ "id": "ZjPqTBNoohK9"
|
|
|
},
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "!git clone -b FastAIv1 --single-branch https://github.com/jantic/DeOldify.git DeOldify"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [],
|
|
|
"source": [
|
|
|
- "from os import path\n",
|
|
|
- "import torch\n",
|
|
|
- "print(torch.__version__)\n",
|
|
|
- "print(torch.cuda.is_available())"
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ "---\n",
|
|
|
+ "\n",
|
|
|
+ "\n",
|
|
|
+ "#◢ Verify Correct Runtime Settings\n",
|
|
|
+ "\n",
|
|
|
+ "**<font color='#FF000'> IMPORTANT </font>**\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": {
|
|
|
- "base_uri": "https://localhost:8080/",
|
|
|
- "height": 34
|
|
|
- },
|
|
|
+ "colab": {},
|
|
|
"colab_type": "code",
|
|
|
- "id": "k19F34Tsd7CX",
|
|
|
- "outputId": "81828b10-6678-4eec-ec53-5b0b9d645782"
|
|
|
+ "id": "00_GcC_trpdE"
|
|
|
},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "cd DeOldify"
|
|
|
+ "from os import path\n",
|
|
|
+ "import torch"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "cell_type": "markdown",
|
|
|
"metadata": {
|
|
|
- "colab": {
|
|
|
- "base_uri": "https://localhost:8080/",
|
|
|
- "height": 187
|
|
|
- },
|
|
|
- "colab_type": "code",
|
|
|
- "id": "lhejMeOxghBM",
|
|
|
- "outputId": "d063f1dc-1286-4355-f8aa-838a7dfc29ee"
|
|
|
+ "colab_type": "text",
|
|
|
+ "id": "gaEJBGDlptEo"
|
|
|
},
|
|
|
- "outputs": [],
|
|
|
"source": [
|
|
|
- "!pip install PyDrive"
|
|
|
+ "#◢ Git clone and install DeOldify"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -97,60 +87,31 @@
|
|
|
"metadata": {
|
|
|
"colab": {},
|
|
|
"colab_type": "code",
|
|
|
- "id": "yODBFi8MgoLZ"
|
|
|
+ "id": "-T-svuHytJ-8"
|
|
|
},
|
|
|
"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 fasterai.visualize import *\n",
|
|
|
- "from pathlib import Path\n",
|
|
|
- "from itertools import repeat\n",
|
|
|
- "from google.colab import drive\n",
|
|
|
- "torch.backends.cudnn.benchmark=True"
|
|
|
+ "!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": {
|
|
|
- "colab": {},
|
|
|
- "colab_type": "code",
|
|
|
- "id": "Ow9Qhf4jgrgd"
|
|
|
- },
|
|
|
+ "metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "auth.authenticate_user()\n",
|
|
|
- "gauth = GoogleAuth()\n",
|
|
|
- "gauth.credentials = GoogleCredentials.get_application_default()\n",
|
|
|
- "drive = GoogleDrive(gauth)"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "markdown",
|
|
|
- "metadata": {
|
|
|
- "colab_type": "text",
|
|
|
- "id": "aVyIYMqrg-SM"
|
|
|
- },
|
|
|
- "source": [
|
|
|
- "Note that the above requires a verification step. It isn't too bad."
|
|
|
+ "cd DeOldify"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "markdown",
|
|
|
"metadata": {
|
|
|
"colab_type": "text",
|
|
|
- "id": "Doru7d3rVYr7"
|
|
|
+ "id": "BDFjbNxaadNJ"
|
|
|
},
|
|
|
"source": [
|
|
|
- "With access to your Google Drive, the \"deOldifyImages\" directory will be created. Drop there your personal images, and after the full execution of the notebook find the results at its subdirectory \"results\""
|
|
|
+ "#◢ Setup"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -159,33 +120,30 @@
|
|
|
"metadata": {
|
|
|
"colab": {},
|
|
|
"colab_type": "code",
|
|
|
- "id": "sU2yQAfqhNJv"
|
|
|
+ "id": "Lsx7xCXNSVt6"
|
|
|
},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "results_dir=Path('/content/drive/My Drive/deOldifyImages/results')\n",
|
|
|
- "\n",
|
|
|
- "#Adjust this if image doesn't look quite right (max 64 on 11GB GPU). The default here works for most photos. \n",
|
|
|
- "#It literally just is a number multiplied by 16 to get the square render resolution. \n",
|
|
|
- "#Note that this doesn't affect the resolution of the final output- the output is the same resolution as the input.\n",
|
|
|
- "#Example: render_factor=21 => color is rendered at 16x21 = 336x336 px. \n",
|
|
|
- "render_factor=36"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "markdown",
|
|
|
- "metadata": {},
|
|
|
- "source": [
|
|
|
- "#◢ Artistic vs Stable Model"
|
|
|
+ "!pip install PyDrive\n",
|
|
|
+ "!pip install ffmpeg-python\n",
|
|
|
+ "!pip install youtube-dl\n",
|
|
|
+ "!pip install tensorboardX"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
"execution_count": null,
|
|
|
- "metadata": {},
|
|
|
+ "metadata": {
|
|
|
+ "colab": {},
|
|
|
+ "colab_type": "code",
|
|
|
+ "id": "MsJa69CMwj3l"
|
|
|
+ },
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "artistic = True #@param {type:\"boolean\"}"
|
|
|
+ "import fastai\n",
|
|
|
+ "from fasterai.visualize import *\n",
|
|
|
+ "from pathlib import Path\n",
|
|
|
+ "torch.backends.cudnn.benchmark=True"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -195,38 +153,32 @@
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
"!mkdir 'models'\n",
|
|
|
- "if artistic:\n",
|
|
|
- " !wget https://www.dropbox.com/s/zkehq1uwahhbc2o/ColorizeArtistic_gen.pth?dl=0 -O ./models/ColorizeArtistic_gen.pth\n",
|
|
|
- "else:\n",
|
|
|
- " !wget https://www.dropbox.com/s/mwjep3vyqk5mkjc/ColorizeStable_gen.pth?dl=0 -O ./models/ColorizeStable_gen.pth"
|
|
|
+ "!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": {
|
|
|
- "base_uri": "https://localhost:8080/",
|
|
|
- "height": 68
|
|
|
- },
|
|
|
+ "colab": {},
|
|
|
"colab_type": "code",
|
|
|
- "id": "NlOT9IlBHkk7",
|
|
|
- "outputId": "1bb5cc4d-15a2-4174-a37c-9e11f3a2dce3"
|
|
|
+ "id": "tzHVnegp21hC"
|
|
|
},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "from google.colab import drive\n",
|
|
|
- "drive.mount('/content/drive')"
|
|
|
+ "colorizer = get_image_colorizer(artistic=True)"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [],
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "metadata": {
|
|
|
+ "colab_type": "text",
|
|
|
+ "id": "z5rSDjZbTntY"
|
|
|
+ },
|
|
|
"source": [
|
|
|
- "!mkdir \"/content/drive/My Drive/deOldifyImages\"\n",
|
|
|
- "!mkdir \"/content/drive/My Drive/deOldifyImages/results\""
|
|
|
+ "#◢ 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. "
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -235,81 +187,74 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "vis = get_image_colorizer(render_factor=render_factor, artistic=artistic)"
|
|
|
+ "source_url = '' #@param {type:\"string\"}"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "markdown",
|
|
|
- "metadata": {
|
|
|
- "colab_type": "text",
|
|
|
- "id": "ZpCf0qbxicVK"
|
|
|
- },
|
|
|
+ "metadata": {},
|
|
|
"source": [
|
|
|
- "Here's an example of colorizing an image downloaded from the internet:"
|
|
|
+ "#◢ 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": {
|
|
|
- "base_uri": "https://localhost:8080/",
|
|
|
- "height": 204
|
|
|
- },
|
|
|
- "colab_type": "code",
|
|
|
- "id": "8-hQC-AfiCKq",
|
|
|
- "outputId": "f52e94a1-48bd-4b27-bc21-2306ee85ef9d"
|
|
|
+ "colab_type": "text",
|
|
|
+ "id": "sUQrbSYipiJn"
|
|
|
},
|
|
|
- "outputs": [],
|
|
|
"source": [
|
|
|
- "!wget \"https://media.githubusercontent.com/media/jantic/DeOldify/master/test_images/TV1930s.jpg\" -O \"family_TV.jpg\""
|
|
|
+ "#◢ Run DeOldify"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
"execution_count": null,
|
|
|
- "metadata": {
|
|
|
- "colab": {
|
|
|
- "base_uri": "https://localhost:8080/",
|
|
|
- "height": 434
|
|
|
- },
|
|
|
- "colab_type": "code",
|
|
|
- "id": "O6kfUN0GiJsq",
|
|
|
- "outputId": "3e37f84d-6d27-4e4e-b7b6-9feae8be40ae"
|
|
|
- },
|
|
|
+ "metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "vis.plot_transformed_image('family_TV.jpg')"
|
|
|
+ "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": "dBY1N_bYaIxq"
|
|
|
+ "id": "A5WMS_GgP4fm"
|
|
|
},
|
|
|
"source": [
|
|
|
- "If you want to colorize pictures from your Google drive, drop them in a directory named deOldifyImages (in the root of your drive) and the next cell will colorize all of them and save the resulting images in deOldifyImages/results."
|
|
|
+ "#◢ 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": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "cell_type": "markdown",
|
|
|
"metadata": {
|
|
|
- "colab": {
|
|
|
- "base_uri": "https://localhost:8080/",
|
|
|
- "height": 559
|
|
|
- },
|
|
|
- "colab_type": "code",
|
|
|
- "id": "vL7775DWaFJ4",
|
|
|
- "outputId": "cdb35172-d43a-4d45-f23c-d86c993aaf9b"
|
|
|
+ "colab_type": "text",
|
|
|
+ "id": "X7Ycv_Y9xAHp"
|
|
|
},
|
|
|
- "outputs": [],
|
|
|
"source": [
|
|
|
- "for img in os.listdir(\"/content/drive/My Drive/deOldifyImages/\"):\n",
|
|
|
- " img_path = str(\"/content/drive/My Drive/deOldifyImages/\") + img\n",
|
|
|
- " if os.path.isfile(img_path):\n",
|
|
|
- " vis.plot_transformed_image(img_path)"
|
|
|
+ "---\n",
|
|
|
+ "#⚙ Recommended image sources \n",
|
|
|
+ "* [/r/TheWayWeWere](https://www.reddit.com/r/TheWayWeWere/)"
|
|
|
]
|
|
|
}
|
|
|
],
|
|
@@ -317,8 +262,9 @@
|
|
|
"accelerator": "GPU",
|
|
|
"colab": {
|
|
|
"collapsed_sections": [],
|
|
|
- "name": "DeOldify_colab.ipynb",
|
|
|
+ "name": "DeOldify-video.ipynb",
|
|
|
"provenance": [],
|
|
|
+ "toc_visible": true,
|
|
|
"version": "0.3.2"
|
|
|
},
|
|
|
"kernelspec": {
|