image-super-resolution

授权协议 Apache-2.0 License
开发语言 Python
所属分类 神经网络/人工智能、 机器学习/深度学习
软件类型 开源软件
地区 不详
投 递 者 壤驷涛
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Image Super-Resolution (ISR)

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:

Read the full documentation at: https://idealo.github.io/image-super-resolution/.

Docker scripts and Google Colab notebooks are available to carry training and prediction. Also, we provide scripts to facilitate training on the cloud with AWS and nvidia-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 the Contribute section.

Contents

Troubleshooting

Training not delivering good/patchy results

When training your own model, start with only PSNR loss (50+ epochs, depending on the dataset) and only then introduce GANS and feature loss. This can be controlled by the loss weights argument.

This is just sample, you will need to tune these parameters.

PSNR only:

loss_weights = {
  'generator': 1.0,
  'feature_extractor': 0.0,
  'discriminator': 0.00
}

Later:

loss_weights = {
  'generator': 0.0,
  'feature_extractor': 0.0833,
  'discriminator': 0.01
}

Weights loading

If you are having trouble loading your own weights or the pre-trained weights (AttributeError: 'str' object has no attribute 'decode'), try:

pip install 'h5py==2.10.0' --force-reinstall

Issue

Pre-trained networks

The weights used to produced these images are available directly when creating the model object.

Currently 4 models are available:

  • RDN: psnr-large, psnr-small, noise-cancel
  • RRDN: gans

Example usage:

model = RRDN(weights='gans')

The network parameters will be automatically chosen.(see Additional Information).

Basic model

RDN model, PSNR driven, choose the option weights='psnr-large' or weights='psnr-small' when creating a RDN model.

Low resolution image (left), ISR output (center), bicubic scaling (right). Click to zoom.

GANS model

RRDN model, trained with Adversarial and VGG features losses, choose the option weights='gans' when creating a RRDN model.

RRDN GANS model (left), bicubic upscaling (right).
-> more detailed comparison

Artefact Cancelling GANS model

RDN model, trained with Adversarial and VGG features losses, choose the option weights='noise-cancel' when creating a RDN model.

Standard vs GANS model. Click to zoom.
RDN GANS artefact cancelling model (left), RDN standard PSNR driven model (right).
-> more detailed comparison

Installation

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-resolution
cd image-super-resolution
python setup.py install

Usage

Prediction

Load image and prepare it

import numpy as np
from PIL import Image

img = Image.open('data/input/test_images/sample_image.jpg')
lr_img = np.array(img)

Load a pre-trained model and run prediction (check the prediction tutorial under notebooks for more details)

from ISR.models import RDN

rdn = RDN(weights='psnr-small')
sr_img = rdn.predict(lr_img)
Image.fromarray(sr_img)

Large image inference

To predict on large images and avoid memory allocation errors, use the by_patch_of_size option for the predict method, for instance

sr_img = model.predict(image, by_patch_of_size=50)

Check the documentation of the ImageModel class for further details.

Training

Create the models

from ISR.models import RRDN
from ISR.models import Discriminator
from ISR.models import Cut_VGG19

lr_train_patch_size = 40
layers_to_extract = [5, 9]
scale = 2
hr_train_patch_size = lr_train_patch_size * scale

rrdn  = 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 and discr are optional)

from ISR.train import Trainer
loss_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'}
)

Additional Information

You can read about how we trained these network weights in our Medium posts:

RDN Pre-trained weights

The weights of the RDN network trained on the DIV2K dataset are available in weights/sample_weights/rdn-C6-D20-G64-G064-x2/PSNR-driven/rdn-C6-D20-G64-G064-x2_PSNR_epoch086.hdf5.
The model was trained using C=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 at weights/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.

RDN Network architecture

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

RRDN Network architecture

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

Contribute

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 the Contribution guide for more details.

Bump version

To bump up the version, use

bumpversion {part} setup.py

Citation

Please 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}},
}

Maintainers

Copyright

See LICENSE for details.

  • 初学者可能往往会把图像分辨率和超分辨率搞混淆,先来看一下他们的概念。 1.分辨率 图像分辨率指图像中存储的信息量,是每英寸图像内有多少个像素点,分辨率的单位为PPI(Pixels Per Inch),通常叫做像素每英寸。一般情况下,图像分辨率越高,图像中包含的细节就越多,信息量也越大。图像分辨率分为空间分辨率和时间分辨率。通常,分辨率被表示成每一个方向上的像素数量,例如64*64的二维图像。但分辨

  • Single-Image-Super-Resolution A list of resources for example-based single image super-resolution, inspired by Awesome-deep-vision and Awesome Computer Vision . Example-based methods Early learning-ba

 相关资料
  • Super Image Picker是一款功能超强的图片选择器。支持超大图预览(比如 10000*5000 的图),支持图片裁剪,可配置头像模式和普通模式,支持动态配置 ImageLoader 以支持多种图片加载库,以及实现流畅的跳转动画。 如何添加 Gradle 1.在Project的build.gradle 中添加仓库地址  // JitPack仓库地址 maven { url "https:

  • AMD FidelityFX Super Resolution (FSR) 是一种开源、高质量的解决方案,用于把较低分辨率的图像输入转变成高分辨率图像输出。 它使用了一系列尖端算法,特别强调创建高质量的边缘,与直接以原始分辨率渲染相比,性能有了很大的提升。FSR 为昂贵的渲染操作(例如硬件光线追踪)提供“实用性能”。 构建说明 前提条件:要构建FSR样本,请遵循以下说明: 1. 安装以下工具:  

  • 前面不止一次讲过, Python 中子类会继承父类所有的类属性和类方法。严格来说,类的构造方法其实就是实例方法,因此毫无疑问,父类的构造方法,子类同样会继承。 但我们知道,Python 是一门支持多继承的面向对象编程语言,如果子类继承的多个父类中包含同名的类实例方法,则子类对象在调用该方法时,会优先选择排在最前面的父类中的实例方法。显然,构造方法也是如此。 举个例子: 运行结果,结果为: 我是人,

  • super-diamond 提供系统参数配置管理,例如数据库的配置信息等,配置参数修改以后可以实时推送到客户端(基于netty4), 方便系统动态修改运行参数。 可以建多个项目,每个项目分为三种profile(development、test、production), 能够控制profile 级别的权限。 所有参数均由development profile配置,test和production pr

  • super-bbs 是一个基于Flask的bbs论坛类项目,前端由Vue 开发,有用户和管理员两套界面。 声明: 严重高仿(照抄)V2EX 开发原因: 前后端分离,替换原来的 FakeV2EX 项目

  • Super Rentals This is a working repository for the Super Rentals tutorial,which you can check out at https://guides.emberjs.com/release/tutorial/. Prerequisites You will need the following things prop