mirror of
https://github.com/mmaithani/data-science.git
synced 2022-04-24 02:56:41 +03:00
324 lines
304 KiB
Plaintext
324 lines
304 KiB
Plaintext
{
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0,
|
|
"metadata": {
|
|
"accelerator": "GPU",
|
|
"colab": {
|
|
"name": "DeOldify ImageColorizerColab.ipynb",
|
|
"provenance": [],
|
|
"collapsed_sections": [],
|
|
"toc_visible": true,
|
|
"include_colab_link": true
|
|
},
|
|
"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.6"
|
|
}
|
|
},
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "view-in-github",
|
|
"colab_type": "text"
|
|
},
|
|
"source": [
|
|
"<a href=\"https://colab.research.google.com/github/mmaithani/data-science/blob/main/DeOldify_ImageColorizerColab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "ZjPqTBNoohK9"
|
|
},
|
|
"source": [
|
|
"\n",
|
|
"\n",
|
|
"---\n",
|
|
"\n",
|
|
"\n",
|
|
"# Correct Runtime Settings\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": "markdown",
|
|
"metadata": {
|
|
"id": "gaEJBGDlptEo"
|
|
},
|
|
"source": [
|
|
"# Git clone and install DeOldify"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "oIGkkf_rxvS6"
|
|
},
|
|
"source": [
|
|
"## i have forked the official repo: [https://github.com/jantic/DeOldify](https://github.com/jantic/DeOldify) and added some test images for ease"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "-T-svuHytJ-8",
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"outputId": "6702b761-86f5-4f98-8266-f3273956ff38"
|
|
},
|
|
"source": [
|
|
"!git clone https://github.com/mmaithani/DeOldify.git DeOldify "
|
|
],
|
|
"execution_count": 1,
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Cloning into 'DeOldify'...\n",
|
|
"remote: Enumerating objects: 14, done.\u001b[K\n",
|
|
"remote: Counting objects: 100% (14/14), done.\u001b[K\n",
|
|
"remote: Compressing objects: 100% (14/14), done.\u001b[K\n",
|
|
"remote: Total 2201 (delta 3), reused 0 (delta 0), pack-reused 2187\u001b[K\n",
|
|
"Receiving objects: 100% (2201/2201), 72.44 MiB | 34.97 MiB/s, done.\n",
|
|
"Resolving deltas: 100% (999/999), done.\n"
|
|
],
|
|
"name": "stdout"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "8VzGZP_lTNrH",
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"outputId": "d56326fd-cee9-43a6-edd2-edca4e437c39"
|
|
},
|
|
"source": [
|
|
"cd DeOldify"
|
|
],
|
|
"execution_count": 1,
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/content/DeOldify\n"
|
|
],
|
|
"name": "stdout"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "BDFjbNxaadNK"
|
|
},
|
|
"source": [
|
|
"# Setup"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "00_GcC_trpdE"
|
|
},
|
|
"source": [
|
|
"#NOTE: This must be the first call in order to work properly!\n",
|
|
"from deoldify import device\n",
|
|
"from deoldify.device_id import DeviceId\n",
|
|
"#choices: CPU, GPU0...GPU7\n",
|
|
"device.set(device=DeviceId.GPU0)\n",
|
|
"\n",
|
|
"import torch\n",
|
|
"\n",
|
|
"if not torch.cuda.is_available():\n",
|
|
" print('GPU not available.')"
|
|
],
|
|
"execution_count": 3,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "Lsx7xCXNSVt6"
|
|
},
|
|
"source": [
|
|
"!pip install -r colab_requirements.txt"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "MsJa69CMwj3l"
|
|
},
|
|
"source": [
|
|
"import fastai\n",
|
|
"from deoldify.visualize import *\n",
|
|
"import warnings\n",
|
|
"warnings.filterwarnings(\"ignore\", category=UserWarning, message=\".*?Your .*? set is empty.*?\")"
|
|
],
|
|
"execution_count": 4,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "YC7mFQQaTNrJ"
|
|
},
|
|
"source": [
|
|
"!mkdir 'models'\n",
|
|
"!wget https://data.deepai.org/deoldify/ColorizeArtistic_gen.pth -O ./models/ColorizeArtistic_gen.pth"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "i7OGmNRBTNrK"
|
|
},
|
|
"source": [
|
|
"!wget https://media.githubusercontent.com/media/jantic/DeOldify/master/resource_images/watermark.png -O ./resource_images/watermark.png"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "tzHVnegp21hC"
|
|
},
|
|
"source": [
|
|
"colorizer = get_image_colorizer(artistic=True)"
|
|
],
|
|
"execution_count": 6,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "sUQrbSYipiJn"
|
|
},
|
|
"source": [
|
|
"# Let's Colorize!!"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "V2r48mlqTNrP"
|
|
},
|
|
"source": [
|
|
"## See how well render_factor values perform on the image here"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "b67_tRLe0WSm"
|
|
},
|
|
"source": [
|
|
""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "7B0fudZDsPYV"
|
|
},
|
|
"source": [
|
|
"for i in range(10,40,2):\r\n",
|
|
" colorizer.plot_transformed_image('/content/DeOldify/test_images/vic-P8Fxe0J8Flo-unsplash.jpg', render_factor=i, display_render_factor=True, figsize=(8,8))"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "a9kBBRsDzxp-"
|
|
},
|
|
"source": [
|
|
"## result(colored) image is stored in /DeOldify/test_images/\r\n",
|
|
""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "ZJvKaR3YtQrx"
|
|
},
|
|
"source": [
|
|
"for i in range(10,40,2):\r\n",
|
|
" colorizer.plot_transformed_image('/content/DeOldify/test_images/mvf78f3j7z961.png', render_factor=i, display_render_factor=True, figsize=(8,8))"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "C8LcvSbATNrP"
|
|
},
|
|
"source": [
|
|
"for i in range(10,40,2):\n",
|
|
" colorizer.plot_transformed_image('test_images/image.jpg', render_factor=i, display_render_factor=True, figsize=(8,8))"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "3gL7YGmOuO1-"
|
|
},
|
|
"source": [
|
|
"for i in range(10,40,2):\r\n",
|
|
" colorizer.plot_transformed_image('/content/DeOldify/test_images/68747470733a2f2f692e696d6775722e636f6d2f427430766e6b652e6a7067 (2).jpg', render_factor=i, display_render_factor=True, figsize=(8,8))"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "2XW-74tY0uaq"
|
|
},
|
|
"source": [
|
|
""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "QCEymV_-ufcI"
|
|
},
|
|
"source": [
|
|
""
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
}
|
|
]
|
|
} |