- Notifications
You must be signed in to change notification settings - Fork0
🔎 Super-scale your images and run experiments with Residual Dense and Adversarial Networks.
License
noderaider/image-super-resolution
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The goal of this project is to upscale and improve the quality of low resolution images.
This project contains Keras implementations of different Residual Dense Networks for Single Image Super-Resolution (ISR) as well as scripts to train these networks using content and adversarial loss components.
The implemented networks include:
- The super-scaling Residual Dense Network described inResidual Dense Network for Image Super-Resolution (Zhang et al. 2018)
- The super-scaling Residual in Residual Dense Network described inESRGAN: Enhanced Super-Resolution Generative Adversarial Networks (Wang et al. 2018)
- A multi-output version of the Keras VGG19 network for deep features extraction used in the perceptual loss
- A custom discriminator network based on the one described inPhoto-Realistic Single Image Super-Resolution Using a Generative Adversarial Network (SRGANS, Ledig et al. 2017)
Read the full documentation at:https://idealo.github.io/image-super-resolution/.
Docker scripts andGoogle Colab notebooks are available to carry training and prediction. Also, we provide scripts to facilitate training on the cloud with AWS andnvidia-docker with only a few commands.
ISR is compatible with Python 3.6 and is distributed under the Apache 2.0 license. We welcome any kind of contribution. If you wish to contribute, please see theContribute section.
The weights used to produced these images are available undersample_weights (seeAdditional Information).
IMPORTANT: the weights are stored ongit lfs. To download them clone the repository and rungit lfs pull; if getting quota issues, go hereidealo#59 (comment).
RRDN model, PSNR driven, weightshere.
![]() |
|---|
| Low resolution image (left), ISR output (center), bicubic scaling (right). Click to zoom. |
RRDN model, trained with Adversarial and VGG features losses, weightshere.
![]() |
|---|
| RRDN GANS model (left), bicubic upscaling (right). |
| ->more detailed comparison |
RDN model, trained with Adversarial and VGG features losses, weightshere.
![]() |
|---|
| Standard vs GANS model. Click to zoom. |
![]() |
|---|
| RDN GANS artefact cancelling model (left), RDN standard PSNR driven model (right). |
| ->more detailed comparison |
There are two ways to install the Image Super-Resolution package:
- Install ISR from PyPI (recommended):
pip install ISR- Install ISR from the GitHub source:
git clone https://github.com/idealo/image-super-resolutioncd image-super-resolutiongit lfs pullpython setup.py installLoad image and prepare it
importnumpyasnpfromPILimportImageimg=Image.open('data/input/test_images/sample_image.jpg')lr_img=np.array(img)
Load model and run prediction
fromISR.modelsimportRDNrdn=RDN(arch_params={'C':6,'D':20,'G':64,'G0':64,'x':2})rdn.model.load_weights('weights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5')sr_img=rdn.predict(lr_img)Image.fromarray(sr_img)
To predict on large images and avoid memory allocation errors, use theby_patch_of_size option for the predict method, for instance
sr_img = model.predict(image, by_patch_of_size=50)Check the documentation of theImageModel class for further details.
Create the models
fromISR.modelsimportRRDNfromISR.modelsimportDiscriminatorfromISR.modelsimportCut_VGG19lr_train_patch_size=40layers_to_extract= [5,9]scale=2hr_train_patch_size=lr_train_patch_size*scalerrdn=RRDN(arch_params={'C':4,'D':3,'G':64,'G0':64,'T':10,'x':scale},patch_size=lr_train_patch_size)f_ext=Cut_VGG19(patch_size=hr_train_patch_size,layers_to_extract=layers_to_extract)discr=Discriminator(patch_size=hr_train_patch_size,kernel_size=3)
Create a Trainer object using the desired settings and give it the models (f_ext anddiscr are optional)
fromISR.trainimportTrainerloss_weights= {'generator':0.0,'feature_extractor':0.0833,'discriminator':0.01}losses= {'generator':'mae','feature_extractor':'mse','discriminator':'binary_crossentropy'}log_dirs= {'logs':'./logs','weights':'./weights'}learning_rate= {'initial_value':0.0004,'decay_factor':0.5,'decay_frequency':30}flatness= {'min':0.0,'max':0.15,'increase':0.01,'increase_frequency':5}trainer=Trainer(generator=rrdn,discriminator=discr,feature_extractor=f_ext,lr_train_dir='low_res/training/images',hr_train_dir='high_res/training/images',lr_valid_dir='low_res/validation/images',hr_valid_dir='high_res/validation/images',loss_weights=loss_weights,learning_rate=learning_rate,flatness=flatness,dataname='image_dataset',log_dirs=log_dirs,weights_generator=None,weights_discriminator=None,n_validation=40,)
Start training
trainer.train(epochs=80,steps_per_epoch=500,batch_size=16,monitored_metrics={'val_PSNR_Y':'max'})
You can read about how we trained these network weights in our Medium posts:
- part 1:A deep learning based magnifying glass
- part 2:Zoom in... enhance
The weights of the RDN network trained on theDIV2K dataset are available inweights/sample_weights/rdn-C6-D20-G64-G064-x2/PSNR-driven/rdn-C6-D20-G64-G064-x2_PSNR_epoch086.hdf5.
The model was trained usingC=6, D=20, G=64, G0=64 as parameters (see architecture for details) for 86 epochs of 1000 batches of 8 32x32 augmented patches taken from LR images.
The artefact can cancelling weights obtained with a combination of different training sessions using different datasets and perceptual loss with VGG19 and GAN can be found atweights/sample_weights/rdn-C6-D20-G64-G064-x2/ArtefactCancelling/rdn-C6-D20-G64-G064-x2_ArtefactCancelling_epoch219.hdf5We recommend using these weights only when cancelling compression artefacts is a desirable effect.
The main parameters of the architecture structure are:
- D - number of Residual Dense Blocks (RDB)
- C - number of convolutional layers stacked inside a RDB
- G - number of feature maps of each convolutional layers inside the RDBs
- G0 - number of feature maps for convolutions outside of RDBs and of each RBD output
source:Residual Dense Network for Image Super-Resolution
The main parameters of the architecture structure are:
- T - number of Residual in Residual Dense Blocks (RRDB)
- D - number of Residual Dense Blocks (RDB) insider each RRDB
- C - number of convolutional layers stacked inside a RDB
- G - number of feature maps of each convolutional layers inside the RDBs
- G0 - number of feature maps for convolutions outside of RDBs and of each RBD output
source:ESRGAN: Enhanced Super-Resolution Generative Adversarial Networks
We welcome all kinds of contributions, models trained on different datasets, new model architectures and/or hyperparameters combinations that improve the performance of the currently published model.
Will publish the performances of new models in this repository.
See theContribution guide for more details.
To bump up the version, use
bumpversion {part} setup.pyPlease cite our work in your publications if it helps your research.
@misc{cardinale2018isr, title={ISR}, author={Francesco Cardinale et al.}, year={2018}, howpublished={\url{https://github.com/idealo/image-super-resolution}},}- Francesco Cardinale, github:cfrancesco
- Zubin John, github:valiantone
- Dat Tran, github:datitran
SeeLICENSE for details.
About
🔎 Super-scale your images and run experiments with Residual Dense and Adversarial Networks.
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- Python99.8%
- Shell0.2%








