Atificial Neural Network High Resolution Images

Vann Ponlork
Sep 16, 2019 · 4 min read

DCGAN generate hight resolution images

In such topic , I want to show about neural network that can improve quality of image from low resolution to higher resolution. Actually, when we enlarge the image the image will lost its quality, but neural network can make same or better quality of image. The below is example of predict image.

  1. LR: Low resolution image
  2. SR: Super resolution image
  3. HR:Hight resolution image (origin image)

In this topic I will use DCGAN to train images to make SR images.

In the process of training the input will downscale 4 times after let Generator generate image upscale 4 time.

Note: There are two neural network Generator and Discriminator


In Neural network, to train neural network we need to prepare dataset first whether what is our dataset ,how many images that we want to train. In this case, the arrange images 35 thousand for training ANN. For my applications , I manage 1000 images 80% for training 20% for testing, So it is depend on yourself how many images you want to train and depend on the resources you have(GPU or CPU). The more images you train the more quality you get, it is not depend on how many batch_size you train. In my experience, if you have less images to train your predict will more noise than you have much image to train. So in this case, as the above mentioned you also need to think about your GPU or CPU my recommendation you should use GPU.

  1. COCO dataset 2017 18GB multi images dimension

2. I trained 800 images with test data 200 images with 128x128

3. The training process will downscale 4 time

Limit memory in training process

In training process, there are frequently meet the problem out of memory , so we should limit the memory to what we want, for me I limit memory to 80% of my GPU.


In training process, to monitor loss value , predict quality you should use tensorboard.

$ tensorboard --logdir=./logs/

For the method to use tensorboard I will mention below

Save Keras model for tensorflow serving

To predict image you can predict in two ways:

  1. predict by local
  2. predict by web service.

For web service I recommend using tensorflow serving,actually, you can use other way.

Deploy model to tensorflow serving


  1. Docker

So, in this case you need to have model to support tensorflow serving others from keras model.

The codes above loads Keras saved model generally generator model and save it to be tensorflow serving model.

One more thing I recommend using docker in to deploy model to tensorflow serving.

My model structure is models=>keras_sr=>1=>model files

For result of prediction and how to predict I will show below article.

Predict by request to tensorflow serving

There are many ways to predict by tensorflow serving, in here, I will use python request to send data to server and predict.

In the code, I will predict the original size from tensorflow serving server.

The process is that below:

Load image from path => read and convert it to array => Normalize it=> Send data to server=> server predict and send data back=>denormalize data => write image

1.Predict the original image size

2.Predict by Resize

Remember that when you save model for tensorflow serving as JSON,so when predict need to use JSON format


You will receive respond 504 from server that mean request timeout,if your image is big or your server will be stopped.

The reasons are :

  1. Model need to upscale image to 4 times, if your image is big it spend much time
  2. Your sending data is big so if your docker use out of memory your docker may be terminated by system


  1. You need to config file in tensorflow serving container to increase timeout
$vi /usr/bin/ => add --rest_api_timeout_in_ms=3000000 it mean that timeout 50 minute

2. You can set memory to container

docker run -m 10g  -p 8502:8501 --oom-kill-disable --mount type=bind,source=/home/ponlork/models/keras_sr/,target=/models/keras_sr -e MODEL_NAME=keras_sr -t tensorflow/serving

Note: In training process the program downscale 4 times so 128/4 = 32 ,but when deployed to tensorflow serving you can predict any size.

Predict local

In this article , I will show you how to use your model to predict local.

Load image from path => read and convert it to array => Normalize it=> model predict=>denormalize data => write image

Save restore karas model

In training process , you need to save and restore to continues another training.

keras_model = load_model(model_path, custom_objects={‘vgg_loss’: loss.vgg_loss})

The below article I will show you the training codes.

Tensorflow serving

I recommend that you use tensorflow serving to deploy model as server.

$docker pull tensorflow/serving

Training process

File structure:

  1. : Is neural network
  2. Utils: is code ready image , prepare data for training
  3. logfile: to load model to restore
  4. train: to train data to neural network
  5. content optimizer

Note: this code include code to use tensorboard.


In above article , I want to show about neural network can help people in everyday life. It can upscale 4 times the image size and keep the same quality or better quality as people need.One thing, the reader can understand how to deploy it to use on the web service as individual needs. One more thing , they can understand some technology such as docker,tensorflow serving,tensorboard,keras …etc.

My feeling right now , is that I want to thank you for support and follow.Next topic I will try to find any thing more that help you or people can use as normal in everyday life.


Developing next-generation technology in Combodia

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store