This article is part of a series about upscaling icon themes with AI. While this page is part 3, part 2 is available here and part 4 is available here.
Pixel Pal is a project I have started whose purpose is to bring new life to old icon themes. Many old icon themes are in raster format and are not available for HiDPI screens. Because the icons are low-resolution. Currently the only way to handle old icon themes is to resample them by the desired factor, but the icons look pixelated. The goal of this project is to upscale icon themes with AI.
In this part I will cover losses, metrics and targets. Before going on about training deep learning networks to upsample intelligently icon images, we need ways to measure whether our models are doing a good job. In particular, I need to know if a model does better than simply pixel doubling.
The images above show side by side the same vector icon but the left icon was rasterised as a 32 by 32 pixel image and the right icon was rasterized as a 64 by 64 pixel image. Furthermore, the former was upsampled using pixel doubling.
As you can see the two images are similar but not identical. I need some way to measure how similar the two are. Simply counting the number of identical pixels is problematic. Just because two pixels aren’t identical does not mean they are not similar. Counting the number of identical pixels as a metric will probably be too strict. So, for this project, I will rely on two metrics suggested in the following article: An Introduction to Super Resolution using Deep Learning. The metrics in question are the following:
For reference the metrics for the pair of images above are :
- Peak Signal-to-Noise Ratio: 16.91 dB
- Structural Similarity: 0.83
Measuring how similar two images are is already a good start. It provides us an idea of how well our models are working. However, there are some limits to metrics:
- Metrics are not always differentiable. However training neural networks requires a way to measure the distance between the desired output and the output the network is producing. This is where losses come into play.
- You need to have some good baselines. In other words, the metric in itself is not useful; you need to have an objective. Such as doing better than simple pixel doubling or bicubic interpolation.
- Metrics will be sensitive to the data you use. You may end up with images that are easy to upsample, and the metric may be deceptively good. This is why you should compute the metrics on the entire dataset and do some statistics on it.
- Metrics are not perfect. In the end we want something to be visually pleasing not something that maximises a mathematical function. This is why you should also visually inspect the output of a neural networks.
To train the network, I will use a loss function. Loss function are ways to measure the distance between the ideal output and the current output. In our case, I will use mean squared error as it is simple and fits our purpose. Always make sure you are using an appropriate loss function.
My objective will be to perform better than straight upsampling via nearest-neighbour and bilinear interpolation.