mirror of
https://github.com/jantic/DeOldify.git
synced 2026-08-29 02:10:55 +08:00
547fb7e56f
It will be better to do:
from deoldify import visualize
Than:
from fasterai import visualize
The PyPI package will be called DeOldify, in this case
it makes more sense to have an import name that matches
the package name.
Also, fasterai resembles fastai library, and DeOldify
is not a library to use with fastai, it's built on
top of it.
279 lines
6.7 KiB
Plaintext
279 lines
6.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"colab_type": "text",
|
|
"id": "view-in-github"
|
|
},
|
|
"source": [
|
|
"<a href=\"https://colab.research.google.com/github/jantic/DeOldify/blob/master/ImageColorizerColab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"colab_type": "text",
|
|
"id": "663IVxfrpIAb"
|
|
},
|
|
"source": [
|
|
"#◢ DeOldify - Colorize your own photos!\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",
|
|
"**<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": {},
|
|
"colab_type": "code",
|
|
"id": "00_GcC_trpdE"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import torch\n",
|
|
"\n",
|
|
"if not torch.cuda.is_available():\n",
|
|
" print('GPU not 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 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 -r requirements.txt"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {},
|
|
"colab_type": "code",
|
|
"id": "MsJa69CMwj3l"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import fastai\n",
|
|
"from deoldify.visualize import *\n",
|
|
"\n",
|
|
"torch.backends.cudnn.benchmark = True"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"!mkdir 'models'\n",
|
|
"!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": "BDFjbNxaadNJ"
|
|
},
|
|
"source": [
|
|
"#◢ Instructions"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### source_url\n",
|
|
"Type in a url to a direct link of an image. Usually that means they'll end in .png, .jpg, etc. NOTE: If you want to use your own image, upload it first to a site like Imgur. \n",
|
|
"\n",
|
|
"### render_factor\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 color portion of the image is rendered. Lower resolution will render faster, and colors also tend to look more vibrant. Older and lower quality images in particular will generally benefit by lowering the render factor. Higher render factors are often better for higher quality images, but the colors may get slightly washed out. \n",
|
|
"\n",
|
|
"#### How to Download a Copy\n",
|
|
"Simply right click on the displayed image and click \"Save image as...\"!\n",
|
|
"\n",
|
|
"## Pro Tips\n",
|
|
"\n",
|
|
"You can evaluate how well the image is rendered at each render_factor by using the code at the bottom (that cell under \"See how well render_factor values perform on a frame here\"). \n",
|
|
"\n",
|
|
"## Troubleshooting\n",
|
|
"If you get a 'CUDA out of memory' error, you probably have the render_factor too high."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"colab_type": "text",
|
|
"id": "sUQrbSYipiJn"
|
|
},
|
|
"source": [
|
|
"#◢ Colorize!!"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"source_url = '' #@param {type:\"string\"}\n",
|
|
"render_factor = 35 #@param {type: \"slider\", min: 7, max: 45}\n",
|
|
"\n",
|
|
"if source_url is not None and source_url !='':\n",
|
|
" image_path = colorizer.plot_transformed_image_from_url(url=source_url, render_factor=render_factor, compare=True)\n",
|
|
" show_image_in_notebook(image_path)\n",
|
|
"else:\n",
|
|
" print('Provide an image url and try again.')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## See how well render_factor values perform on the image here"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"for i in range(10,46,2):\n",
|
|
" colorizer.plot_transformed_image('test_images/image.png', render_factor=i, display_render_factor=True, figsize=(8,8))"
|
|
]
|
|
},
|
|
{
|
|
"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": "ImageColorizerColab.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
|
|
}
|