Upscale images by a factor of 2 via deep convolutional neural network in Python: API and pre-trained models, based on the ESPC architecture by Shi et al. 2016 [1].
Two pre-trained models are included: Luminance and RGB, both of which were trained on approximately 33k various images (~6.5Gb). You can, however, use any Tensorflow model which is compatible with the architecture, or even train your own, in which case UpscalingUtilities
package and Training.ipynb
notebook may be useful.
Requirements: Tensorflow
, PIL
. Tested on Python 3.10.
- Import necessary utilities, all dependencies are loaded automatically:
from UpscalingUtilities import *
from Neural_Upscale_2x import *
- Load desired model. Pre-trained models are either
Luminance_Model
orRGB_Model
. Say you want to use the first one:
model = load_upscaling_model('../Luminance_Model')
- Load desired image using
Tensorflow
's function, which returns aPIL
image instance:
img = load_img('../img.png')
- Initialize an upscaler object using the appropriate function. Either
luminanceUpscaler()
orrgbUpscaler()
. In this example:
upscaler = luminanceUpscaler(model)
- Upscale! Returns an image upscaled by a factor of 2 in both width and height (4 times as many pixels) as a
PIL
image instance, which you can save as usual:
img_2x = upscaler.upscale(img)
img_2x.save('../title.png')
[1] Wenzhe Shi, Jose Caballero, Ferenc Huszár, Johannes Totz, Andrew P Aitken, Rob Bishop, Daniel Rueckert, and Zehan Wang. Real-time single image and video super-resolution using an efficient sub-pixel convolutional neural network. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 1874–1883, 2016.