Computer_Vision/Chapter13/Image_super_resolution_using_SRGAN.ipynb

540 lines
399 KiB
Plaintext
Raw Permalink Normal View History

2024-02-13 03:34:51 +01:00
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Image_super_resolution_using_SRGAN.ipynb",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/PacktPublishing/Hands-On-Computer-Vision-with-PyTorch/blob/master/Chapter13/Image_super_resolution_using_SRGAN.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "vXvKdQgrg8WI",
"outputId": "17592253-82e6-48cd-816e-49d6d05f0f64",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 90
}
},
"source": [
"import os\n",
"if not os.path.exists('srgan.pth.tar'):\n",
" !pip install -q torch_snippets\n",
" !wget -q https://raw.githubusercontent.com/sizhky/a-PyTorch-Tutorial-to-Super-Resolution/master/models.py -O models.py\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",
"\n",
" auth.authenticate_user()\n",
" gauth = GoogleAuth()\n",
" gauth.credentials = GoogleCredentials.get_application_default()\n",
" drive = GoogleDrive(gauth)\n",
"\n",
" downloaded = drive.CreateFile({'id': '1_PJ1Uimbr0xrPjE8U3Q_bG7XycGgsbVo'})\n",
" downloaded.GetContentFile('srgan.pth.tar')\n",
" from torch_snippets import *\n",
" device = 'cuda' if torch.cuda.is_available() else 'cpu'"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"\u001b[K |████████████████████████████████| 61kB 9.3MB/s \n",
"\u001b[K |████████████████████████████████| 36.7MB 81kB/s \n",
"\u001b[K |████████████████████████████████| 102kB 12.3MB/s \n",
"\u001b[?25h Building wheel for contextvars (setup.py) ... \u001b[?25l\u001b[?25hdone\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "3Wzd705WhDx7",
"outputId": "21c43f37-72d3-4859-80e2-c8cb0ea11a8a",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
}
},
"source": [
"model = torch.load('srgan.pth.tar', map_location='cpu')['generator'].to(device)\n",
"model.eval()"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"/usr/local/lib/python3.6/dist-packages/torch/serialization.py:649: SourceChangeWarning: source code of class 'torch.nn.modules.container.Sequential' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n",
" warnings.warn(msg, SourceChangeWarning)\n",
"/usr/local/lib/python3.6/dist-packages/torch/serialization.py:649: SourceChangeWarning: source code of class 'torch.nn.modules.conv.Conv2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n",
" warnings.warn(msg, SourceChangeWarning)\n",
"/usr/local/lib/python3.6/dist-packages/torch/serialization.py:649: SourceChangeWarning: source code of class 'torch.nn.modules.activation.PReLU' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n",
" warnings.warn(msg, SourceChangeWarning)\n",
"/usr/local/lib/python3.6/dist-packages/torch/serialization.py:649: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n",
" warnings.warn(msg, SourceChangeWarning)\n",
"/usr/local/lib/python3.6/dist-packages/torch/serialization.py:649: SourceChangeWarning: source code of class 'torch.nn.modules.pixelshuffle.PixelShuffle' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n",
" warnings.warn(msg, SourceChangeWarning)\n",
"/usr/local/lib/python3.6/dist-packages/torch/serialization.py:649: SourceChangeWarning: source code of class 'torch.nn.modules.activation.Tanh' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n",
" warnings.warn(msg, SourceChangeWarning)\n",
"/usr/local/lib/python3.6/dist-packages/torch/serialization.py:649: SourceChangeWarning: source code of class 'torch.nn.modules.activation.LeakyReLU' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n",
" warnings.warn(msg, SourceChangeWarning)\n",
"/usr/local/lib/python3.6/dist-packages/torch/serialization.py:649: SourceChangeWarning: source code of class 'torch.nn.modules.pooling.AdaptiveAvgPool2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n",
" warnings.warn(msg, SourceChangeWarning)\n",
"/usr/local/lib/python3.6/dist-packages/torch/serialization.py:649: SourceChangeWarning: source code of class 'torch.nn.modules.linear.Linear' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.\n",
" warnings.warn(msg, SourceChangeWarning)\n"
],
"name": "stderr"
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Generator(\n",
" (net): SRResNet(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(3, 64, kernel_size=(9, 9), stride=(1, 1), padding=(4, 4))\n",
" (1): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (residual_blocks): Sequential(\n",
" (0): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (1): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (2): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (3): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (4): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (5): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (6): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (7): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (8): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (9): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (10): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (11): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (12): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (13): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (14): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" (15): ResidualBlock(\n",
" (conv_block1): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (2): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" )\n",
" )\n",
" (conv_block2): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" )\n",
" )\n",
" (subpixel_convolutional_blocks): Sequential(\n",
" (0): SubPixelConvolutionalBlock(\n",
" (conv): Conv2d(64, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (pixel_shuffle): PixelShuffle(upscale_factor=2)\n",
" (prelu): PReLU(num_parameters=1)\n",
" )\n",
" (1): SubPixelConvolutionalBlock(\n",
" (conv): Conv2d(64, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n",
" (pixel_shuffle): PixelShuffle(upscale_factor=2)\n",
" (prelu): PReLU(num_parameters=1)\n",
" )\n",
" )\n",
" (conv_block3): ConvolutionalBlock(\n",
" (conv_block): Sequential(\n",
" (0): Conv2d(64, 3, kernel_size=(9, 9), stride=(1, 1), padding=(4, 4))\n",
" (1): Tanh()\n",
" )\n",
" )\n",
" )\n",
")"
]
},
"metadata": {
"tags": []
},
"execution_count": 2
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "At4qwZ21hG0P",
"outputId": "2094f895-4be8-4906-b809-48e851c3e692",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 401
}
},
"source": [
"!wget https://www.dropbox.com/s/nmzwu68nrl9j0lf/Hema6.JPG"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"--2020-10-18 07:03:41-- https://www.dropbox.com/s/nmzwu68nrl9j0lf/Hema6.JPG\n",
"Resolving www.dropbox.com (www.dropbox.com)... 162.125.81.1, 2620:100:6031:1::a27d:5101\n",
"Connecting to www.dropbox.com (www.dropbox.com)|162.125.81.1|:443... connected.\n",
"HTTP request sent, awaiting response... 301 Moved Permanently\n",
"Location: /s/raw/nmzwu68nrl9j0lf/Hema6.JPG [following]\n",
"--2020-10-18 07:03:42-- https://www.dropbox.com/s/raw/nmzwu68nrl9j0lf/Hema6.JPG\n",
"Reusing existing connection to www.dropbox.com:443.\n",
"HTTP request sent, awaiting response... 302 Found\n",
"Location: https://ucf5e7114771406b2f7aa5fb2772.dl.dropboxusercontent.com/cd/0/inline/BBejwhTNggmFOJ7aYiOqEpaCw3sj3rdL7-AxT_M727gOkQwnRbLkbUrGjnr-XZAgNflb_omszLDAre8ehKa8Vo-CzBodwQBGrIFrK2NMqE-eK9izcl8d4ZSWAPwuMVJaptU/file# [following]\n",
"--2020-10-18 07:03:42-- https://ucf5e7114771406b2f7aa5fb2772.dl.dropboxusercontent.com/cd/0/inline/BBejwhTNggmFOJ7aYiOqEpaCw3sj3rdL7-AxT_M727gOkQwnRbLkbUrGjnr-XZAgNflb_omszLDAre8ehKa8Vo-CzBodwQBGrIFrK2NMqE-eK9izcl8d4ZSWAPwuMVJaptU/file\n",
"Resolving ucf5e7114771406b2f7aa5fb2772.dl.dropboxusercontent.com (ucf5e7114771406b2f7aa5fb2772.dl.dropboxusercontent.com)... 162.125.81.15, 2620:100:6031:15::a27d:510f\n",
"Connecting to ucf5e7114771406b2f7aa5fb2772.dl.dropboxusercontent.com (ucf5e7114771406b2f7aa5fb2772.dl.dropboxusercontent.com)|162.125.81.15|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 21002 (21K) [image/jpeg]\n",
"Saving to: Hema6.JPG\n",
"\n",
"Hema6.JPG 100%[===================>] 20.51K --.-KB/s in 0.001s \n",
"\n",
"2020-10-18 07:03:43 (20.8 MB/s) - Hema6.JPG saved [21002/21002]\n",
"\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "yVNjAI3rhR4E"
},
"source": [
"preprocess = T.Compose([\n",
" T.ToTensor(),\n",
" T.Normalize([0.485, 0.456, 0.406],\n",
" [0.229, 0.224, 0.225]),\n",
" T.Lambda(lambda x: x.to(device))\n",
"])\n",
"\n",
"postprocess = T.Compose([\n",
" T.Lambda(lambda x: (x.cpu().detach()+1)/2),\n",
" T.ToPILImage()\n",
"])"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "mA5-CPxhhTYU"
},
"source": [
"image = readPIL('Hema6.JPG')\n",
"image.size\n",
"# (260,181)\n",
"image = image.resize((130,90))\n",
"im = preprocess(image)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "tlw-luG6hXY_"
},
"source": [
"sr = model(im[None])[0]\n",
"sr = postprocess(sr)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "wFRuf-XAhYFp",
"outputId": "1a8e82fa-ec1d-49da-c251-93f304d8c306",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 303
}
},
"source": [
"subplots([image, sr], nc=2, figsize=(10,10), titles=['Original image','High resolution image'])"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"2020-10-18 07:03:58.160 | INFO | torch_snippets.loader:subplots:359 - plotting 2 images in a grid of 1x2 @ (10, 10)\n"
],
"name": "stderr"
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAsgAAAEMCAYAAADZOkBJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9a6xtS1bf9xujquZcj332Oefec7v7dgdoMC8bKe4vgcSxFCQcxcjBoMR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ni+xAUEW3vTo4/IJhVSinHe8xpOn7MJ56j6n6Y1Qrmz/b0uc/K9FFVVE/XEYRqlVKyjyebgPnv+flD+xEgIHhbQoioKKBI8w3N7PhT69wO7w4RmgspbQZUkPkmrY2tbdWMUuvxWsfy+KKAIKZIjUi7vtBeXfDf8xyB9jytPYZg5v0KAUQwvwoVo6o/k4ocrxPP5pyKz9xSsvfZ2XMiYPO4aSeICFFD6+9ICAkQiqk/jwm1htYF/j4EEKuIVYIIKag/y1n3mfo9qtXT/Y+WZR7C52MQRH3sqwohhDa22rjyhz/r59OYMQzO+oDjteT03kSIKaEan5g6V1fXXF1dkfPE9e6acRwIQUid98mUB3Ie/NrBTu8Mnw+PHj3k8dUVpWQOw55SfHwiAyL1iWd9//sfvuVa4L/jff+2WYWpZFQCVX2MlJJBhKlMboMFqmUKhWqFnHdUKgHBZGr9YGSbmq1RKEqpI4PdUOuESMVqJtSMVEMNghmKUA1CCHR9h4XInsIwQa1Q6oRQUCqKsZHI3e0l77h9j
"text/plain": [
"<Figure size 720x720 with 2 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "QHSV2lNyhZkf"
},
"source": [
""
],
"execution_count": null,
"outputs": []
}
]
}