Image Super-Resolution in Python

Ardiant Utomo
gdplabs
Published in
3 min readApr 4, 2022

using Efficient Sub Pixel Convolutional Neural Network

A while ago, I was looking at old photos ( low resolution) on my computer. Suddenly, this thing came to my mind “Can AI fix that low-resolution image into a high-resolution image”. I googled it and found many nice articles about it. I found there is super-resolution imaging that can be used to solve my problem. I studied several articles and I create my own code based on the articles that I had read.

Shi, 2016, wrote a nice paper about Super-Resolution imaging. In this article, we will use the network configuration that comes from that paper. And also, we will use BSDS500 datasets.

Okay, let’s begin.

The first step that we’ll take is importing the module that we will use in this experiment.

The dataset that will be used is Berkeley Segmentation Data Set 500 (BSDS500).

The code above will download the dataset using the get_file function from Keras which automatically extracts the file (extract=True).
the dataset_dir variable will contain the dataset path.

After we have our dataset extracted, we create a variable to load our dataset

Neural networks process inputs with low weight values and inputs with large integer values can interrupt or slow down the learning process. Therefore, it is recommended to normalize the pixel values so that each pixel value is between 0 and 1.

Now, we will prepare our data, so it will be ready for training. We will grayscale our image and downscale the image. So the small images will be the input, and the original image (not downscaled) is the target image.

To show the differences between the image and the downscaled image, add the following snippet into your code

Image vs Downscaled Image

The next step is creating the neural network model. We will use the neural network configuration proposed by Shi, 2016.

After the training is done, we can test our model using the code below:

Example of small image vs upscaled image

Now we have tested our model, the next step we can do is to calculate the peak signal-to-noise ratio (PSNR) to evaluate our super-resolution model performance.

I hope you enjoy this article.

References:

--

--