• Stars
    star
    3,313
  • Rank 13,538 (Top 0.3 %)
  • Language
    Python
  • Created over 7 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network

Super Resolution Examples

SRGAN Architecture

Prepare Data and Pre-trained VGG

    1. You need to download the pretrained VGG19 model weights in here.
    1. You need to have the high resolution images for training.
    • In this experiment, I used images from DIV2K - bicubic downscaling x4 competition, so the hyper-paremeters in config.py (like number of epochs) are seleted basic on that dataset, if you change a larger dataset you can reduce the number of epochs.
    • If you dont want to use DIV2K dataset, you can also use Yahoo MirFlickr25k, just simply download it using train_hr_imgs = tl.files.load_flickr25k_dataset(tag=None) in main.py.
    • If you want to use your own images, you can set the path to your image folder via config.TRAIN.hr_img_path in config.py.

Run

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ You need install TensorLayerX at first!

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ Please install TensorLayerX via source

pip install git+https://github.com/tensorlayer/tensorlayerx.git 

Train

config.TRAIN.img_path = "your_image_folder/"

Your directory structure should look like this:

srgan/
    โ””โ”€โ”€ config.py
    โ””โ”€โ”€ srgan.py
    โ””โ”€โ”€ train.py
    โ””โ”€โ”€ vgg.py
    โ””โ”€โ”€ model
          โ””โ”€โ”€ vgg19.npy
    โ””โ”€โ”€ DIV2K
          โ””โ”€โ”€ DIV2K_train_HR
          โ”œโ”€โ”€ DIV2K_train_LR_bicubic
          โ”œโ”€โ”€ DIV2K_valid_HR
          โ””โ”€โ”€ DIV2K_valid_LR_bicubic

  • Start training.
python train.py

๐Ÿ”ฅModify a line of code in train.py, easily switch to any framework!

import os
os.environ['TL_BACKEND'] = 'tensorflow'
# os.environ['TL_BACKEND'] = 'mindspore'
# os.environ['TL_BACKEND'] = 'paddle'
# os.environ['TL_BACKEND'] = 'pytorch'

๐Ÿšง We will support PyTorch as Backend soon.

Evaluation.

๐Ÿ”ฅ We have trained SRGAN on DIV2K dataset. ๐Ÿ”ฅ Download model weights as follows.

SRGAN_g SRGAN_d
TensorFlow Baidu, Googledrive Baidu, Googledrive
PaddlePaddle Baidu, Googledrive Baidu, Googledrive
MindSpore ๐ŸšงComing soon! ๐ŸšงComing soon!
PyTorch ๐ŸšงComing soon! ๐ŸšงComing soon!

Download weights file and put weights under the folder srgan/models/.

Your directory structure should look like this:

srgan/
    โ””โ”€โ”€ config.py
    โ””โ”€โ”€ srgan.py
    โ””โ”€โ”€ train.py
    โ””โ”€โ”€ vgg.py
    โ””โ”€โ”€ model
          โ””โ”€โ”€ vgg19.npy
    โ””โ”€โ”€ DIV2K
          โ”œโ”€โ”€ DIV2K_train_HR
          โ”œโ”€โ”€ DIV2K_train_LR_bicubic
          โ”œโ”€โ”€ DIV2K_valid_HR
          โ””โ”€โ”€ DIV2K_valid_LR_bicubic
    โ””โ”€โ”€ models
          โ”œโ”€โ”€ g.npz  # You should rename the weigths file. 
          โ””โ”€โ”€ d.npz  # If you set os.environ['TL_BACKEND'] = 'tensorflow',you should rename srgan-g-tensorflow.npz to g.npz .

  • Start evaluation.
python train.py --mode=eval

Results will be saved under the folder srgan/samples/.

Results

Reference

Citation

If you find this project useful, we would be grateful if you cite the TensorLayer paper๏ผš

@article{tensorlayer2017,
author = {Dong, Hao and Supratak, Akara and Mai, Luo and Liu, Fangde and Oehmichen, Axel and Yu, Simiao and Guo, Yike},
journal = {ACM Multimedia},
title = {{TensorLayer: A Versatile Library for Efficient Deep Learning Development}},
url = {http://tensorlayer.org},
year = {2017}
}

@inproceedings{tensorlayer2021,
  title={TensorLayer 3.0: A Deep Learning Library Compatible With Multiple Backends},
  author={Lai, Cheng and Han, Jiarong and Dong, Hao},
  booktitle={2021 IEEE International Conference on Multimedia \& Expo Workshops (ICMEW)},
  pages={1--3},
  year={2021},
  organization={IEEE}
}

Other Projects

Discussion

License

  • For academic and non-commercial use only.
  • For commercial use, please contact [email protected].

More Repositories

1

TensorLayer

Deep Learning and Reinforcement Learning Library for Scientists and Engineers
Python
7,333
star
2

HyperPose

Library for Fast and Flexible Human Pose Estimation
Python
1,248
star
3

seq2seq-chatbot

Chatbot in 200 lines of code using TensorLayer
Python
837
star
4

RLzoo

A Comprehensive Reinforcement Learning Zoo for Simple Usage ๐Ÿš€
Python
623
star
5

TensorLayerX

TensorLayerX: A Unified Deep Learning and Reinforcement Learning Framework for All Hardwares, Backends and OS.
Python
506
star
6

text-antispam

ๅ•†็”จ็บงๅžƒๅœพๆ–‡ๆœฌๅˆ†็ฑปๅ™จ
Python
404
star
7

tensorlayer-chinese

TensorLayer ไธญๆ–‡ๆ–‡ๆกฃ
361
star
8

DCGAN

The Simplest DCGAN Implementation
Python
339
star
9

awesome-tensorlayer

A curated list of dedicated resources and applications
266
star
10

DAGAN

The implementation code for "DAGAN: Deep De-Aliasing Generative Adversarial Networks for Fast Compressed Sensing MRI Reconstruction"
Python
167
star
11

chinese-book

ใ€Šๆทฑๅบฆๅญฆไน ๏ผšไธ€่ตท็Žฉ่ฝฌTensorLayerใ€‹่ต„ๆบๅˆ†ไบซใ€่ฎจ่ฎบ
140
star
12

adaptive-style-transfer

Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization
Python
114
star
13

pretrained-models

76
star
14

TLXZoo

Pre-trained backbones for TensorLayerX
Python
33
star
15

HaoDong_aicourse2023_codes

Python
26
star
16

TLX2ONNX

ONNX Model Exporter for TensorLayerX
Python
21
star
17

cyclegan

CycleGAN in 300 lines of code
Python
20
star
18

TLXCV

A Platform-agnostic Computer Vision Application Library
Python
11
star
19

Paddle2TLX

Transfer PaddlePaddle's codes to TensorLayerX's codes
Python
11
star
20

TLXNLP

A Platform-agnostic Natural Language Processing Application Library
3
star
21

fMRI-deep-image-reconstruction

fMRI deep image reconstruction
Python
2
star
22

arcface-tlx

2
star
23

tlxvision

Computer vision algorithms implemented in TensorLayerX
Python
1
star