File size: 5,703 Bytes
ca6cab8
 
 
 
 
4b640eb
 
ca6cab8
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
4b640eb
ca6cab8
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
4b640eb
ca6cab8
 
 
4b640eb
ca6cab8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
4b640eb
ca6cab8
 
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
4b640eb
ca6cab8
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
4b640eb
ca6cab8
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
 
 
 
4b640eb
ca6cab8
 
 
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
 
 
 
 
 
 
 
 
 
 
 
4b640eb
ca6cab8
 
 
4b640eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca6cab8
4b640eb
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "colab_type": "text",
        "id": "view-in-github"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/soumik12345/enhance-me/blob/mirnet/notebooks/enhance_me_train.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "1JryaVhtBHij",
        "outputId": "4fac7fb6-787c-4a1b-f6ef-12ec48024619"
      },
      "outputs": [],
      "source": [
        "!git clone https://github.com/soumik12345/enhance-me -b mirnet\n",
        "!pip install wandb streamlit"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "G_c4VtXWHR5l"
      },
      "outputs": [],
      "source": [
        "import sys\n",
        "sys.path.append(\"./enhance-me\")\n",
        "\n",
        "from PIL import Image\n",
        "from enhance_me import commons\n",
        "from enhance_me.mirnet import MIRNet"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ZpBHbYaMIqP_"
      },
      "outputs": [],
      "source": [
        "#@title MIRNet Train Configs\n",
        "\n",
        "experiment_name = 'lol_dataset_128' #@param {type:\"string\"}\n",
        "image_size = 128 #@param {type:\"integer\"}\n",
        "dataset_label = 'lol' #@param [\"lol\"]\n",
        "apply_random_horizontal_flip = True #@param {type:\"boolean\"}\n",
        "apply_random_vertical_flip = True #@param {type:\"boolean\"}\n",
        "apply_random_rotation = True #@param {type:\"boolean\"}\n",
        "wandb_api_key = '' #@param {type:\"string\"}\n",
        "val_split = 0.1 #@param {type:\"slider\", min:0.1, max:1.0, step:0.1}\n",
        "batch_size = 4 #@param {type:\"integer\"}\n",
        "num_recursive_residual_groups = 3 #@param {type:\"slider\", min:1, max:5, step:1}\n",
        "num_multi_scale_residual_blocks = 2 #@param {type:\"slider\", min:1, max:5, step:1}\n",
        "learning_rate = 1e-4 #@param {type:\"number\"}\n",
        "epsilon = 1e-3 #@param {type:\"number\"}\n",
        "epochs = 50 #@param {type:\"slider\", min:10, max:100, step:5}"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 124
        },
        "id": "IVRoedqBIMuH",
        "outputId": "388a806f-f41f-420c-9c03-01024decb2d3"
      },
      "outputs": [],
      "source": [
        "mirnet = MIRNet(\n",
        "    experiment_name=experiment_name,\n",
        "    image_size=image_size,\n",
        "    dataset_label=dataset_label,\n",
        "    val_split=val_split,\n",
        "    batch_size=batch_size,\n",
        "    apply_random_horizontal_flip=apply_random_horizontal_flip,\n",
        "    apply_random_vertical_flip=apply_random_vertical_flip,\n",
        "    apply_random_rotation=apply_random_rotation,\n",
        "    wandb_api_key=None if wandb_api_key == '' else wandb_api_key\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "tsfKrBCsL_Bb"
      },
      "outputs": [],
      "source": [
        "mirnet.build_model(\n",
        "    num_recursive_residual_groups=num_recursive_residual_groups,\n",
        "    num_multi_scale_residual_blocks=num_multi_scale_residual_blocks,\n",
        "    learning_rate=learning_rate,\n",
        "    epsilon=epsilon\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "y3L9wlpkNziL",
        "outputId": "65e7ba4d-1607-4c14-d5d7-e55c4641ad0a"
      },
      "outputs": [],
      "source": [
        "history = mirnet.train(epochs=epochs)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "background_save": true,
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "daFKbgBkiyzc",
        "outputId": "38c3fc7a-8cef-4332-8efe-35103c75f1a3"
      },
      "outputs": [],
      "source": [
        "for index, low_image_file in enumerate(mirnet.test_low_images):\n",
        "    original_image = Image.open(low_image_file)\n",
        "    enhanced_image = mirnet.infer(original_image)\n",
        "    ground_truth = Image.open(mirnet.test_enhanced_images[index])\n",
        "    commons.plot_results(\n",
        "        [original_image, ground_truth, ground_truth],\n",
        "        [\"Original Image\", \"Ground Truth\", \"Enhanced Image\"],\n",
        "        (18, 18)\n",
        "    )"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "dO-IbNQHkB3R"
      },
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "authorship_tag": "ABX9TyMwNbyaCs348ucM56hcLJop",
      "collapsed_sections": [],
      "include_colab_link": true,
      "machine_shape": "hm",
      "name": "enhance-me-train.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}