Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4abfb2979 | ||
|
|
5ca1078535 | ||
|
|
fa4c8a03ae | ||
|
|
37a7c5726d | ||
|
|
382d5be582 | ||
|
|
61e81d3108 | ||
|
|
8f5744bc51 | ||
|
|
d9c2e77853 | ||
|
|
0ac8d66d39 | ||
|
|
89aa45c72d | ||
|
|
f18f613acc | ||
|
|
870a997099 | ||
|
|
576aaddfaf | ||
|
|
b827be13a1 | ||
|
|
e5e79fbde3 | ||
|
|
e5763af574 | ||
|
|
e2db576020 | ||
|
|
6b15fc6936 | ||
|
|
bc77ca5666 | ||
|
|
23d180fd8d | ||
|
|
38c913f1af | ||
|
|
8cb9bd403e | ||
|
|
8041099021 | ||
|
|
40d964c08d | ||
|
|
cdc14b74a5 | ||
|
|
827fae3bdc | ||
|
|
c8346f8823 | ||
|
|
abe36dfd04 | ||
|
|
89d897650c | ||
|
|
685d429c81 | ||
|
|
13c95fe094 | ||
|
|
82cf0e8e4a | ||
|
|
cddc2ff658 | ||
|
|
98add035f2 | ||
|
|
5adeaa2588 | ||
|
|
9ff1944d06 | ||
|
|
3d96c8ab9f | ||
|
|
f115f40a77 | ||
|
|
2b4e485eb0 | ||
|
|
01aeba2f7a | ||
|
|
3e65d21817 | ||
|
|
b7f191a9f5 | ||
|
|
e83bf0e1e4 |
33
.github/workflows/no-response.yml
vendored
@@ -1,33 +0,0 @@
|
|||||||
name: No Response
|
|
||||||
|
|
||||||
# TODO: it seems not to work
|
|
||||||
# Modified from: https://raw.githubusercontent.com/github/docs/main/.github/workflows/no-response.yaml
|
|
||||||
|
|
||||||
# **What it does**: Closes issues that don't have enough information to be actionable.
|
|
||||||
# **Why we have it**: To remove the need for maintainers to remember to check back on issues periodically
|
|
||||||
# to see if contributors have responded.
|
|
||||||
# **Who does it impact**: Everyone that works on docs or docs-internal.
|
|
||||||
|
|
||||||
on:
|
|
||||||
issue_comment:
|
|
||||||
types: [created]
|
|
||||||
|
|
||||||
schedule:
|
|
||||||
# Schedule for five minutes after the hour every hour
|
|
||||||
- cron: '5 * * * *'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
noResponse:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: lee-dohm/no-response@v0.5.0
|
|
||||||
with:
|
|
||||||
token: ${{ github.token }}
|
|
||||||
closeComment: >
|
|
||||||
This issue has been automatically closed because there has been no response
|
|
||||||
to our request for more information from the original author. With only the
|
|
||||||
information that is currently in the issue, we don't have enough information
|
|
||||||
to take action. Please reach out if you have or find the answers we need so
|
|
||||||
that we can investigate further.
|
|
||||||
If you still have questions, please improve your description and re-open it.
|
|
||||||
Thanks :-)
|
|
||||||
41
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
name: release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
permissions: write-all
|
||||||
|
name: Create Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Create Release
|
||||||
|
id: create_release
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag_name: ${{ github.ref }}
|
||||||
|
release_name: Real-ESRGAN ${{ github.ref }} Release Note
|
||||||
|
body: |
|
||||||
|
🚀 See you again 😸
|
||||||
|
🚀Have a nice day 😸 and happy everyday 😃
|
||||||
|
🚀 Long time no see ☄️
|
||||||
|
|
||||||
|
✨ **Highlights**
|
||||||
|
✅ [Features] Support ...
|
||||||
|
|
||||||
|
🐛 **Bug Fixes**
|
||||||
|
|
||||||
|
🌴 **Improvements**
|
||||||
|
|
||||||
|
📢📢📢
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://raw.githubusercontent.com/xinntao/Real-ESRGAN/master/assets/realesrgan_logo.png" height=150>
|
||||||
|
</p>
|
||||||
|
draft: true
|
||||||
|
prerelease: false
|
||||||
2
.gitignore
vendored
@@ -5,7 +5,7 @@ results/*
|
|||||||
tb_logger/*
|
tb_logger/*
|
||||||
wandb/*
|
wandb/*
|
||||||
tmp/*
|
tmp/*
|
||||||
realesrgan/weights/*
|
weights/*
|
||||||
|
|
||||||
version.py
|
version.py
|
||||||
|
|
||||||
|
|||||||
128
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
We as members, contributors, and leaders pledge to make participation in our
|
||||||
|
community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||||
|
identity and expression, level of experience, education, socio-economic status,
|
||||||
|
nationality, personal appearance, race, religion, or sexual identity
|
||||||
|
and orientation.
|
||||||
|
|
||||||
|
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||||
|
diverse, inclusive, and healthy community.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to a positive environment for our
|
||||||
|
community include:
|
||||||
|
|
||||||
|
* Demonstrating empathy and kindness toward other people
|
||||||
|
* Being respectful of differing opinions, viewpoints, and experiences
|
||||||
|
* Giving and gracefully accepting constructive feedback
|
||||||
|
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||||
|
and learning from the experience
|
||||||
|
* Focusing on what is best not just for us as individuals, but for the
|
||||||
|
overall community
|
||||||
|
|
||||||
|
Examples of unacceptable behavior include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery, and sexual attention or
|
||||||
|
advances of any kind
|
||||||
|
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or email
|
||||||
|
address, without their explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Enforcement Responsibilities
|
||||||
|
|
||||||
|
Community leaders are responsible for clarifying and enforcing our standards of
|
||||||
|
acceptable behavior and will take appropriate and fair corrective action in
|
||||||
|
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||||
|
or harmful.
|
||||||
|
|
||||||
|
Community leaders have the right and responsibility to remove, edit, or reject
|
||||||
|
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||||
|
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||||
|
decisions when appropriate.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies within all community spaces, and also applies when
|
||||||
|
an individual is officially representing the community in public spaces.
|
||||||
|
Examples of representing our community include using an official e-mail address,
|
||||||
|
posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported to the community leaders responsible for enforcement at
|
||||||
|
xintao.wang@outlook.com or xintaowang@tencent.com.
|
||||||
|
All complaints will be reviewed and investigated promptly and fairly.
|
||||||
|
|
||||||
|
All community leaders are obligated to respect the privacy and security of the
|
||||||
|
reporter of any incident.
|
||||||
|
|
||||||
|
## Enforcement Guidelines
|
||||||
|
|
||||||
|
Community leaders will follow these Community Impact Guidelines in determining
|
||||||
|
the consequences for any action they deem in violation of this Code of Conduct:
|
||||||
|
|
||||||
|
### 1. Correction
|
||||||
|
|
||||||
|
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||||
|
unprofessional or unwelcome in the community.
|
||||||
|
|
||||||
|
**Consequence**: A private, written warning from community leaders, providing
|
||||||
|
clarity around the nature of the violation and an explanation of why the
|
||||||
|
behavior was inappropriate. A public apology may be requested.
|
||||||
|
|
||||||
|
### 2. Warning
|
||||||
|
|
||||||
|
**Community Impact**: A violation through a single incident or series
|
||||||
|
of actions.
|
||||||
|
|
||||||
|
**Consequence**: A warning with consequences for continued behavior. No
|
||||||
|
interaction with the people involved, including unsolicited interaction with
|
||||||
|
those enforcing the Code of Conduct, for a specified period of time. This
|
||||||
|
includes avoiding interactions in community spaces as well as external channels
|
||||||
|
like social media. Violating these terms may lead to a temporary or
|
||||||
|
permanent ban.
|
||||||
|
|
||||||
|
### 3. Temporary Ban
|
||||||
|
|
||||||
|
**Community Impact**: A serious violation of community standards, including
|
||||||
|
sustained inappropriate behavior.
|
||||||
|
|
||||||
|
**Consequence**: A temporary ban from any sort of interaction or public
|
||||||
|
communication with the community for a specified period of time. No public or
|
||||||
|
private interaction with the people involved, including unsolicited interaction
|
||||||
|
with those enforcing the Code of Conduct, is allowed during this period.
|
||||||
|
Violating these terms may lead to a permanent ban.
|
||||||
|
|
||||||
|
### 4. Permanent Ban
|
||||||
|
|
||||||
|
**Community Impact**: Demonstrating a pattern of violation of community
|
||||||
|
standards, including sustained inappropriate behavior, harassment of an
|
||||||
|
individual, or aggression toward or disparagement of classes of individuals.
|
||||||
|
|
||||||
|
**Consequence**: A permanent ban from any sort of public interaction within
|
||||||
|
the community.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||||
|
version 2.0, available at
|
||||||
|
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||||
|
|
||||||
|
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||||
|
enforcement ladder](https://github.com/mozilla/diversity).
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see the FAQ at
|
||||||
|
https://www.contributor-covenant.org/faq. Translations are available at
|
||||||
|
https://www.contributor-covenant.org/translations.
|
||||||
@@ -5,4 +5,4 @@ include inference_realesrgan.py
|
|||||||
include VERSION
|
include VERSION
|
||||||
include LICENSE
|
include LICENSE
|
||||||
include requirements.txt
|
include requirements.txt
|
||||||
include realesrgan/weights/README.md
|
include weights/README.md
|
||||||
|
|||||||
288
README.md
@@ -1,4 +1,12 @@
|
|||||||
# Real-ESRGAN
|
<p align="center">
|
||||||
|
<img src="assets/realesrgan_logo.png" height=120>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## <div align="center"><b><a href="README.md">English</a> | <a href="README_CN.md">简体中文</a></b></div>
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
|
👀[**Demos**](#-demos-videos) **|** 🚩[**Updates**](#-updates) **|** ⚡[**Usage**](#-quick-inference) **|** 🏰[**Model Zoo**](docs/model_zoo.md) **|** 🔧[Install](#-dependencies-and-installation) **|** 💻[Train](docs/Training.md) **|** ❓[FAQ](docs/FAQ.md) **|** 🎨[Contribution](docs/CONTRIBUTING.md)
|
||||||
|
|
||||||
[](https://github.com/xinntao/Real-ESRGAN/releases)
|
[](https://github.com/xinntao/Real-ESRGAN/releases)
|
||||||
[](https://pypi.org/project/realesrgan/)
|
[](https://pypi.org/project/realesrgan/)
|
||||||
@@ -8,49 +16,39 @@
|
|||||||
[](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/pylint.yml)
|
[](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/pylint.yml)
|
||||||
[](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/publish-pip.yml)
|
[](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/publish-pip.yml)
|
||||||
|
|
||||||
[English](README.md) **|** [简体中文](README_CN.md)
|
</div>
|
||||||
|
|
||||||
:fire: :fire: :fire: Add **small video models** for anime videos (**针对动漫视频的小模型**). Please see [anime video models](docs/anime_video_model.md).
|
🔥 **AnimeVideo-v3 model (动漫视频小模型)**. Please see [[*anime video models*](docs/anime_video_model.md)] and [[*comparisons*](docs/anime_comparisons.md)]<br>
|
||||||
|
🔥 **RealESRGAN_x4plus_anime_6B** for anime images **(动漫插图模型)**. Please see [[*anime_model*](docs/anime_model.md)]
|
||||||
|
|
||||||
1. [Colab Demo](https://colab.research.google.com/drive/1k2Zod6kSHEvraybHl50Lys0LerhyTMCo?usp=sharing) for Real-ESRGAN <a href="https://colab.research.google.com/drive/1k2Zod6kSHEvraybHl50Lys0LerhyTMCo?usp=sharing"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a>.
|
<!-- 1. You can try in our website: [ARC Demo](https://arc.tencent.com/en/ai-demos/imgRestore) (now only support RealESRGAN_x4plus_anime_6B) -->
|
||||||
2. Portable [Windows](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-windows.zip) / [Linux](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-ubuntu.zip) / [MacOS](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-macos.zip) **executable files for Intel/AMD/Nvidia GPU**. You can find more information [here](#Portable-executable-files). The ncnn implementation is in [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan).
|
1. :boom: **Update** online Replicate demo: [](https://replicate.com/xinntao/realesrgan)
|
||||||
|
1. Online Colab demo for Real-ESRGAN: [](https://colab.research.google.com/drive/1k2Zod6kSHEvraybHl50Lys0LerhyTMCo?usp=sharing) **|** Online Colab demo for for Real-ESRGAN (**anime videos**): [](https://colab.research.google.com/drive/1yNl9ORUxxlL4N0keJa2SEPB61imPQd1B?usp=sharing)
|
||||||
|
1. Portable [Windows](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-windows.zip) / [Linux](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip) / [MacOS](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-macos.zip) **executable files for Intel/AMD/Nvidia GPU**. You can find more information [here](#portable-executable-files-ncnn). The ncnn implementation is in [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan)
|
||||||
|
<!-- 1. You can watch enhanced animations in [Tencent Video](https://v.qq.com/s/topic/v_child/render/fC4iyCAM.html). 欢迎观看[腾讯视频动漫修复](https://v.qq.com/s/topic/v_child/render/fC4iyCAM.html) -->
|
||||||
|
|
||||||
Real-ESRGAN aims at developing **Practical Algorithms for General Image Restoration**.<br>
|
Real-ESRGAN aims at developing **Practical Algorithms for General Image/Video Restoration**.<br>
|
||||||
We extend the powerful ESRGAN to a practical restoration application (namely, Real-ESRGAN), which is trained with pure synthetic data.
|
We extend the powerful ESRGAN to a practical restoration application (namely, Real-ESRGAN), which is trained with pure synthetic data.
|
||||||
|
|
||||||
:art: Real-ESRGAN needs your contributions. Any contributions are welcome, such as new features/models/typo fixes/suggestions/maintenance, *etc*. See [CONTRIBUTING.md](CONTRIBUTING.md). All contributors are list [here](README.md#hugs-acknowledgement).
|
🌌 Thanks for your valuable feedbacks/suggestions. All the feedbacks are updated in [feedback.md](docs/feedback.md).
|
||||||
|
|
||||||
:question: Frequently Asked Questions can be found in [FAQ.md](FAQ.md) (Well, it is still empty there =-=||).
|
|
||||||
|
|
||||||
:milky_way: Thanks for your valuable feedbacks/suggestions. All the feedbacks are updated in [feedback.md](feedback.md).
|
|
||||||
|
|
||||||
:triangular_flag_on_post: **Updates**
|
|
||||||
- :white_check_mark: Add small models for anime videos. More details are in [anime video models](docs/anime_video_model.md).
|
|
||||||
- :white_check_mark: Add the ncnn implementation [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan).
|
|
||||||
- :white_check_mark: Add [*RealESRGAN_x4plus_anime_6B.pth*](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth), which is optimized for **anime** images with much smaller model size. More details and comparisons with [waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan) are in [**anime_model.md**](docs/anime_model.md)
|
|
||||||
- :white_check_mark: Support finetuning on your own data or paired data (*i.e.*, finetuning ESRGAN). See [here](Training.md#Finetune-Real-ESRGAN-on-your-own-dataset)
|
|
||||||
- :white_check_mark: Integrate [GFPGAN](https://github.com/TencentARC/GFPGAN) to support **face enhancement**.
|
|
||||||
- :white_check_mark: Integrated to [Huggingface Spaces](https://huggingface.co/spaces) with [Gradio](https://github.com/gradio-app/gradio). See [Gradio Web Demo](https://huggingface.co/spaces/akhaliq/Real-ESRGAN). Thanks [@AK391](https://github.com/AK391)
|
|
||||||
- :white_check_mark: Support arbitrary scale with `--outscale` (It actually further resizes outputs with `LANCZOS4`). Add *RealESRGAN_x2plus.pth* model.
|
|
||||||
- :white_check_mark: [The inference code](inference_realesrgan.py) supports: 1) **tile** options; 2) images with **alpha channel**; 3) **gray** images; 4) **16-bit** images.
|
|
||||||
- :white_check_mark: The training codes have been released. A detailed guide can be found in [Training.md](Training.md).
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
If Real-ESRGAN is helpful in your photos/projects, please help to :star: this repo or recommend it to your friends. Thanks:blush: <br>
|
If Real-ESRGAN is helpful, please help to ⭐ this repo or recommend it to your friends 😊 <br>
|
||||||
Other recommended projects:<br>
|
Other recommended projects:<br>
|
||||||
:arrow_forward: [GFPGAN](https://github.com/TencentARC/GFPGAN): A practical algorithm for real-world face restoration <br>
|
▶️ [GFPGAN](https://github.com/TencentARC/GFPGAN): A practical algorithm for real-world face restoration <br>
|
||||||
:arrow_forward: [BasicSR](https://github.com/xinntao/BasicSR): An open-source image and video restoration toolbox<br>
|
▶️ [BasicSR](https://github.com/xinntao/BasicSR): An open-source image and video restoration toolbox<br>
|
||||||
:arrow_forward: [facexlib](https://github.com/xinntao/facexlib): A collection that provides useful face-relation functions.<br>
|
▶️ [facexlib](https://github.com/xinntao/facexlib): A collection that provides useful face-relation functions.<br>
|
||||||
:arrow_forward: [HandyView](https://github.com/xinntao/HandyView): A PyQt5-based image viewer that is handy for view and comparison. <br>
|
▶️ [HandyView](https://github.com/xinntao/HandyView): A PyQt5-based image viewer that is handy for view and comparison <br>
|
||||||
|
▶️ [HandyFigure](https://github.com/xinntao/HandyFigure): Open source of paper figures <br>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### :book: Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data
|
### 📖 Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data
|
||||||
|
|
||||||
> [[Paper](https://arxiv.org/abs/2107.10833)]   [Project Page]   [[YouTube Video](https://www.youtube.com/watch?v=fxHWoDSSvSc)]   [[B站讲解](https://www.bilibili.com/video/BV1H34y1m7sS/)]   [[Poster](https://xinntao.github.io/projects/RealESRGAN_src/RealESRGAN_poster.pdf)]   [[PPT slides](https://docs.google.com/presentation/d/1QtW6Iy8rm8rGLsJ0Ldti6kP-7Qyzy6XL/edit?usp=sharing&ouid=109799856763657548160&rtpof=true&sd=true)]<br>
|
> [[Paper](https://arxiv.org/abs/2107.10833)]   [[YouTube Video](https://www.youtube.com/watch?v=fxHWoDSSvSc)]   [[B站讲解](https://www.bilibili.com/video/BV1H34y1m7sS/)]   [[Poster](https://xinntao.github.io/projects/RealESRGAN_src/RealESRGAN_poster.pdf)]   [[PPT slides](https://docs.google.com/presentation/d/1QtW6Iy8rm8rGLsJ0Ldti6kP-7Qyzy6XL/edit?usp=sharing&ouid=109799856763657548160&rtpof=true&sd=true)]<br>
|
||||||
> [Xintao Wang](https://xinntao.github.io/), Liangbin Xie, [Chao Dong](https://scholar.google.com.hk/citations?user=OSDCB0UAAAAJ), [Ying Shan](https://scholar.google.com/citations?user=4oXBp9UAAAAJ&hl=en) <br>
|
> [Xintao Wang](https://xinntao.github.io/), Liangbin Xie, [Chao Dong](https://scholar.google.com.hk/citations?user=OSDCB0UAAAAJ), [Ying Shan](https://scholar.google.com/citations?user=4oXBp9UAAAAJ&hl=en) <br>
|
||||||
> Tencent ARC Lab; Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences
|
> [Tencent ARC Lab](https://arc.tencent.com/en/ai-demos/imgRestore); Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="assets/teaser.jpg">
|
<img src="assets/teaser.jpg">
|
||||||
@@ -58,78 +56,35 @@ Other recommended projects:<br>
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
We have provided a pretrained model (*RealESRGAN_x4plus.pth*) with upsampling X4.<br>
|
<!---------------------------------- Updates --------------------------->
|
||||||
**Note that RealESRGAN may still fail in some cases as the real-world degradations are really too complex.**<br>
|
## 🚩 Updates
|
||||||
Moreover, it **may not** perform well on **human faces, text**, *etc*, which will be optimized later.
|
|
||||||
<br>
|
|
||||||
|
|
||||||
Real-ESRGAN will be a long-term supported project (in my current plan :smiley:). It will be continuously updated
|
- ✅ Add the **realesr-general-x4v3** model - a tiny small model for general scenes. It also supports the **-dn** option to balance the noise (avoiding over-smooth results). **-dn** is short for denoising strength.
|
||||||
in my spare time.
|
- ✅ Update the **RealESRGAN AnimeVideo-v3** model. Please see [anime video models](docs/anime_video_model.md) and [comparisons](docs/anime_comparisons.md) for more details.
|
||||||
|
- ✅ Add small models for anime videos. More details are in [anime video models](docs/anime_video_model.md).
|
||||||
Here is a TODO list in the near future:
|
- ✅ Add the ncnn implementation [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan).
|
||||||
|
- ✅ Add [*RealESRGAN_x4plus_anime_6B.pth*](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth), which is optimized for **anime** images with much smaller model size. More details and comparisons with [waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan) are in [**anime_model.md**](docs/anime_model.md)
|
||||||
- [ ] optimize for human faces
|
- ✅ Support finetuning on your own data or paired data (*i.e.*, finetuning ESRGAN). See [here](docs/Training.md#Finetune-Real-ESRGAN-on-your-own-dataset)
|
||||||
- [ ] optimize for texts
|
- ✅ Integrate [GFPGAN](https://github.com/TencentARC/GFPGAN) to support **face enhancement**.
|
||||||
- [x] optimize for anime images
|
- ✅ Integrated to [Huggingface Spaces](https://huggingface.co/spaces) with [Gradio](https://github.com/gradio-app/gradio). See [Gradio Web Demo](https://huggingface.co/spaces/akhaliq/Real-ESRGAN). Thanks [@AK391](https://github.com/AK391)
|
||||||
- [ ] support more scales
|
- ✅ Support arbitrary scale with `--outscale` (It actually further resizes outputs with `LANCZOS4`). Add *RealESRGAN_x2plus.pth* model.
|
||||||
- [ ] support controllable restoration strength
|
- ✅ [The inference code](inference_realesrgan.py) supports: 1) **tile** options; 2) images with **alpha channel**; 3) **gray** images; 4) **16-bit** images.
|
||||||
|
- ✅ The training codes have been released. A detailed guide can be found in [Training.md](docs/Training.md).
|
||||||
If you have any good ideas or demands, please open an issue/discussion to let me know. <br>
|
|
||||||
If you have some images that Real-ESRGAN could not well restored, please also open an issue/discussion. I will record it (but I cannot guarantee to resolve it:stuck_out_tongue:). If necessary, I will open a page to specially record these real-world cases that need to be solved, but the current technology is difficult to handle well.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Portable executable files
|
<!---------------------------------- Demo videos --------------------------->
|
||||||
|
## 👀 Demos Videos
|
||||||
|
|
||||||
You can download [Windows](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-windows.zip) / [Linux](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-ubuntu.zip) / [MacOS](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-macos.zip) **executable files for Intel/AMD/Nvidia GPU**.
|
#### Bilibili
|
||||||
|
|
||||||
This executable file is **portable** and includes all the binaries and models required. No CUDA or PyTorch environment is needed.<br>
|
- [大闹天宫片段](https://www.bilibili.com/video/BV1ja41117zb)
|
||||||
|
- [Anime dance cut 动漫魔性舞蹈](https://www.bilibili.com/video/BV1wY4y1L7hT/)
|
||||||
|
- [海贼王片段](https://www.bilibili.com/video/BV1i3411L7Gy/)
|
||||||
|
|
||||||
You can simply run the following command (the Windows example, more information is in the README.md of each executable files):
|
#### YouTube
|
||||||
|
|
||||||
```bash
|
## 🔧 Dependencies and Installation
|
||||||
./realesrgan-ncnn-vulkan.exe -i input.jpg -o output.png -n model_name
|
|
||||||
```
|
|
||||||
|
|
||||||
We have provided five models:
|
|
||||||
|
|
||||||
1. realesrgan-x4plus (default)
|
|
||||||
2. realesrnet-x4plus
|
|
||||||
3. realesrgan-x4plus-anime (optimized for anime images, small model size)
|
|
||||||
4. RealESRGANv2-animevideo-xsx2 (anime video, X2)
|
|
||||||
5. RealESRGANv2-animevideo-xsx4 (anime video, X4)
|
|
||||||
|
|
||||||
You can use the `-n` argument for other models, for example, `./realesrgan-ncnn-vulkan.exe -i input.jpg -o output.png -n realesrnet-x4plus`
|
|
||||||
|
|
||||||
### Usage of executable files
|
|
||||||
|
|
||||||
1. Please refer to [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan#computer-usages) for more details.
|
|
||||||
1. Note that it does not support all the functions (such as `outscale`) as the python script `inference_realesrgan.py`.
|
|
||||||
|
|
||||||
```console
|
|
||||||
Usage: realesrgan-ncnn-vulkan.exe -i infile -o outfile [options]...
|
|
||||||
|
|
||||||
-h show this help
|
|
||||||
-v verbose output
|
|
||||||
-i input-path input image path (jpg/png/webp) or directory
|
|
||||||
-o output-path output image path (jpg/png/webp) or directory
|
|
||||||
-s scale upscale ratio (4, default=4)
|
|
||||||
-t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu
|
|
||||||
-m model-path folder path to pre-trained models(default=models)
|
|
||||||
-n model-name model name (default=realesrgan-x4plus, can be realesrgan-x4plus | realesrgan-x4plus-anime | realesrnet-x4plus)
|
|
||||||
-g gpu-id gpu device to use (default=0) can be 0,1,2 for multi-gpu
|
|
||||||
-j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu
|
|
||||||
-x enable tta mode
|
|
||||||
-f format output image format (jpg/png/webp, default=ext/png)
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that it may introduce block inconsistency (and also generate slightly different results from the PyTorch implementation), because this executable file first crops the input image into several tiles, and then processes them separately, finally stitches together.
|
|
||||||
|
|
||||||
This executable file is based on the wonderful [Tencent/ncnn](https://github.com/Tencent/ncnn) and [realsr-ncnn-vulkan](https://github.com/nihui/realsr-ncnn-vulkan) by [nihui](https://github.com/nihui).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## :wrench: Dependencies and Installation
|
|
||||||
|
|
||||||
- Python >= 3.7 (Recommend to use [Anaconda](https://www.anaconda.com/download/#linux) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html))
|
- Python >= 3.7 (Recommend to use [Anaconda](https://www.anaconda.com/download/#linux) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html))
|
||||||
- [PyTorch >= 1.7](https://pytorch.org/)
|
- [PyTorch >= 1.7](https://pytorch.org/)
|
||||||
@@ -156,14 +111,95 @@ This executable file is based on the wonderful [Tencent/ncnn](https://github.com
|
|||||||
python setup.py develop
|
python setup.py develop
|
||||||
```
|
```
|
||||||
|
|
||||||
## :zap: Quick Inference
|
---
|
||||||
|
|
||||||
### Inference general images
|
## ⚡ Quick Inference
|
||||||
|
|
||||||
|
There are usually three ways to inference Real-ESRGAN.
|
||||||
|
|
||||||
|
1. [Online inference](#online-inference)
|
||||||
|
1. [Portable executable files (NCNN)](#portable-executable-files-ncnn)
|
||||||
|
1. [Python script](#python-script)
|
||||||
|
|
||||||
|
### Online inference
|
||||||
|
|
||||||
|
1. You can try in our website: [ARC Demo](https://arc.tencent.com/en/ai-demos/imgRestore) (now only support RealESRGAN_x4plus_anime_6B)
|
||||||
|
1. [Colab Demo](https://colab.research.google.com/drive/1k2Zod6kSHEvraybHl50Lys0LerhyTMCo?usp=sharing) for Real-ESRGAN **|** [Colab Demo](https://colab.research.google.com/drive/1yNl9ORUxxlL4N0keJa2SEPB61imPQd1B?usp=sharing) for Real-ESRGAN (**anime videos**).
|
||||||
|
|
||||||
|
### Portable executable files (NCNN)
|
||||||
|
|
||||||
|
You can download [Windows](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-windows.zip) / [Linux](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip) / [MacOS](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-macos.zip) **executable files for Intel/AMD/Nvidia GPU**.
|
||||||
|
|
||||||
|
This executable file is **portable** and includes all the binaries and models required. No CUDA or PyTorch environment is needed.<br>
|
||||||
|
|
||||||
|
You can simply run the following command (the Windows example, more information is in the README.md of each executable files):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./realesrgan-ncnn-vulkan.exe -i input.jpg -o output.png -n model_name
|
||||||
|
```
|
||||||
|
|
||||||
|
We have provided five models:
|
||||||
|
|
||||||
|
1. realesrgan-x4plus (default)
|
||||||
|
2. realesrnet-x4plus
|
||||||
|
3. realesrgan-x4plus-anime (optimized for anime images, small model size)
|
||||||
|
4. realesr-animevideov3 (animation video)
|
||||||
|
|
||||||
|
You can use the `-n` argument for other models, for example, `./realesrgan-ncnn-vulkan.exe -i input.jpg -o output.png -n realesrnet-x4plus`
|
||||||
|
|
||||||
|
#### Usage of portable executable files
|
||||||
|
|
||||||
|
1. Please refer to [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan#computer-usages) for more details.
|
||||||
|
1. Note that it does not support all the functions (such as `outscale`) as the python script `inference_realesrgan.py`.
|
||||||
|
|
||||||
|
```console
|
||||||
|
Usage: realesrgan-ncnn-vulkan.exe -i infile -o outfile [options]...
|
||||||
|
|
||||||
|
-h show this help
|
||||||
|
-i input-path input image path (jpg/png/webp) or directory
|
||||||
|
-o output-path output image path (jpg/png/webp) or directory
|
||||||
|
-s scale upscale ratio (can be 2, 3, 4. default=4)
|
||||||
|
-t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu
|
||||||
|
-m model-path folder path to the pre-trained models. default=models
|
||||||
|
-n model-name model name (default=realesr-animevideov3, can be realesr-animevideov3 | realesrgan-x4plus | realesrgan-x4plus-anime | realesrnet-x4plus)
|
||||||
|
-g gpu-id gpu device to use (default=auto) can be 0,1,2 for multi-gpu
|
||||||
|
-j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu
|
||||||
|
-x enable tta mode"
|
||||||
|
-f format output image format (jpg/png/webp, default=ext/png)
|
||||||
|
-v verbose output
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that it may introduce block inconsistency (and also generate slightly different results from the PyTorch implementation), because this executable file first crops the input image into several tiles, and then processes them separately, finally stitches together.
|
||||||
|
|
||||||
|
### Python script
|
||||||
|
|
||||||
|
#### Usage of python script
|
||||||
|
|
||||||
|
1. You can use X4 model for **arbitrary output size** with the argument `outscale`. The program will further perform cheap resize operation after the Real-ESRGAN output.
|
||||||
|
|
||||||
|
```console
|
||||||
|
Usage: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]...
|
||||||
|
|
||||||
|
A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile --outscale 3.5 --face_enhance
|
||||||
|
|
||||||
|
-h show this help
|
||||||
|
-i --input Input image or folder. Default: inputs
|
||||||
|
-o --output Output folder. Default: results
|
||||||
|
-n --model_name Model name. Default: RealESRGAN_x4plus
|
||||||
|
-s, --outscale The final upsampling scale of the image. Default: 4
|
||||||
|
--suffix Suffix of the restored image. Default: out
|
||||||
|
-t, --tile Tile size, 0 for no tile during testing. Default: 0
|
||||||
|
--face_enhance Whether to use GFPGAN to enhance face. Default: False
|
||||||
|
--fp32 Use fp32 precision during inference. Default: fp16 (half precision).
|
||||||
|
--ext Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Inference general images
|
||||||
|
|
||||||
Download pre-trained models: [RealESRGAN_x4plus.pth](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth)
|
Download pre-trained models: [RealESRGAN_x4plus.pth](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P weights
|
||||||
```
|
```
|
||||||
|
|
||||||
Inference!
|
Inference!
|
||||||
@@ -174,7 +210,7 @@ python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance
|
|||||||
|
|
||||||
Results are in the `results` folder
|
Results are in the `results` folder
|
||||||
|
|
||||||
### Inference anime images
|
#### Inference anime images
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_1.png">
|
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_1.png">
|
||||||
@@ -185,42 +221,14 @@ Pre-trained models: [RealESRGAN_x4plus_anime_6B](https://github.com/xinntao/Real
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# download model
|
# download model
|
||||||
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P experiments/pretrained_models
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights
|
||||||
# inference
|
# inference
|
||||||
python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
|
python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
|
||||||
```
|
```
|
||||||
|
|
||||||
Results are in the `results` folder
|
Results are in the `results` folder
|
||||||
|
|
||||||
### Usage of python script
|
---
|
||||||
|
|
||||||
1. You can use X4 model for **arbitrary output size** with the argument `outscale`. The program will further perform cheap resize operation after the Real-ESRGAN output.
|
|
||||||
|
|
||||||
```console
|
|
||||||
Usage: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]...
|
|
||||||
|
|
||||||
A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile --outscale 3.5 --half --face_enhance
|
|
||||||
|
|
||||||
-h show this help
|
|
||||||
-i --input Input image or folder. Default: inputs
|
|
||||||
-o --output Output folder. Default: results
|
|
||||||
-n --model_name Model name. Default: RealESRGAN_x4plus
|
|
||||||
-s, --outscale The final upsampling scale of the image. Default: 4
|
|
||||||
--suffix Suffix of the restored image. Default: out
|
|
||||||
-t, --tile Tile size, 0 for no tile during testing. Default: 0
|
|
||||||
--face_enhance Whether to use GFPGAN to enhance face. Default: False
|
|
||||||
--half Whether to use half precision during inference. Default: False
|
|
||||||
--ext Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## :european_castle: Model Zoo
|
|
||||||
|
|
||||||
Please see [docs/model_zoo.md](docs/model_zoo.md)
|
|
||||||
|
|
||||||
## :computer: Training and Finetuning on your own dataset
|
|
||||||
|
|
||||||
A detailed guide can be found in [Training.md](Training.md).
|
|
||||||
|
|
||||||
## BibTeX
|
## BibTeX
|
||||||
|
|
||||||
@@ -231,14 +239,34 @@ A detailed guide can be found in [Training.md](Training.md).
|
|||||||
date = {2021}
|
date = {2021}
|
||||||
}
|
}
|
||||||
|
|
||||||
## :e-mail: Contact
|
## 📧 Contact
|
||||||
|
|
||||||
If you have any question, please email `xintao.wang@outlook.com` or `xintaowang@tencent.com`.
|
If you have any question, please email `xintao.wang@outlook.com` or `xintaowang@tencent.com`.
|
||||||
|
|
||||||
## :hugs: Acknowledgement
|
<!---------------------------------- Projects that use Real-ESRGAN --------------------------->
|
||||||
|
## 🧩 Projects that use Real-ESRGAN
|
||||||
|
|
||||||
|
If you develop/use Real-ESRGAN in your projects, welcome to let me know.
|
||||||
|
|
||||||
|
- NCNN-Android: [RealSR-NCNN-Android](https://github.com/tumuyan/RealSR-NCNN-Android) by [tumuyan](https://github.com/tumuyan)
|
||||||
|
- VapourSynth: [vs-realesrgan](https://github.com/HolyWu/vs-realesrgan) by [HolyWu](https://github.com/HolyWu)
|
||||||
|
- NCNN: [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan)
|
||||||
|
|
||||||
|
**GUI**
|
||||||
|
|
||||||
|
- [Waifu2x-Extension-GUI](https://github.com/AaronFeng753/Waifu2x-Extension-GUI) by [AaronFeng753](https://github.com/AaronFeng753)
|
||||||
|
- [Squirrel-RIFE](https://github.com/Justin62628/Squirrel-RIFE) by [Justin62628](https://github.com/Justin62628)
|
||||||
|
- [Real-GUI](https://github.com/scifx/Real-GUI) by [scifx](https://github.com/scifx)
|
||||||
|
- [Real-ESRGAN_GUI](https://github.com/net2cn/Real-ESRGAN_GUI) by [net2cn](https://github.com/net2cn)
|
||||||
|
- [Real-ESRGAN-EGUI](https://github.com/WGzeyu/Real-ESRGAN-EGUI) by [WGzeyu](https://github.com/WGzeyu)
|
||||||
|
- [anime_upscaler](https://github.com/shangar21/anime_upscaler) by [shangar21](https://github.com/shangar21)
|
||||||
|
- [Upscayl](https://github.com/upscayl/upscayl) by [Nayam Amarshe](https://github.com/NayamAmarshe) and [TGS963](https://github.com/TGS963)
|
||||||
|
|
||||||
|
## 🤗 Acknowledgement
|
||||||
|
|
||||||
Thanks for all the contributors.
|
Thanks for all the contributors.
|
||||||
|
|
||||||
- [AK391](https://github.com/AK391): Integrate RealESRGAN to [Huggingface Spaces](https://huggingface.co/spaces) with [Gradio](https://github.com/gradio-app/gradio). See [Gradio Web Demo](https://huggingface.co/spaces/akhaliq/Real-ESRGAN).
|
- [AK391](https://github.com/AK391): Integrate RealESRGAN to [Huggingface Spaces](https://huggingface.co/spaces) with [Gradio](https://github.com/gradio-app/gradio). See [Gradio Web Demo](https://huggingface.co/spaces/akhaliq/Real-ESRGAN).
|
||||||
- [Asiimoviet](https://github.com/Asiimoviet): Translate the README.md to Chinese (中文).
|
- [Asiimoviet](https://github.com/Asiimoviet): Translate the README.md to Chinese (中文).
|
||||||
- [2ji3150](https://github.com/2ji3150): Thanks for the [detailed and valuable feedbacks/suggestions](https://github.com/xinntao/Real-ESRGAN/issues/131).
|
- [2ji3150](https://github.com/2ji3150): Thanks for the [detailed and valuable feedbacks/suggestions](https://github.com/xinntao/Real-ESRGAN/issues/131).
|
||||||
|
- [Jared-02](https://github.com/Jared-02): Translate the Training.md to Chinese (中文).
|
||||||
|
|||||||
109
README_CN.md
@@ -1,4 +1,8 @@
|
|||||||
# Real-ESRGAN
|
<p align="center">
|
||||||
|
<img src="assets/realesrgan_logo.png" height=120>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## <div align="center"><b><a href="README.md">English</a> | <a href="README_CN.md">简体中文</a></b></div>
|
||||||
|
|
||||||
[](https://github.com/xinntao/Real-ESRGAN/releases)
|
[](https://github.com/xinntao/Real-ESRGAN/releases)
|
||||||
[](https://pypi.org/project/realesrgan/)
|
[](https://pypi.org/project/realesrgan/)
|
||||||
@@ -8,32 +12,19 @@
|
|||||||
[](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/pylint.yml)
|
[](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/pylint.yml)
|
||||||
[](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/publish-pip.yml)
|
[](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/publish-pip.yml)
|
||||||
|
|
||||||
[English](README.md) **|** [简体中文](README_CN.md)
|
:fire: 更新动漫视频的小模型 **RealESRGAN AnimeVideo-v3**. 更多信息在 [[动漫视频模型介绍](docs/anime_video_model.md)] 和 [[比较](docs/anime_comparisons_CN.md)] 中.
|
||||||
|
|
||||||
:fire: :fire: :fire: 添加了**针对动漫视频的小模型**, 更多信息在 [anime video models](docs/anime_video_model.md) 中.
|
1. Real-ESRGAN的[Colab Demo](https://colab.research.google.com/drive/1k2Zod6kSHEvraybHl50Lys0LerhyTMCo?usp=sharing) | Real-ESRGAN**动漫视频** 的[Colab Demo](https://colab.research.google.com/drive/1yNl9ORUxxlL4N0keJa2SEPB61imPQd1B?usp=sharing)
|
||||||
|
2. **支持Intel/AMD/Nvidia显卡**的绿色版exe文件: [Windows版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-windows.zip) / [Linux版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip) / [macOS版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-macos.zip),详情请移步[这里](#便携版(绿色版)可执行文件)。NCNN的实现在 [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan)。
|
||||||
|
|
||||||
1. Real-ESRGAN的[Colab Demo](https://colab.research.google.com/drive/1k2Zod6kSHEvraybHl50Lys0LerhyTMCo?usp=sharing) <a href="https://colab.research.google.com/drive/1k2Zod6kSHEvraybHl50Lys0LerhyTMCo?usp=sharing"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a>.
|
Real-ESRGAN 的目标是开发出**实用的图像/视频修复算法**。<br>
|
||||||
2. **支持Intel/AMD/Nvidia显卡**的绿色版exe文件: [Windows版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-windows.zip) / [Linux版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-ubuntu.zip) / [macOS版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-macos.zip),详情请移步[这里](#便携版(绿色版)可执行文件)。NCNN的实现在 [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan)。
|
|
||||||
|
|
||||||
Real-ESRGAN 的目标是开发出**实用的图像修复算法**。<br>
|
|
||||||
我们在 ESRGAN 的基础上使用纯合成的数据来进行训练,以使其能被应用于实际的图片修复的场景(顾名思义:Real-ESRGAN)。
|
我们在 ESRGAN 的基础上使用纯合成的数据来进行训练,以使其能被应用于实际的图片修复的场景(顾名思义:Real-ESRGAN)。
|
||||||
|
|
||||||
:art: Real-ESRGAN 需要,也很欢迎你的贡献,如新功能、模型、bug修复、建议、维护等等。详情可以查看[CONTRIBUTING.md](CONTRIBUTING.md),所有的贡献者都会被列在[此处](README_CN.md#hugs-感谢)。
|
:art: Real-ESRGAN 需要,也很欢迎你的贡献,如新功能、模型、bug修复、建议、维护等等。详情可以查看[CONTRIBUTING.md](docs/CONTRIBUTING.md),所有的贡献者都会被列在[此处](README_CN.md#hugs-感谢)。
|
||||||
|
|
||||||
:milky_way: 感谢大家提供了很好的反馈。这些反馈会逐步更新在 [这个文档](feedback.md)。
|
:milky_way: 感谢大家提供了很好的反馈。这些反馈会逐步更新在 [这个文档](docs/feedback.md)。
|
||||||
|
|
||||||
:question: 常见的问题可以在[FAQ.md](FAQ.md)中找到答案。(好吧,现在还是空白的=-=||)
|
:question: 常见的问题可以在[FAQ.md](docs/FAQ.md)中找到答案。(好吧,现在还是空白的=-=||)
|
||||||
|
|
||||||
:triangular_flag_on_post: **更新**
|
|
||||||
- :white_check_mark: 添加了针对动漫视频的小模型, 更多信息在 [anime video models](docs/anime_video_model.md) 中.
|
|
||||||
- :white_check_mark: 添加了ncnn 实现:[Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan).
|
|
||||||
- :white_check_mark: 添加了 [*RealESRGAN_x4plus_anime_6B.pth*](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth),对二次元图片进行了优化,并减少了model的大小。详情 以及 与[waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan)的对比请查看[**anime_model.md**](docs/anime_model.md)
|
|
||||||
- :white_check_mark: 支持用户在自己的数据上进行微调 (finetune):[详情](Training.md#Finetune-Real-ESRGAN-on-your-own-dataset)
|
|
||||||
- :white_check_mark: 支持使用[GFPGAN](https://github.com/TencentARC/GFPGAN)**增强人脸**
|
|
||||||
- :white_check_mark: 通过[Gradio](https://github.com/gradio-app/gradio)添加到了[Huggingface Spaces](https://huggingface.co/spaces)(一个机器学习应用的在线平台):[Gradio在线版](https://huggingface.co/spaces/akhaliq/Real-ESRGAN)。感谢[@AK391](https://github.com/AK391)
|
|
||||||
- :white_check_mark: 支持任意比例的缩放:`--outscale`(实际上使用`LANCZOS4`来更进一步调整输出图像的尺寸)。添加了*RealESRGAN_x2plus.pth*模型
|
|
||||||
- :white_check_mark: [推断脚本](inference_realesrgan.py)支持: 1) 分块处理**tile**; 2) 带**alpha通道**的图像; 3) **灰色**图像; 4) **16-bit**图像.
|
|
||||||
- :white_check_mark: 训练代码已经发布,具体做法可查看:[Training.md](Training.md)。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -46,6 +37,52 @@ Real-ESRGAN 的目标是开发出**实用的图像修复算法**。<br>
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<!---------------------------------- Updates --------------------------->
|
||||||
|
<details>
|
||||||
|
<summary>🚩<b>更新</b></summary>
|
||||||
|
|
||||||
|
- ✅ 更新动漫视频的小模型 **RealESRGAN AnimeVideo-v3**. 更多信息在 [anime video models](docs/anime_video_model.md) 和 [comparisons](docs/anime_comparisons.md)中.
|
||||||
|
- ✅ 添加了针对动漫视频的小模型, 更多信息在 [anime video models](docs/anime_video_model.md) 中.
|
||||||
|
- ✅ 添加了ncnn 实现:[Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan).
|
||||||
|
- ✅ 添加了 [*RealESRGAN_x4plus_anime_6B.pth*](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth),对二次元图片进行了优化,并减少了model的大小。详情 以及 与[waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan)的对比请查看[**anime_model.md**](docs/anime_model.md)
|
||||||
|
- ✅支持用户在自己的数据上进行微调 (finetune):[详情](docs/Training.md#Finetune-Real-ESRGAN-on-your-own-dataset)
|
||||||
|
- ✅ 支持使用[GFPGAN](https://github.com/TencentARC/GFPGAN)**增强人脸**
|
||||||
|
- ✅ 通过[Gradio](https://github.com/gradio-app/gradio)添加到了[Huggingface Spaces](https://huggingface.co/spaces)(一个机器学习应用的在线平台):[Gradio在线版](https://huggingface.co/spaces/akhaliq/Real-ESRGAN)。感谢[@AK391](https://github.com/AK391)
|
||||||
|
- ✅ 支持任意比例的缩放:`--outscale`(实际上使用`LANCZOS4`来更进一步调整输出图像的尺寸)。添加了*RealESRGAN_x2plus.pth*模型
|
||||||
|
- ✅ [推断脚本](inference_realesrgan.py)支持: 1) 分块处理**tile**; 2) 带**alpha通道**的图像; 3) **灰色**图像; 4) **16-bit**图像.
|
||||||
|
- ✅ 训练代码已经发布,具体做法可查看:[Training.md](docs/Training.md)。
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<!---------------------------------- Projects that use Real-ESRGAN --------------------------->
|
||||||
|
<details>
|
||||||
|
<summary>🧩<b>使用Real-ESRGAN的项目</b></summary>
|
||||||
|
|
||||||
|
👋 如果你开发/使用/集成了Real-ESRGAN, 欢迎联系我添加
|
||||||
|
|
||||||
|
- NCNN-Android: [RealSR-NCNN-Android](https://github.com/tumuyan/RealSR-NCNN-Android) by [tumuyan](https://github.com/tumuyan)
|
||||||
|
- VapourSynth: [vs-realesrgan](https://github.com/HolyWu/vs-realesrgan) by [HolyWu](https://github.com/HolyWu)
|
||||||
|
- NCNN: [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan)
|
||||||
|
|
||||||
|
**易用的图形界面**
|
||||||
|
|
||||||
|
- [Waifu2x-Extension-GUI](https://github.com/AaronFeng753/Waifu2x-Extension-GUI) by [AaronFeng753](https://github.com/AaronFeng753)
|
||||||
|
- [Squirrel-RIFE](https://github.com/Justin62628/Squirrel-RIFE) by [Justin62628](https://github.com/Justin62628)
|
||||||
|
- [Real-GUI](https://github.com/scifx/Real-GUI) by [scifx](https://github.com/scifx)
|
||||||
|
- [Real-ESRGAN_GUI](https://github.com/net2cn/Real-ESRGAN_GUI) by [net2cn](https://github.com/net2cn)
|
||||||
|
- [Real-ESRGAN-EGUI](https://github.com/WGzeyu/Real-ESRGAN-EGUI) by [WGzeyu](https://github.com/WGzeyu)
|
||||||
|
- [anime_upscaler](https://github.com/shangar21/anime_upscaler) by [shangar21](https://github.com/shangar21)
|
||||||
|
- [RealESRGAN-GUI](https://github.com/Baiyuetribe/paper2gui/blob/main/Video%20Super%20Resolution/RealESRGAN-GUI.md) by [Baiyuetribe](https://github.com/Baiyuetribe)
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>👀<b>Demo视频(B站)</b></summary>
|
||||||
|
|
||||||
|
- [大闹天宫片段](https://www.bilibili.com/video/BV1ja41117zb)
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
### :book: Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data
|
### :book: Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data
|
||||||
|
|
||||||
> [[论文](https://arxiv.org/abs/2107.10833)]   [项目主页]   [[YouTube 视频](https://www.youtube.com/watch?v=fxHWoDSSvSc)]   [[B站视频](https://www.bilibili.com/video/BV1H34y1m7sS/)]   [[Poster](https://xinntao.github.io/projects/RealESRGAN_src/RealESRGAN_poster.pdf)]   [[PPT](https://docs.google.com/presentation/d/1QtW6Iy8rm8rGLsJ0Ldti6kP-7Qyzy6XL/edit?usp=sharing&ouid=109799856763657548160&rtpof=true&sd=true)]<br>
|
> [[论文](https://arxiv.org/abs/2107.10833)]   [项目主页]   [[YouTube 视频](https://www.youtube.com/watch?v=fxHWoDSSvSc)]   [[B站视频](https://www.bilibili.com/video/BV1H34y1m7sS/)]   [[Poster](https://xinntao.github.io/projects/RealESRGAN_src/RealESRGAN_poster.pdf)]   [[PPT](https://docs.google.com/presentation/d/1QtW6Iy8rm8rGLsJ0Ldti6kP-7Qyzy6XL/edit?usp=sharing&ouid=109799856763657548160&rtpof=true&sd=true)]<br>
|
||||||
@@ -79,7 +116,7 @@ Real-ESRGAN 将会被长期支持,我会在空闲的时间中持续维护更
|
|||||||
|
|
||||||
### 便携版(绿色版)可执行文件
|
### 便携版(绿色版)可执行文件
|
||||||
|
|
||||||
你可以下载**支持Intel/AMD/Nvidia显卡**的绿色版exe文件: [Windows版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-windows.zip) / [Linux版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-ubuntu.zip) / [macOS版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-macos.zip)。
|
你可以下载**支持Intel/AMD/Nvidia显卡**的绿色版exe文件: [Windows版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-windows.zip) / [Linux版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip) / [macOS版](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-macos.zip)。
|
||||||
|
|
||||||
绿色版指的是这些exe你可以直接运行(放U盘里拷走都没问题),因为里面已经有所需的文件和模型了。它不需要 CUDA 或者 PyTorch运行环境。<br>
|
绿色版指的是这些exe你可以直接运行(放U盘里拷走都没问题),因为里面已经有所需的文件和模型了。它不需要 CUDA 或者 PyTorch运行环境。<br>
|
||||||
|
|
||||||
@@ -94,8 +131,7 @@ Real-ESRGAN 将会被长期支持,我会在空闲的时间中持续维护更
|
|||||||
1. realesrgan-x4plus(默认)
|
1. realesrgan-x4plus(默认)
|
||||||
2. reaesrnet-x4plus
|
2. reaesrnet-x4plus
|
||||||
3. realesrgan-x4plus-anime(针对动漫插画图像优化,有更小的体积)
|
3. realesrgan-x4plus-anime(针对动漫插画图像优化,有更小的体积)
|
||||||
4. RealESRGANv2-animevideo-xsx2 (针对动漫视频, X2)
|
4. realesr-animevideov3 (针对动漫视频)
|
||||||
5. RealESRGANv2-animevideo-xsx4 (针对动漫视频, X4)
|
|
||||||
|
|
||||||
你可以通过`-n`参数来使用其他模型,例如`./realesrgan-ncnn-vulkan.exe -i 二次元图片.jpg -o 二刺螈图片.png -n realesrgan-x4plus-anime`
|
你可以通过`-n`参数来使用其他模型,例如`./realesrgan-ncnn-vulkan.exe -i 二次元图片.jpg -o 二刺螈图片.png -n realesrgan-x4plus-anime`
|
||||||
|
|
||||||
@@ -108,23 +144,21 @@ Real-ESRGAN 将会被长期支持,我会在空闲的时间中持续维护更
|
|||||||
Usage: realesrgan-ncnn-vulkan.exe -i infile -o outfile [options]...
|
Usage: realesrgan-ncnn-vulkan.exe -i infile -o outfile [options]...
|
||||||
|
|
||||||
-h show this help
|
-h show this help
|
||||||
-v verbose output
|
|
||||||
-i input-path input image path (jpg/png/webp) or directory
|
-i input-path input image path (jpg/png/webp) or directory
|
||||||
-o output-path output image path (jpg/png/webp) or directory
|
-o output-path output image path (jpg/png/webp) or directory
|
||||||
-s scale upscale ratio (4, default=4)
|
-s scale upscale ratio (can be 2, 3, 4. default=4)
|
||||||
-t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu
|
-t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu
|
||||||
-m model-path folder path to pre-trained models(default=models)
|
-m model-path folder path to the pre-trained models. default=models
|
||||||
-n model-name model name (default=realesrgan-x4plus, can be realesrgan-x4plus | realesrgan-x4plus-anime | realesrnet-x4plus)
|
-n model-name model name (default=realesr-animevideov3, can be realesr-animevideov3 | realesrgan-x4plus | realesrgan-x4plus-anime | realesrnet-x4plus)
|
||||||
-g gpu-id gpu device to use (default=0) can be 0,1,2 for multi-gpu
|
-g gpu-id gpu device to use (default=auto) can be 0,1,2 for multi-gpu
|
||||||
-j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu
|
-j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu
|
||||||
-x enable tta mode
|
-x enable tta mode"
|
||||||
-f format output image format (jpg/png/webp, default=ext/png)
|
-f format output image format (jpg/png/webp, default=ext/png)
|
||||||
|
-v verbose output
|
||||||
```
|
```
|
||||||
|
|
||||||
由于这些exe文件会把图像分成几个板块,然后来分别进行处理,再合成导出,输出的图像可能会有一点割裂感(而且可能跟PyTorch的输出不太一样)
|
由于这些exe文件会把图像分成几个板块,然后来分别进行处理,再合成导出,输出的图像可能会有一点割裂感(而且可能跟PyTorch的输出不太一样)
|
||||||
|
|
||||||
这些exe文件均基于[Tencent/ncnn](https://github.com/Tencent/ncnn)以及[nihui](https://github.com/nihui)的[realsr-ncnn-vulkan](https://github.com/nihui/realsr-ncnn-vulkan),感谢!
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## :wrench: 依赖以及安装
|
## :wrench: 依赖以及安装
|
||||||
@@ -161,7 +195,7 @@ Usage: realesrgan-ncnn-vulkan.exe -i infile -o outfile [options]...
|
|||||||
下载我们训练好的模型: [RealESRGAN_x4plus.pth](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth)
|
下载我们训练好的模型: [RealESRGAN_x4plus.pth](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P weights
|
||||||
```
|
```
|
||||||
|
|
||||||
推断!
|
推断!
|
||||||
@@ -183,7 +217,7 @@ python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 下载模型
|
# 下载模型
|
||||||
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P experiments/pretrained_models
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights
|
||||||
# 推断
|
# 推断
|
||||||
python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
|
python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
|
||||||
```
|
```
|
||||||
@@ -197,7 +231,7 @@ python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
|
|||||||
```console
|
```console
|
||||||
Usage: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]...
|
Usage: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]...
|
||||||
|
|
||||||
A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile --outscale 3.5 --half --face_enhance
|
A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile --outscale 3.5 --face_enhance
|
||||||
|
|
||||||
-h show this help
|
-h show this help
|
||||||
-i --input Input image or folder. Default: inputs
|
-i --input Input image or folder. Default: inputs
|
||||||
@@ -207,7 +241,7 @@ A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile
|
|||||||
--suffix Suffix of the restored image. Default: out
|
--suffix Suffix of the restored image. Default: out
|
||||||
-t, --tile Tile size, 0 for no tile during testing. Default: 0
|
-t, --tile Tile size, 0 for no tile during testing. Default: 0
|
||||||
--face_enhance Whether to use GFPGAN to enhance face. Default: False
|
--face_enhance Whether to use GFPGAN to enhance face. Default: False
|
||||||
--half Whether to use half precision during inference. Default: False
|
--fp32 Whether to use half precision during inference. Default: False
|
||||||
--ext Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto
|
--ext Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -217,7 +251,7 @@ A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile
|
|||||||
|
|
||||||
## :computer: 训练,在你的数据上微调(Fine-tune)
|
## :computer: 训练,在你的数据上微调(Fine-tune)
|
||||||
|
|
||||||
这里有一份详细的指南:[Training.md](Training.md).
|
这里有一份详细的指南:[Training.md](docs/Training.md).
|
||||||
|
|
||||||
## BibTeX 引用
|
## BibTeX 引用
|
||||||
|
|
||||||
@@ -239,3 +273,4 @@ A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile
|
|||||||
- [AK391](https://github.com/AK391): 通过[Gradio](https://github.com/gradio-app/gradio)添加到了[Huggingface Spaces](https://huggingface.co/spaces)(一个机器学习应用的在线平台):[Gradio在线版](https://huggingface.co/spaces/akhaliq/Real-ESRGAN)。
|
- [AK391](https://github.com/AK391): 通过[Gradio](https://github.com/gradio-app/gradio)添加到了[Huggingface Spaces](https://huggingface.co/spaces)(一个机器学习应用的在线平台):[Gradio在线版](https://huggingface.co/spaces/akhaliq/Real-ESRGAN)。
|
||||||
- [Asiimoviet](https://github.com/Asiimoviet): 把 README.md 文档 翻译成了中文。
|
- [Asiimoviet](https://github.com/Asiimoviet): 把 README.md 文档 翻译成了中文。
|
||||||
- [2ji3150](https://github.com/2ji3150): 感谢详尽并且富有价值的[反馈、建议](https://github.com/xinntao/Real-ESRGAN/issues/131).
|
- [2ji3150](https://github.com/2ji3150): 感谢详尽并且富有价值的[反馈、建议](https://github.com/xinntao/Real-ESRGAN/issues/131).
|
||||||
|
- [Jared-02](https://github.com/Jared-02): 把 Training.md 文档 翻译成了中文。
|
||||||
|
|||||||
BIN
assets/realesrgan_logo.png
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
assets/realesrgan_logo_ai.png
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
assets/realesrgan_logo_av.png
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
assets/realesrgan_logo_gi.png
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
assets/realesrgan_logo_gv.png
Normal file
|
After Width: | Height: | Size: 81 KiB |
22
cog.yaml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# This file is used for constructing replicate env
|
||||||
|
image: "r8.im/tencentarc/realesrgan"
|
||||||
|
|
||||||
|
build:
|
||||||
|
gpu: true
|
||||||
|
python_version: "3.8"
|
||||||
|
system_packages:
|
||||||
|
- "libgl1-mesa-glx"
|
||||||
|
- "libglib2.0-0"
|
||||||
|
python_packages:
|
||||||
|
- "torch==1.7.1"
|
||||||
|
- "torchvision==0.8.2"
|
||||||
|
- "numpy==1.21.1"
|
||||||
|
- "lmdb==1.2.1"
|
||||||
|
- "opencv-python==4.5.3.56"
|
||||||
|
- "PyYAML==5.4.1"
|
||||||
|
- "tqdm==4.62.2"
|
||||||
|
- "yapf==0.31.0"
|
||||||
|
- "basicsr==1.4.2"
|
||||||
|
- "facexlib==0.2.5"
|
||||||
|
|
||||||
|
predict: "cog_predict.py:Predictor"
|
||||||
148
cog_predict.py
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
# flake8: noqa
|
||||||
|
# This file is used for deploying replicate models
|
||||||
|
# running: cog predict -i img=@inputs/00017_gray.png -i version='General - v3' -i scale=2 -i face_enhance=True -i tile=0
|
||||||
|
# push: cog push r8.im/xinntao/realesrgan
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
os.system('pip install gfpgan')
|
||||||
|
os.system('python setup.py develop')
|
||||||
|
|
||||||
|
import cv2
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
import torch
|
||||||
|
from basicsr.archs.rrdbnet_arch import RRDBNet
|
||||||
|
from basicsr.archs.srvgg_arch import SRVGGNetCompact
|
||||||
|
|
||||||
|
from realesrgan.utils import RealESRGANer
|
||||||
|
|
||||||
|
try:
|
||||||
|
from cog import BasePredictor, Input, Path
|
||||||
|
from gfpgan import GFPGANer
|
||||||
|
except Exception:
|
||||||
|
print('please install cog and realesrgan package')
|
||||||
|
|
||||||
|
|
||||||
|
class Predictor(BasePredictor):
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
os.makedirs('output', exist_ok=True)
|
||||||
|
# download weights
|
||||||
|
if not os.path.exists('weights/realesr-general-x4v3.pth'):
|
||||||
|
os.system(
|
||||||
|
'wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth -P ./weights'
|
||||||
|
)
|
||||||
|
if not os.path.exists('weights/GFPGANv1.4.pth'):
|
||||||
|
os.system('wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth -P ./weights')
|
||||||
|
if not os.path.exists('weights/RealESRGAN_x4plus.pth'):
|
||||||
|
os.system(
|
||||||
|
'wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P ./weights'
|
||||||
|
)
|
||||||
|
if not os.path.exists('weights/RealESRGAN_x4plus_anime_6B.pth'):
|
||||||
|
os.system(
|
||||||
|
'wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P ./weights'
|
||||||
|
)
|
||||||
|
if not os.path.exists('weights/realesr-animevideov3.pth'):
|
||||||
|
os.system(
|
||||||
|
'wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth -P ./weights'
|
||||||
|
)
|
||||||
|
|
||||||
|
def choose_model(self, scale, version, tile=0):
|
||||||
|
half = True if torch.cuda.is_available() else False
|
||||||
|
if version == 'General - RealESRGANplus':
|
||||||
|
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
||||||
|
model_path = 'weights/RealESRGAN_x4plus.pth'
|
||||||
|
self.upsampler = RealESRGANer(
|
||||||
|
scale=4, model_path=model_path, model=model, tile=tile, tile_pad=10, pre_pad=0, half=half)
|
||||||
|
elif version == 'General - v3':
|
||||||
|
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
||||||
|
model_path = 'weights/realesr-general-x4v3.pth'
|
||||||
|
self.upsampler = RealESRGANer(
|
||||||
|
scale=4, model_path=model_path, model=model, tile=tile, tile_pad=10, pre_pad=0, half=half)
|
||||||
|
elif version == 'Anime - anime6B':
|
||||||
|
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4)
|
||||||
|
model_path = 'weights/RealESRGAN_x4plus_anime_6B.pth'
|
||||||
|
self.upsampler = RealESRGANer(
|
||||||
|
scale=4, model_path=model_path, model=model, tile=tile, tile_pad=10, pre_pad=0, half=half)
|
||||||
|
elif version == 'AnimeVideo - v3':
|
||||||
|
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu')
|
||||||
|
model_path = 'weights/realesr-animevideov3.pth'
|
||||||
|
self.upsampler = RealESRGANer(
|
||||||
|
scale=4, model_path=model_path, model=model, tile=tile, tile_pad=10, pre_pad=0, half=half)
|
||||||
|
|
||||||
|
self.face_enhancer = GFPGANer(
|
||||||
|
model_path='weights/GFPGANv1.4.pth',
|
||||||
|
upscale=scale,
|
||||||
|
arch='clean',
|
||||||
|
channel_multiplier=2,
|
||||||
|
bg_upsampler=self.upsampler)
|
||||||
|
|
||||||
|
def predict(
|
||||||
|
self,
|
||||||
|
img: Path = Input(description='Input'),
|
||||||
|
version: str = Input(
|
||||||
|
description='RealESRGAN version. Please see [Readme] below for more descriptions',
|
||||||
|
choices=['General - RealESRGANplus', 'General - v3', 'Anime - anime6B', 'AnimeVideo - v3'],
|
||||||
|
default='General - v3'),
|
||||||
|
scale: float = Input(description='Rescaling factor', default=2),
|
||||||
|
face_enhance: bool = Input(
|
||||||
|
description='Enhance faces with GFPGAN. Note that it does not work for anime images/vidoes', default=False),
|
||||||
|
tile: int = Input(
|
||||||
|
description=
|
||||||
|
'Tile size. Default is 0, that is no tile. When encountering the out-of-GPU-memory issue, please specify it, e.g., 400 or 200',
|
||||||
|
default=0)
|
||||||
|
) -> Path:
|
||||||
|
if tile <= 100 or tile is None:
|
||||||
|
tile = 0
|
||||||
|
print(f'img: {img}. version: {version}. scale: {scale}. face_enhance: {face_enhance}. tile: {tile}.')
|
||||||
|
try:
|
||||||
|
extension = os.path.splitext(os.path.basename(str(img)))[1]
|
||||||
|
img = cv2.imread(str(img), cv2.IMREAD_UNCHANGED)
|
||||||
|
if len(img.shape) == 3 and img.shape[2] == 4:
|
||||||
|
img_mode = 'RGBA'
|
||||||
|
elif len(img.shape) == 2:
|
||||||
|
img_mode = None
|
||||||
|
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
|
||||||
|
else:
|
||||||
|
img_mode = None
|
||||||
|
|
||||||
|
h, w = img.shape[0:2]
|
||||||
|
if h < 300:
|
||||||
|
img = cv2.resize(img, (w * 2, h * 2), interpolation=cv2.INTER_LANCZOS4)
|
||||||
|
|
||||||
|
self.choose_model(scale, version, tile)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if face_enhance:
|
||||||
|
_, _, output = self.face_enhancer.enhance(
|
||||||
|
img, has_aligned=False, only_center_face=False, paste_back=True)
|
||||||
|
else:
|
||||||
|
output, _ = self.upsampler.enhance(img, outscale=scale)
|
||||||
|
except RuntimeError as error:
|
||||||
|
print('Error', error)
|
||||||
|
print('If you encounter CUDA out of memory, try to set "tile" to a smaller size, e.g., 400.')
|
||||||
|
|
||||||
|
if img_mode == 'RGBA': # RGBA images should be saved in png format
|
||||||
|
extension = 'png'
|
||||||
|
# save_path = f'output/out.{extension}'
|
||||||
|
# cv2.imwrite(save_path, output)
|
||||||
|
out_path = Path(tempfile.mkdtemp()) / f'out.{extension}'
|
||||||
|
cv2.imwrite(str(out_path), output)
|
||||||
|
except Exception as error:
|
||||||
|
print('global exception: ', error)
|
||||||
|
finally:
|
||||||
|
clean_folder('output')
|
||||||
|
return out_path
|
||||||
|
|
||||||
|
|
||||||
|
def clean_folder(folder):
|
||||||
|
for filename in os.listdir(folder):
|
||||||
|
file_path = os.path.join(folder, filename)
|
||||||
|
try:
|
||||||
|
if os.path.isfile(file_path) or os.path.islink(file_path):
|
||||||
|
os.unlink(file_path)
|
||||||
|
elif os.path.isdir(file_path):
|
||||||
|
shutil.rmtree(file_path)
|
||||||
|
except Exception as e:
|
||||||
|
print(f'Failed to delete {file_path}. Reason: {e}')
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
# Contributing to Real-ESRGAN
|
# Contributing to Real-ESRGAN
|
||||||
|
|
||||||
|
:art: Real-ESRGAN needs your contributions. Any contributions are welcome, such as new features/models/typo fixes/suggestions/maintenance, *etc*. See [CONTRIBUTING.md](docs/CONTRIBUTING.md). All contributors are list [here](README.md#hugs-acknowledgement).
|
||||||
|
|
||||||
We like open-source and want to develop practical algorithms for general image restoration. However, individual strength is limited. So, any kinds of contributions are welcome, such as:
|
We like open-source and want to develop practical algorithms for general image restoration. However, individual strength is limited. So, any kinds of contributions are welcome, such as:
|
||||||
|
|
||||||
- New features
|
- New features
|
||||||
@@ -19,6 +21,7 @@ We like open-source and want to develop practical algorithms for general image r
|
|||||||
1. Create a PR
|
1. Create a PR
|
||||||
|
|
||||||
**Note**:
|
**Note**:
|
||||||
|
|
||||||
1. Please check the code style and linting
|
1. Please check the code style and linting
|
||||||
1. The style configuration is specified in [setup.cfg](setup.cfg)
|
1. The style configuration is specified in [setup.cfg](setup.cfg)
|
||||||
1. If you use VSCode, the settings are configured in [.vscode/settings.json](.vscode/settings.json)
|
1. If you use VSCode, the settings are configured in [.vscode/settings.json](.vscode/settings.json)
|
||||||
10
docs/FAQ.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# FAQ
|
||||||
|
|
||||||
|
1. **Q: How to select models?**<br>
|
||||||
|
A: Please refer to [docs/model_zoo.md](docs/model_zoo.md)
|
||||||
|
|
||||||
|
1. **Q: Can `face_enhance` be used for anime images/animation videos?**<br>
|
||||||
|
A: No, it can only be used for real faces. It is recommended not to use this option for anime images/animation videos to save GPU memory.
|
||||||
|
|
||||||
|
1. **Q: Error "slow_conv2d_cpu" not implemented for 'Half'**<br>
|
||||||
|
A: In order to save GPU memory consumption and speed up inference, Real-ESRGAN uses half precision (fp16) during inference by default. However, some operators for half inference are not implemented in CPU mode. You need to add **`--fp32` option** for the commands. For example, `python inference_realesrgan.py -n RealESRGAN_x4plus.pth -i inputs --fp32`.
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
- [Generate degraded images on the fly](#Generate-degraded-images-on-the-fly)
|
- [Generate degraded images on the fly](#Generate-degraded-images-on-the-fly)
|
||||||
- [Use paired training data](#use-your-own-paired-data)
|
- [Use paired training data](#use-your-own-paired-data)
|
||||||
|
|
||||||
|
[English](Training.md) **|** [简体中文](Training_CN.md)
|
||||||
|
|
||||||
## Train Real-ESRGAN
|
## Train Real-ESRGAN
|
||||||
|
|
||||||
### Overview
|
### Overview
|
||||||
@@ -65,7 +67,7 @@ You can use the [scripts/generate_meta_info.py](scripts/generate_meta_info.py) s
|
|||||||
You can merge several folders into one meta_info txt. Here is the example:
|
You can merge several folders into one meta_info txt. Here is the example:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python scripts/generate_meta_info.py --input datasets/DF2K/DF2K_HR, datasets/DF2K/DF2K_multiscale --root datasets/DF2K, datasets/DF2K --meta_info datasets/DF2K/meta_info/meta_info_DF2Kmultiscale.txt
|
python scripts/generate_meta_info.py --input datasets/DF2K/DF2K_HR datasets/DF2K/DF2K_multiscale --root datasets/DF2K datasets/DF2K --meta_info datasets/DF2K/meta_info/meta_info_DF2Kmultiscale.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
### Train Real-ESRNet
|
### Train Real-ESRNet
|
||||||
@@ -164,7 +166,7 @@ You can finetune Real-ESRGAN on your own dataset. Typically, the fine-tuning pro
|
|||||||
|
|
||||||
### Generate degraded images on the fly
|
### Generate degraded images on the fly
|
||||||
|
|
||||||
Only high-resolution images are required. The low-quality images are generated with the degradation process described in Real-ESRGAN during trainig.
|
Only high-resolution images are required. The low-quality images are generated with the degradation process described in Real-ESRGAN during training.
|
||||||
|
|
||||||
**1. Prepare dataset**
|
**1. Prepare dataset**
|
||||||
|
|
||||||
@@ -251,7 +253,7 @@ train:
|
|||||||
type: RealESRGANPairedDataset
|
type: RealESRGANPairedDataset
|
||||||
dataroot_gt: datasets/DF2K # modify to the root path of your folder
|
dataroot_gt: datasets/DF2K # modify to the root path of your folder
|
||||||
dataroot_lq: datasets/DF2K # modify to the root path of your folder
|
dataroot_lq: datasets/DF2K # modify to the root path of your folder
|
||||||
meta_info: datasets/DF2K/meta_info/meta_info_DIV2K_sub_pair.txt # modify to the root path of your folder
|
meta_info: datasets/DF2K/meta_info/meta_info_DIV2K_sub_pair.txt # modify to your own generate meta info txt
|
||||||
io_backend:
|
io_backend:
|
||||||
type: disk
|
type: disk
|
||||||
```
|
```
|
||||||
271
docs/Training_CN.md
Normal file
@@ -0,0 +1,271 @@
|
|||||||
|
# :computer: 如何训练/微调 Real-ESRGAN
|
||||||
|
|
||||||
|
- [训练 Real-ESRGAN](#训练-real-esrgan)
|
||||||
|
- [概述](#概述)
|
||||||
|
- [准备数据集](#准备数据集)
|
||||||
|
- [训练 Real-ESRNet 模型](#训练-real-esrnet-模型)
|
||||||
|
- [训练 Real-ESRGAN 模型](#训练-real-esrgan-模型)
|
||||||
|
- [用自己的数据集微调 Real-ESRGAN](#用自己的数据集微调-real-esrgan)
|
||||||
|
- [动态生成降级图像](#动态生成降级图像)
|
||||||
|
- [使用已配对的数据](#使用已配对的数据)
|
||||||
|
|
||||||
|
[English](Training.md) **|** [简体中文](Training_CN.md)
|
||||||
|
|
||||||
|
## 训练 Real-ESRGAN
|
||||||
|
|
||||||
|
### 概述
|
||||||
|
|
||||||
|
训练分为两个步骤。除了 loss 函数外,这两个步骤拥有相同数据合成以及训练的一条龙流程。具体点说:
|
||||||
|
|
||||||
|
1. 首先使用 L1 loss 训练 Real-ESRNet 模型,其中 L1 loss 来自预先训练的 ESRGAN 模型。
|
||||||
|
|
||||||
|
2. 然后我们将 Real-ESRNet 模型作为生成器初始化,结合L1 loss、感知 loss、GAN loss 三者的参数对 Real-ESRGAN 进行训练。
|
||||||
|
|
||||||
|
### 准备数据集
|
||||||
|
|
||||||
|
我们使用 DF2K ( DIV2K 和 Flickr2K ) + OST 数据集进行训练。只需要HR图像!<br>
|
||||||
|
下面是网站链接:
|
||||||
|
1. DIV2K: http://data.vision.ee.ethz.ch/cvl/DIV2K/DIV2K_train_HR.zip
|
||||||
|
2. Flickr2K: https://cv.snu.ac.kr/research/EDSR/Flickr2K.tar
|
||||||
|
3. OST: https://openmmlab.oss-cn-hangzhou.aliyuncs.com/datasets/OST_dataset.zip
|
||||||
|
|
||||||
|
以下是数据的准备步骤。
|
||||||
|
|
||||||
|
#### 第1步:【可选】生成多尺寸图片
|
||||||
|
|
||||||
|
针对 DF2K 数据集,我们使用多尺寸缩放策略,*换言之*,我们对 HR 图像进行下采样,就能获得多尺寸的标准参考(Ground-Truth)图像。 <br>
|
||||||
|
您可以使用这个 [scripts/generate_multiscale_DF2K.py](scripts/generate_multiscale_DF2K.py) 脚本快速生成多尺寸的图像。<br>
|
||||||
|
注意:如果您只想简单试试,那么可以跳过此步骤。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python scripts/generate_multiscale_DF2K.py --input datasets/DF2K/DF2K_HR --output datasets/DF2K/DF2K_multiscale
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 第2步:【可选】裁切为子图像
|
||||||
|
|
||||||
|
我们可以将 DF2K 图像裁切为子图像,以加快 IO 和处理速度。<br>
|
||||||
|
如果你的 IO 够好或储存空间有限,那么此步骤是可选的。<br>
|
||||||
|
|
||||||
|
您可以使用脚本 [scripts/extract_subimages.py](scripts/extract_subimages.py)。这是使用示例:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python scripts/extract_subimages.py --input datasets/DF2K/DF2K_multiscale --output datasets/DF2K/DF2K_multiscale_sub --crop_size 400 --step 200
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 第3步:准备元信息 txt
|
||||||
|
|
||||||
|
您需要准备一个包含图像路径的 txt 文件。下面是 `meta_info_DF2Kmultiscale+OST_sub.txt` 中的部分展示(由于各个用户可能有截然不同的子图像划分,这个文件不适合你的需求,你得准备自己的 txt 文件):
|
||||||
|
|
||||||
|
```txt
|
||||||
|
DF2K_HR_sub/000001_s001.png
|
||||||
|
DF2K_HR_sub/000001_s002.png
|
||||||
|
DF2K_HR_sub/000001_s003.png
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
你可以使用该脚本 [scripts/generate_meta_info.py](scripts/generate_meta_info.py) 生成包含图像路径的 txt 文件。<br>
|
||||||
|
你还可以合并多个文件夹的图像路径到一个元信息(meta_info)txt。这是使用示例:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python scripts/generate_meta_info.py --input datasets/DF2K/DF2K_HR, datasets/DF2K/DF2K_multiscale --root datasets/DF2K, datasets/DF2K --meta_info datasets/DF2K/meta_info/meta_info_DF2Kmultiscale.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
### 训练 Real-ESRNet 模型
|
||||||
|
|
||||||
|
1. 下载预先训练的模型 [ESRGAN](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth),放到 `experiments/pretrained_models`目录下。
|
||||||
|
```bash
|
||||||
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth -P experiments/pretrained_models
|
||||||
|
```
|
||||||
|
2. 相应地修改选项文件 `options/train_realesrnet_x4plus.yml` 中的内容:
|
||||||
|
```yml
|
||||||
|
train:
|
||||||
|
name: DF2K+OST
|
||||||
|
type: RealESRGANDataset
|
||||||
|
dataroot_gt: datasets/DF2K # 修改为你的数据集文件夹根目录
|
||||||
|
meta_info: realesrgan/meta_info/meta_info_DF2Kmultiscale+OST_sub.txt # 修改为你自己生成的元信息txt
|
||||||
|
io_backend:
|
||||||
|
type: disk
|
||||||
|
```
|
||||||
|
3. 如果你想在训练过程中执行验证,就取消注释这些内容并进行相应的修改:
|
||||||
|
```yml
|
||||||
|
# 取消注释这些以进行验证
|
||||||
|
# val:
|
||||||
|
# name: validation
|
||||||
|
# type: PairedImageDataset
|
||||||
|
# dataroot_gt: path_to_gt
|
||||||
|
# dataroot_lq: path_to_lq
|
||||||
|
# io_backend:
|
||||||
|
# type: disk
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
# 取消注释这些以进行验证
|
||||||
|
# 验证设置
|
||||||
|
# val:
|
||||||
|
# val_freq: !!float 5e3
|
||||||
|
# save_img: True
|
||||||
|
|
||||||
|
# metrics:
|
||||||
|
# psnr: # 指标名称,可以是任意的
|
||||||
|
# type: calculate_psnr
|
||||||
|
# crop_border: 4
|
||||||
|
# test_y_channel: false
|
||||||
|
```
|
||||||
|
4. 正式训练之前,你可以用 `--debug` 模式检查是否正常运行。我们用了4个GPU进行训练:
|
||||||
|
```bash
|
||||||
|
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
||||||
|
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --launcher pytorch --debug
|
||||||
|
```
|
||||||
|
|
||||||
|
用 **1个GPU** 训练的 debug 模式示例:
|
||||||
|
```bash
|
||||||
|
python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --debug
|
||||||
|
```
|
||||||
|
5. 正式训练开始。我们用了4个GPU进行训练。还可以使用参数 `--auto_resume` 在必要时自动恢复训练。
|
||||||
|
```bash
|
||||||
|
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
||||||
|
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --launcher pytorch --auto_resume
|
||||||
|
```
|
||||||
|
|
||||||
|
用 **1个GPU** 训练:
|
||||||
|
```bash
|
||||||
|
python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --auto_resume
|
||||||
|
```
|
||||||
|
|
||||||
|
### 训练 Real-ESRGAN 模型
|
||||||
|
|
||||||
|
1. 训练 Real-ESRNet 模型后,您得到了这个 `experiments/train_RealESRNetx4plus_1000k_B12G4_fromESRGAN/model/net_g_1000000.pth` 文件。如果需要指定预训练路径到其他文件,请修改选项文件 `train_realesrgan_x4plus.yml` 中 `pretrain_network_g` 的值。
|
||||||
|
1. 修改选项文件 `train_realesrgan_x4plus.yml` 的内容。大多数修改与上节提到的类似。
|
||||||
|
1. 正式训练之前,你可以以 `--debug` 模式检查是否正常运行。我们使用了4个GPU进行训练:
|
||||||
|
```bash
|
||||||
|
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
||||||
|
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --launcher pytorch --debug
|
||||||
|
```
|
||||||
|
|
||||||
|
用 **1个GPU** 训练的 debug 模式示例:
|
||||||
|
```bash
|
||||||
|
python realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --debug
|
||||||
|
```
|
||||||
|
1. 正式训练开始。我们使用4个GPU进行训练。还可以使用参数 `--auto_resume` 在必要时自动恢复训练。
|
||||||
|
```bash
|
||||||
|
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
||||||
|
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --launcher pytorch --auto_resume
|
||||||
|
```
|
||||||
|
|
||||||
|
用 **1个GPU** 训练:
|
||||||
|
```bash
|
||||||
|
python realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --auto_resume
|
||||||
|
```
|
||||||
|
|
||||||
|
## 用自己的数据集微调 Real-ESRGAN
|
||||||
|
|
||||||
|
你可以用自己的数据集微调 Real-ESRGAN。一般地,微调(Fine-Tune)程序可以分为两种类型:
|
||||||
|
|
||||||
|
1. [动态生成降级图像](#动态生成降级图像)
|
||||||
|
2. [使用**已配对**的数据](#使用已配对的数据)
|
||||||
|
|
||||||
|
### 动态生成降级图像
|
||||||
|
|
||||||
|
只需要高分辨率图像。在训练过程中,使用 Real-ESRGAN 描述的降级模型生成低质量图像。
|
||||||
|
|
||||||
|
**1. 准备数据集**
|
||||||
|
|
||||||
|
完整信息请参见[本节](#准备数据集)。
|
||||||
|
|
||||||
|
**2. 下载预训练模型**
|
||||||
|
|
||||||
|
下载预先训练的模型到 `experiments/pretrained_models` 目录下。
|
||||||
|
|
||||||
|
- *RealESRGAN_x4plus.pth*:
|
||||||
|
```bash
|
||||||
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models
|
||||||
|
```
|
||||||
|
|
||||||
|
- *RealESRGAN_x4plus_netD.pth*:
|
||||||
|
```bash
|
||||||
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth -P experiments/pretrained_models
|
||||||
|
```
|
||||||
|
|
||||||
|
**3. 微调**
|
||||||
|
|
||||||
|
修改选项文件 [options/finetune_realesrgan_x4plus.yml](options/finetune_realesrgan_x4plus.yml) ,特别是 `datasets` 部分:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
train:
|
||||||
|
name: DF2K+OST
|
||||||
|
type: RealESRGANDataset
|
||||||
|
dataroot_gt: datasets/DF2K # 修改为你的数据集文件夹根目录
|
||||||
|
meta_info: realesrgan/meta_info/meta_info_DF2Kmultiscale+OST_sub.txt # 修改为你自己生成的元信息txt
|
||||||
|
io_backend:
|
||||||
|
type: disk
|
||||||
|
```
|
||||||
|
|
||||||
|
我们使用4个GPU进行训练。还可以使用参数 `--auto_resume` 在必要时自动恢复训练。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
||||||
|
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/finetune_realesrgan_x4plus.yml --launcher pytorch --auto_resume
|
||||||
|
```
|
||||||
|
|
||||||
|
用 **1个GPU** 训练:
|
||||||
|
```bash
|
||||||
|
python realesrgan/train.py -opt options/finetune_realesrgan_x4plus.yml --auto_resume
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用已配对的数据
|
||||||
|
|
||||||
|
你还可以用自己已经配对的数据微调 RealESRGAN。这个过程更类似于微调 ESRGAN。
|
||||||
|
|
||||||
|
**1. 准备数据集**
|
||||||
|
|
||||||
|
假设你已经有两个文件夹(folder):
|
||||||
|
|
||||||
|
- **gt folder**(标准参考,高分辨率图像):*datasets/DF2K/DIV2K_train_HR_sub*
|
||||||
|
- **lq folder**(低质量,低分辨率图像):*datasets/DF2K/DIV2K_train_LR_bicubic_X4_sub*
|
||||||
|
|
||||||
|
然后,您可以使用脚本 [scripts/generate_meta_info_pairdata.py](scripts/generate_meta_info_pairdata.py) 生成元信息(meta_info)txt 文件。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python scripts/generate_meta_info_pairdata.py --input datasets/DF2K/DIV2K_train_HR_sub datasets/DF2K/DIV2K_train_LR_bicubic_X4_sub --meta_info datasets/DF2K/meta_info/meta_info_DIV2K_sub_pair.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. 下载预训练模型**
|
||||||
|
|
||||||
|
下载预先训练的模型到 `experiments/pretrained_models` 目录下。
|
||||||
|
|
||||||
|
- *RealESRGAN_x4plus.pth*:
|
||||||
|
```bash
|
||||||
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models
|
||||||
|
```
|
||||||
|
|
||||||
|
- *RealESRGAN_x4plus_netD.pth*:
|
||||||
|
```bash
|
||||||
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth -P experiments/pretrained_models
|
||||||
|
```
|
||||||
|
|
||||||
|
**3. 微调**
|
||||||
|
|
||||||
|
修改选项文件 [options/finetune_realesrgan_x4plus_pairdata.yml](options/finetune_realesrgan_x4plus_pairdata.yml) ,特别是 `datasets` 部分:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
train:
|
||||||
|
name: DIV2K
|
||||||
|
type: RealESRGANPairedDataset
|
||||||
|
dataroot_gt: datasets/DF2K # 修改为你的 gt folder 文件夹根目录
|
||||||
|
dataroot_lq: datasets/DF2K # 修改为你的 lq folder 文件夹根目录
|
||||||
|
meta_info: datasets/DF2K/meta_info/meta_info_DIV2K_sub_pair.txt # 修改为你自己生成的元信息txt
|
||||||
|
io_backend:
|
||||||
|
type: disk
|
||||||
|
```
|
||||||
|
|
||||||
|
我们使用4个GPU进行训练。还可以使用参数 `--auto_resume` 在必要时自动恢复训练。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
||||||
|
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/finetune_realesrgan_x4plus_pairdata.yml --launcher pytorch --auto_resume
|
||||||
|
```
|
||||||
|
|
||||||
|
用 **1个GPU** 训练:
|
||||||
|
```bash
|
||||||
|
python realesrgan/train.py -opt options/finetune_realesrgan_x4plus_pairdata.yml --auto_resume
|
||||||
|
```
|
||||||
66
docs/anime_comparisons.md
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# Comparisons among different anime models
|
||||||
|
|
||||||
|
[English](anime_comparisons.md) **|** [简体中文](anime_comparisons_CN.md)
|
||||||
|
|
||||||
|
## Update News
|
||||||
|
|
||||||
|
- 2022/04/24: Release **AnimeVideo-v3**. We have made the following improvements:
|
||||||
|
- **better naturalness**
|
||||||
|
- **Fewer artifacts**
|
||||||
|
- **more faithful to the original colors**
|
||||||
|
- **better texture restoration**
|
||||||
|
- **better background restoration**
|
||||||
|
|
||||||
|
## Comparisons
|
||||||
|
|
||||||
|
We have compared our RealESRGAN-AnimeVideo-v3 with the following methods.
|
||||||
|
Our RealESRGAN-AnimeVideo-v3 can achieve better results with faster inference speed.
|
||||||
|
|
||||||
|
- [waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan) with the hyperparameters: `tile=0`, `noiselevel=2`
|
||||||
|
- [Real-CUGAN](https://github.com/bilibili/ailab/tree/main/Real-CUGAN): we use the [20220227](https://github.com/bilibili/ailab/releases/tag/Real-CUGAN-add-faster-low-memory-mode) version, the hyperparameters are: `cache_mode=0`, `tile=0`, `alpha=1`.
|
||||||
|
- our RealESRGAN-AnimeVideo-v3
|
||||||
|
|
||||||
|
## Results
|
||||||
|
|
||||||
|
You may need to **zoom in** for comparing details, or **click the image** to see in the full size. Please note that the images
|
||||||
|
in the table below are the resized and cropped patches from the original images, you can download the original inputs and outputs from [Google Drive](https://drive.google.com/drive/folders/1bc_Hje1Nqop9NDkUvci2VACSjL7HZMRp?usp=sharing) .
|
||||||
|
|
||||||
|
**More natural results, better background restoration**
|
||||||
|
| Input | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
||||||
|
| :---: | :---: | :---: | :---: |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
|
||||||
|
**Fewer artifacts, better detailed textures**
|
||||||
|
| Input | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
||||||
|
| :---: | :---: | :---: | :---: |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
|
||||||
|
**Other better results**
|
||||||
|
| Input | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
||||||
|
| :---: | :---: | :---: | :---: |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
|  |   |   |   |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
|
||||||
|
## Inference Speed
|
||||||
|
|
||||||
|
### PyTorch
|
||||||
|
|
||||||
|
Note that we only report the **model** time, and ignore the IO time.
|
||||||
|
|
||||||
|
| GPU | Input Resolution | waifu2x | Real-CUGAN | RealESRGAN-AnimeVideo-v3
|
||||||
|
| :---: | :---: | :---: | :---: | :---: |
|
||||||
|
| V100 | 1921 x 1080 | - | 3.4 fps | **10.0** fps |
|
||||||
|
| V100 | 1280 x 720 | - | 7.2 fps | **22.6** fps |
|
||||||
|
| V100 | 640 x 480 | - | 24.4 fps | **65.9** fps |
|
||||||
|
|
||||||
|
### ncnn
|
||||||
|
|
||||||
|
- [ ] TODO
|
||||||
68
docs/anime_comparisons_CN.md
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# 动漫视频模型比较
|
||||||
|
|
||||||
|
[English](anime_comparisons.md) **|** [简体中文](anime_comparisons_CN.md)
|
||||||
|
|
||||||
|
## 更新
|
||||||
|
|
||||||
|
- 2022/04/24: 发布 **AnimeVideo-v3**. 主要做了以下更新:
|
||||||
|
- **更自然**
|
||||||
|
- **更少瑕疵**
|
||||||
|
- **颜色保持得更好**
|
||||||
|
- **更好的纹理恢复**
|
||||||
|
- **虚化背景处理**
|
||||||
|
|
||||||
|
## 比较
|
||||||
|
|
||||||
|
我们将 RealESRGAN-AnimeVideo-v3 与以下方法进行了比较。我们的 RealESRGAN-AnimeVideo-v3 可以以更快的推理速度获得更好的结果。
|
||||||
|
|
||||||
|
- [waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan). 超参数: `tile=0`, `noiselevel=2`
|
||||||
|
- [Real-CUGAN](https://github.com/bilibili/ailab/tree/main/Real-CUGAN): 我们使用了[20220227](https://github.com/bilibili/ailab/releases/tag/Real-CUGAN-add-faster-low-memory-mode)版本, 超参: `cache_mode=0`, `tile=0`, `alpha=1`.
|
||||||
|
- 我们的 RealESRGAN-AnimeVideo-v3
|
||||||
|
|
||||||
|
## 结果
|
||||||
|
|
||||||
|
您可能需要**放大**以比较详细信息, 或者**单击图像**以查看完整尺寸。 请注意下面表格的图片是从原图里裁剪patch并且resize后的结果,您可以从
|
||||||
|
[Google Drive](https://drive.google.com/drive/folders/1bc_Hje1Nqop9NDkUvci2VACSjL7HZMRp?usp=sharing) 里下载原始的输入和输出。
|
||||||
|
|
||||||
|
**更自然的结果,更好的虚化背景恢复**
|
||||||
|
|
||||||
|
| 输入 | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
||||||
|
| :---: | :---: | :---: | :---: |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
|
||||||
|
**更少瑕疵,更好的细节纹理**
|
||||||
|
|
||||||
|
| 输入 | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
||||||
|
| :---: | :---: | :---: | :---: |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
|
||||||
|
**其他更好的结果**
|
||||||
|
|
||||||
|
| 输入 | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
||||||
|
| :---: | :---: | :---: | :---: |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
|  |   |   |   |
|
||||||
|
| |  |  |  |
|
||||||
|
| |  |  |  |
|
||||||
|
|
||||||
|
## 推理速度比较
|
||||||
|
|
||||||
|
### PyTorch
|
||||||
|
|
||||||
|
请注意,我们只报告了**模型推理**的时间, 而忽略了读写硬盘的时间.
|
||||||
|
|
||||||
|
| GPU | 输入尺寸 | waifu2x | Real-CUGAN | RealESRGAN-AnimeVideo-v3
|
||||||
|
| :---: | :---: | :---: | :---: | :---: |
|
||||||
|
| V100 | 1921 x 1080 | - | 3.4 fps | **10.0** fps |
|
||||||
|
| V100 | 1280 x 720 | - | 7.2 fps | **22.6** fps |
|
||||||
|
| V100 | 640 x 480 | - | 24.4 fps | **65.9** fps |
|
||||||
|
|
||||||
|
### ncnn
|
||||||
|
|
||||||
|
- [ ] TODO
|
||||||
@@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
:white_check_mark: We add [*RealESRGAN_x4plus_anime_6B.pth*](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth), which is optimized for **anime** images with much smaller model size.
|
:white_check_mark: We add [*RealESRGAN_x4plus_anime_6B.pth*](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth), which is optimized for **anime** images with much smaller model size.
|
||||||
|
|
||||||
- [Anime Model](#anime-model)
|
- [How to Use](#how-to-use)
|
||||||
- [How to Use](#how-to-use)
|
|
||||||
- [PyTorch Inference](#pytorch-inference)
|
- [PyTorch Inference](#pytorch-inference)
|
||||||
- [ncnn Executable File](#ncnn-executable-file)
|
- [ncnn Executable File](#ncnn-executable-file)
|
||||||
- [Comparisons with waifu2x](#comparisons-with-waifu2x)
|
- [Comparisons with waifu2x](#comparisons-with-waifu2x)
|
||||||
- [Comparisons with Sliding Bars](#comparisons-with-sliding-bars)
|
- [Comparisons with Sliding Bars](#comparisons-with-sliding-bars)
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_1.png">
|
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_1.png">
|
||||||
@@ -15,7 +14,7 @@
|
|||||||
|
|
||||||
The following is a video comparison with sliding bar. You may need to use the full-screen mode for better visual quality, as the original image is large; otherwise, you may encounter aliasing issue.
|
The following is a video comparison with sliding bar. You may need to use the full-screen mode for better visual quality, as the original image is large; otherwise, you may encounter aliasing issue.
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/17445847/131535127-613250d4-f754-4e20-9720-2f9608ad0675.mp4
|
<https://user-images.githubusercontent.com/17445847/131535127-613250d4-f754-4e20-9720-2f9608ad0675.mp4>
|
||||||
|
|
||||||
## How to Use
|
## How to Use
|
||||||
|
|
||||||
@@ -25,14 +24,14 @@ Pre-trained models: [RealESRGAN_x4plus_anime_6B](https://github.com/xinntao/Real
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# download model
|
# download model
|
||||||
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P experiments/pretrained_models
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights
|
||||||
# inference
|
# inference
|
||||||
python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
|
python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
|
||||||
```
|
```
|
||||||
|
|
||||||
### ncnn Executable File
|
### ncnn Executable File
|
||||||
|
|
||||||
Download the latest portable [Windows](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-windows.zip) / [Linux](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-ubuntu.zip) / [MacOS](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-macos.zip) **executable files for Intel/AMD/Nvidia GPU**.
|
Download the latest portable [Windows](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-windows.zip) / [Linux](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip) / [MacOS](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-macos.zip) **executable files for Intel/AMD/Nvidia GPU**.
|
||||||
|
|
||||||
Taking the Windows as example, run:
|
Taking the Windows as example, run:
|
||||||
|
|
||||||
@@ -64,6 +63,6 @@ We compare Real-ESRGAN-anime with [waifu2x](https://github.com/nihui/waifu2x-ncn
|
|||||||
|
|
||||||
The following are video comparisons with sliding bar. You may need to use the full-screen mode for better visual quality, as the original image is large; otherwise, you may encounter aliasing issue.
|
The following are video comparisons with sliding bar. You may need to use the full-screen mode for better visual quality, as the original image is large; otherwise, you may encounter aliasing issue.
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/17445847/131536647-a2fbf896-b495-4a9f-b1dd-ca7bbc90101a.mp4
|
<https://user-images.githubusercontent.com/17445847/131536647-a2fbf896-b495-4a9f-b1dd-ca7bbc90101a.mp4>
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/17445847/131536742-6d9d82b6-9765-4296-a15f-18f9aeaa5465.mp4
|
<https://user-images.githubusercontent.com/17445847/131536742-6d9d82b6-9765-4296-a15f-18f9aeaa5465.mp4>
|
||||||
|
|||||||
@@ -1,30 +1,32 @@
|
|||||||
# Anime Video Models
|
# Anime Video Models
|
||||||
|
|
||||||
:white_check_mark: We add small models that are optimized for anime videos :-)
|
:white_check_mark: We add small models that are optimized for anime videos :-)<br>
|
||||||
|
More comparisons can be found in [anime_comparisons.md](anime_comparisons.md)
|
||||||
|
|
||||||
| Models | Scale | Description |
|
- [How to Use](#how-to-use)
|
||||||
| ---------------------------------------------------------------------------------------------------------------------------------- | :---- | :----------------------------- |
|
- [PyTorch Inference](#pytorch-inference)
|
||||||
| [RealESRGANv2-animevideo-xsx2](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/RealESRGANv2-animevideo-xsx2.pth) | X2 | Anime video model with XS size |
|
- [ncnn Executable File](#ncnn-executable-file)
|
||||||
| [RealESRGANv2-animevideo-xsx4](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/RealESRGANv2-animevideo-xsx4.pth) | X4 | Anime video model with XS size |
|
|
||||||
|
|
||||||
- [Anime Video Models](#anime-video-models)
|
|
||||||
- [How to Use](#how-to-use)
|
|
||||||
- [PyTorch Inference](#pytorch-inference)
|
|
||||||
- [ncnn Executable File](#ncnn-executable-file)
|
|
||||||
- [Step 1: Use ffmpeg to extract frames from video](#step-1-use-ffmpeg-to-extract-frames-from-video)
|
- [Step 1: Use ffmpeg to extract frames from video](#step-1-use-ffmpeg-to-extract-frames-from-video)
|
||||||
- [Step 2: Inference with Real-ESRGAN executable file](#step-2-inference-with-real-esrgan-executable-file)
|
- [Step 2: Inference with Real-ESRGAN executable file](#step-2-inference-with-real-esrgan-executable-file)
|
||||||
- [Step 3: Merge the enhanced frames back into a video](#step-3-merge-the-enhanced-frames-back-into-a-video)
|
- [Step 3: Merge the enhanced frames back into a video](#step-3-merge-the-enhanced-frames-back-into-a-video)
|
||||||
- [More Demos](#more-demos)
|
- [More Demos](#more-demos)
|
||||||
|
|
||||||
|
| Models | Scale | Description |
|
||||||
|
| ---------------------------------------------------------------------------------------------------------------------------------- | :---- | :----------------------------- |
|
||||||
|
| [realesr-animevideov3](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth) | X4 <sup>1</sup> | Anime video model with XS size |
|
||||||
|
|
||||||
|
Note: <br>
|
||||||
|
<sup>1</sup> This model can also be used for X1, X2, X3.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
The following are some demos (best view in the full screen mode).
|
The following are some demos (best view in the full screen mode).
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/17445847/145706977-98bc64a4-af27-481c-8abe-c475e15db7ff.MP4
|
<https://user-images.githubusercontent.com/17445847/145706977-98bc64a4-af27-481c-8abe-c475e15db7ff.MP4>
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/17445847/145707055-6a4b79cb-3d9d-477f-8610-c6be43797133.MP4
|
<https://user-images.githubusercontent.com/17445847/145707055-6a4b79cb-3d9d-477f-8610-c6be43797133.MP4>
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/17445847/145707046-8702a17c-a194-4471-8a53-a4cc44c9594c.MP4
|
<https://user-images.githubusercontent.com/17445847/145783523-f4553729-9f03-44a8-a7cc-782aadf67b50.MP4>
|
||||||
|
|
||||||
## How to Use
|
## How to Use
|
||||||
|
|
||||||
@@ -32,12 +34,25 @@ https://user-images.githubusercontent.com/17445847/145707046-8702a17c-a194-4471-
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# download model
|
# download model
|
||||||
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/RealESRGANv2-animevideo-xsx2.pth -P experiments/pretrained_models
|
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth -P weights
|
||||||
# inference
|
# single gpu and single process inference
|
||||||
python inference_realesrgan_video.py -i inputs/video/onepiece_demo.mp4 -n RealESRGANv2-animevideo-xsx2 -s 2 -v -a --half --suffix outx2
|
CUDA_VISIBLE_DEVICES=0 python inference_realesrgan_video.py -i inputs/video/onepiece_demo.mp4 -n realesr-animevideov3 -s 2 --suffix outx2
|
||||||
|
# single gpu and multi process inference (you can use multi-processing to improve GPU utilization)
|
||||||
|
CUDA_VISIBLE_DEVICES=0 python inference_realesrgan_video.py -i inputs/video/onepiece_demo.mp4 -n realesr-animevideov3 -s 2 --suffix outx2 --num_process_per_gpu 2
|
||||||
|
# multi gpu and multi process inference
|
||||||
|
CUDA_VISIBLE_DEVICES=0,1,2,3 python inference_realesrgan_video.py -i inputs/video/onepiece_demo.mp4 -n realesr-animevideov3 -s 2 --suffix outx2 --num_process_per_gpu 2
|
||||||
```
|
```
|
||||||
|
|
||||||
### ncnn Executable File
|
```console
|
||||||
|
Usage:
|
||||||
|
--num_process_per_gpu The total number of process is num_gpu * num_process_per_gpu. The bottleneck of
|
||||||
|
the program lies on the IO, so the GPUs are usually not fully utilized. To alleviate
|
||||||
|
this issue, you can use multi-processing by setting this parameter. As long as it
|
||||||
|
does not exceed the CUDA memory
|
||||||
|
--extract_frame_first If you encounter ffmpeg error when using multi-processing, you can turn this option on.
|
||||||
|
```
|
||||||
|
|
||||||
|
### NCNN Executable File
|
||||||
|
|
||||||
#### Step 1: Use ffmpeg to extract frames from video
|
#### Step 1: Use ffmpeg to extract frames from video
|
||||||
|
|
||||||
@@ -49,12 +64,12 @@ ffmpeg -i onepiece_demo.mp4 -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 tmp_frames/fram
|
|||||||
|
|
||||||
#### Step 2: Inference with Real-ESRGAN executable file
|
#### Step 2: Inference with Real-ESRGAN executable file
|
||||||
|
|
||||||
1. Download the latest portable [Windows](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-windows.zip) / [Linux](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-ubuntu.zip) / [MacOS](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/realesrgan-ncnn-vulkan-20211212-macos.zip) **executable files for Intel/AMD/Nvidia GPU**
|
1. Download the latest portable [Windows](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-windows.zip) / [Linux](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip) / [MacOS](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-macos.zip) **executable files for Intel/AMD/Nvidia GPU**
|
||||||
|
|
||||||
1. Taking the Windows as example, run:
|
1. Taking the Windows as example, run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./realesrgan-ncnn-vulkan.exe -i tmp_frames -o out_frames -n RealESRGANv2-animevideo-xsx2 -s 2 -f jpg
|
./realesrgan-ncnn-vulkan.exe -i tmp_frames -o out_frames -n realesr-animevideov3 -s 2 -f jpg
|
||||||
```
|
```
|
||||||
|
|
||||||
- Remember to create the folder `out_frames` ahead
|
- Remember to create the folder `out_frames` ahead
|
||||||
@@ -81,7 +96,7 @@ ffmpeg -i onepiece_demo.mp4 -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 tmp_frames/fram
|
|||||||
2. Merge frames
|
2. Merge frames
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ffmpeg -i out_frames/frame%08d.jpg -c:v libx264 -r 23.98 -pix_fmt yuv420p output.mp4
|
ffmpeg -r 23.98 -i out_frames/frame%08d.jpg -c:v libx264 -r 23.98 -pix_fmt yuv420p output.mp4
|
||||||
```
|
```
|
||||||
|
|
||||||
```console
|
```console
|
||||||
@@ -95,7 +110,7 @@ ffmpeg -i onepiece_demo.mp4 -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 tmp_frames/fram
|
|||||||
If you also want to copy audio from the input videos, run:
|
If you also want to copy audio from the input videos, run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ffmpeg -i out_frames/frame%08d.jpg -i onepiece_demo.mp4 -map 0:v:0 -map 1:a:0 -c:a copy -c:v libx264 -r 23.98 -pix_fmt yuv420p output_w_audio.mp4
|
ffmpeg -r 23.98 -i out_frames/frame%08d.jpg -i onepiece_demo.mp4 -map 0:v:0 -map 1:a:0 -c:a copy -c:v libx264 -r 23.98 -pix_fmt yuv420p output_w_audio.mp4
|
||||||
```
|
```
|
||||||
|
|
||||||
```console
|
```console
|
||||||
@@ -110,12 +125,12 @@ ffmpeg -i onepiece_demo.mp4 -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 tmp_frames/fram
|
|||||||
|
|
||||||
- Input video for One Piece:
|
- Input video for One Piece:
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/17445847/145706822-0e83d9c4-78ef-40ee-b2a4-d8b8c3692d17.mp4
|
<https://user-images.githubusercontent.com/17445847/145706822-0e83d9c4-78ef-40ee-b2a4-d8b8c3692d17.mp4>
|
||||||
|
|
||||||
- Out video for One Piece
|
- Out video for One Piece
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/17445847/145706827-384108c0-78f6-4aa7-9621-99d1aaf65682.mp4
|
<https://user-images.githubusercontent.com/17445847/164960481-759658cf-fcb8-480c-b888-cecb606e8744.mp4>
|
||||||
|
|
||||||
**More comparisons**
|
**More comparisons**
|
||||||
|
|
||||||
https://user-images.githubusercontent.com/17445847/145707458-04a5e9b9-2edd-4d1f-b400-380a72e5f5e6.MP4
|
<https://user-images.githubusercontent.com/17445847/145707458-04a5e9b9-2edd-4d1f-b400-380a72e5f5e6.MP4>
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
# :european_castle: Model Zoo
|
# :european_castle: Model Zoo
|
||||||
|
|
||||||
- [:european_castle: Model Zoo](#european_castle-model-zoo)
|
- [For General Images](#for-general-images)
|
||||||
- [For General Images](#for-general-images)
|
- [For Anime Images](#for-anime-images)
|
||||||
- [For Anime Images](#for-anime-images)
|
- [For Anime Videos](#for-anime-videos)
|
||||||
- [For Anime Videos](#for-anime-videos)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -15,6 +14,7 @@
|
|||||||
| [RealESRGAN_x2plus](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth) | X2 | X2 model for general images |
|
| [RealESRGAN_x2plus](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth) | X2 | X2 model for general images |
|
||||||
| [RealESRNet_x4plus](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth) | X4 | X4 model with MSE loss (over-smooth effects) |
|
| [RealESRNet_x4plus](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth) | X4 | X4 model with MSE loss (over-smooth effects) |
|
||||||
| [official ESRGAN_x4](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth) | X4 | official ESRGAN model |
|
| [official ESRGAN_x4](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth) | X4 | official ESRGAN model |
|
||||||
|
| [realesr-general-x4v3](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth) | X4 (can also be used for X1, X2, X3) | A tiny small model (consume much fewer GPU memory and time); not too strong deblur and denoise capacity |
|
||||||
|
|
||||||
The following models are **discriminators**, which are usually used for fine-tuning.
|
The following models are **discriminators**, which are usually used for fine-tuning.
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ The following models are **discriminators**, which are usually used for fine-tun
|
|||||||
| [RealESRGAN_x4plus_netD](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth) | RealESRGAN_x4plus |
|
| [RealESRGAN_x4plus_netD](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth) | RealESRGAN_x4plus |
|
||||||
| [RealESRGAN_x2plus_netD](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x2plus_netD.pth) | RealESRGAN_x2plus |
|
| [RealESRGAN_x2plus_netD](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x2plus_netD.pth) | RealESRGAN_x2plus |
|
||||||
|
|
||||||
## For Anime Images
|
## For Anime Images / Illustrations
|
||||||
|
|
||||||
| Models | Scale | Description |
|
| Models | Scale | Description |
|
||||||
| ------------------------------------------------------------------------------------------------------------------------------ | :---- | :---------------------------------------------------------- |
|
| ------------------------------------------------------------------------------------------------------------------------------ | :---- | :---------------------------------------------------------- |
|
||||||
@@ -35,12 +35,14 @@ The following models are **discriminators**, which are usually used for fine-tun
|
|||||||
| ---------------------------------------------------------------------------------------------------------------------------------------- | :------------------------- |
|
| ---------------------------------------------------------------------------------------------------------------------------------------- | :------------------------- |
|
||||||
| [RealESRGAN_x4plus_anime_6B_netD](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B_netD.pth) | RealESRGAN_x4plus_anime_6B |
|
| [RealESRGAN_x4plus_anime_6B_netD](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B_netD.pth) | RealESRGAN_x4plus_anime_6B |
|
||||||
|
|
||||||
## For Anime Videos
|
## For Animation Videos
|
||||||
|
|
||||||
| Models | Scale | Description |
|
| Models | Scale | Description |
|
||||||
| ---------------------------------------------------------------------------------------------------------------------------------- | :---- | :----------------------------- |
|
| ---------------------------------------------------------------------------------------------------------------------------------- | :---- | :----------------------------- |
|
||||||
| [RealESRGANv2-animevideo-xsx2](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/RealESRGANv2-animevideo-xsx2.pth) | X2 | Anime video model with XS size |
|
| [realesr-animevideov3](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth) | X4<sup>1</sup> | Anime video model with XS size |
|
||||||
| [RealESRGANv2-animevideo-xsx4](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.3.0/RealESRGANv2-animevideo-xsx4.pth) | X4 | Anime video model with XS size |
|
|
||||||
|
Note: <br>
|
||||||
|
<sup>1</sup> This model can also be used for X1, X2, X3.
|
||||||
|
|
||||||
The following models are **discriminators**, which are usually used for fine-tuning.
|
The following models are **discriminators**, which are usually used for fine-tuning.
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import cv2
|
|||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
from basicsr.archs.rrdbnet_arch import RRDBNet
|
from basicsr.archs.rrdbnet_arch import RRDBNet
|
||||||
|
from basicsr.utils.download_util import load_file_from_url
|
||||||
|
|
||||||
from realesrgan import RealESRGANer
|
from realesrgan import RealESRGANer
|
||||||
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
|
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
|
||||||
@@ -18,17 +19,26 @@ def main():
|
|||||||
'--model_name',
|
'--model_name',
|
||||||
type=str,
|
type=str,
|
||||||
default='RealESRGAN_x4plus',
|
default='RealESRGAN_x4plus',
|
||||||
help=('Model names: RealESRGAN_x4plus | RealESRNet_x4plus | RealESRGAN_x4plus_anime_6B | RealESRGAN_x2plus'
|
help=('Model names: RealESRGAN_x4plus | RealESRNet_x4plus | RealESRGAN_x4plus_anime_6B | RealESRGAN_x2plus | '
|
||||||
'RealESRGANv2-anime-xsx2 | RealESRGANv2-animevideo-xsx2-nousm | RealESRGANv2-animevideo-xsx2'
|
'realesr-animevideov3 | realesr-general-x4v3'))
|
||||||
'RealESRGANv2-anime-xsx4 | RealESRGANv2-animevideo-xsx4-nousm | RealESRGANv2-animevideo-xsx4'))
|
|
||||||
parser.add_argument('-o', '--output', type=str, default='results', help='Output folder')
|
parser.add_argument('-o', '--output', type=str, default='results', help='Output folder')
|
||||||
|
parser.add_argument(
|
||||||
|
'-dn',
|
||||||
|
'--denoise_strength',
|
||||||
|
type=float,
|
||||||
|
default=0.5,
|
||||||
|
help=('Denoise strength. 0 for weak denoise (keep noise), 1 for strong denoise ability. '
|
||||||
|
'Only used for the realesr-general-x4v3 model'))
|
||||||
parser.add_argument('-s', '--outscale', type=float, default=4, help='The final upsampling scale of the image')
|
parser.add_argument('-s', '--outscale', type=float, default=4, help='The final upsampling scale of the image')
|
||||||
|
parser.add_argument(
|
||||||
|
'--model_path', type=str, default=None, help='[Option] Model path. Usually, you do not need to specify it')
|
||||||
parser.add_argument('--suffix', type=str, default='out', help='Suffix of the restored image')
|
parser.add_argument('--suffix', type=str, default='out', help='Suffix of the restored image')
|
||||||
parser.add_argument('-t', '--tile', type=int, default=0, help='Tile size, 0 for no tile during testing')
|
parser.add_argument('-t', '--tile', type=int, default=0, help='Tile size, 0 for no tile during testing')
|
||||||
parser.add_argument('--tile_pad', type=int, default=10, help='Tile padding')
|
parser.add_argument('--tile_pad', type=int, default=10, help='Tile padding')
|
||||||
parser.add_argument('--pre_pad', type=int, default=0, help='Pre padding size at each border')
|
parser.add_argument('--pre_pad', type=int, default=0, help='Pre padding size at each border')
|
||||||
parser.add_argument('--face_enhance', action='store_true', help='Use GFPGAN to enhance face')
|
parser.add_argument('--face_enhance', action='store_true', help='Use GFPGAN to enhance face')
|
||||||
parser.add_argument('--half', action='store_true', help='Use half precision during inference')
|
parser.add_argument(
|
||||||
|
'--fp32', action='store_true', help='Use fp32 precision during inference. Default: fp16 (half precision).')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--alpha_upsampler',
|
'--alpha_upsampler',
|
||||||
type=str,
|
type=str,
|
||||||
@@ -39,51 +49,76 @@ def main():
|
|||||||
type=str,
|
type=str,
|
||||||
default='auto',
|
default='auto',
|
||||||
help='Image extension. Options: auto | jpg | png, auto means using the same extension as inputs')
|
help='Image extension. Options: auto | jpg | png, auto means using the same extension as inputs')
|
||||||
|
parser.add_argument(
|
||||||
|
'-g', '--gpu-id', type=int, default=None, help='gpu device to use (default=None) can be 0,1,2 for multi-gpu')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# determine models according to model names
|
# determine models according to model names
|
||||||
args.model_name = args.model_name.split('.')[0]
|
args.model_name = args.model_name.split('.')[0]
|
||||||
if args.model_name in ['RealESRGAN_x4plus', 'RealESRNet_x4plus']: # x4 RRDBNet model
|
if args.model_name == 'RealESRGAN_x4plus': # x4 RRDBNet model
|
||||||
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
||||||
netscale = 4
|
netscale = 4
|
||||||
elif args.model_name in ['RealESRGAN_x4plus_anime_6B']: # x4 RRDBNet model with 6 blocks
|
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth']
|
||||||
|
elif args.model_name == 'RealESRNet_x4plus': # x4 RRDBNet model
|
||||||
|
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
||||||
|
netscale = 4
|
||||||
|
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth']
|
||||||
|
elif args.model_name == 'RealESRGAN_x4plus_anime_6B': # x4 RRDBNet model with 6 blocks
|
||||||
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4)
|
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4)
|
||||||
netscale = 4
|
netscale = 4
|
||||||
elif args.model_name in ['RealESRGAN_x2plus']: # x2 RRDBNet model
|
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth']
|
||||||
|
elif args.model_name == 'RealESRGAN_x2plus': # x2 RRDBNet model
|
||||||
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
|
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
|
||||||
netscale = 2
|
netscale = 2
|
||||||
elif args.model_name in [
|
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth']
|
||||||
'RealESRGANv2-anime-xsx2', 'RealESRGANv2-animevideo-xsx2-nousm', 'RealESRGANv2-animevideo-xsx2'
|
elif args.model_name == 'realesr-animevideov3': # x4 VGG-style model (XS size)
|
||||||
]: # x2 VGG-style model (XS size)
|
|
||||||
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=2, act_type='prelu')
|
|
||||||
netscale = 2
|
|
||||||
elif args.model_name in [
|
|
||||||
'RealESRGANv2-anime-xsx4', 'RealESRGANv2-animevideo-xsx4-nousm', 'RealESRGANv2-animevideo-xsx4'
|
|
||||||
]: # x4 VGG-style model (XS size)
|
|
||||||
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu')
|
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu')
|
||||||
netscale = 4
|
netscale = 4
|
||||||
|
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth']
|
||||||
|
elif args.model_name == 'realesr-general-x4v3': # x4 VGG-style model (S size)
|
||||||
|
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
||||||
|
netscale = 4
|
||||||
|
file_url = [
|
||||||
|
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth',
|
||||||
|
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth'
|
||||||
|
]
|
||||||
|
|
||||||
# determine model paths
|
# determine model paths
|
||||||
model_path = os.path.join('experiments/pretrained_models', args.model_name + '.pth')
|
if args.model_path is not None:
|
||||||
|
model_path = args.model_path
|
||||||
|
else:
|
||||||
|
model_path = os.path.join('weights', args.model_name + '.pth')
|
||||||
if not os.path.isfile(model_path):
|
if not os.path.isfile(model_path):
|
||||||
model_path = os.path.join('realesrgan/weights', args.model_name + '.pth')
|
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
if not os.path.isfile(model_path):
|
for url in file_url:
|
||||||
raise ValueError(f'Model {args.model_name} does not exist.')
|
# model_path will be updated
|
||||||
|
model_path = load_file_from_url(
|
||||||
|
url=url, model_dir=os.path.join(ROOT_DIR, 'weights'), progress=True, file_name=None)
|
||||||
|
|
||||||
|
# use dni to control the denoise strength
|
||||||
|
dni_weight = None
|
||||||
|
if args.model_name == 'realesr-general-x4v3' and args.denoise_strength != 1:
|
||||||
|
wdn_model_path = model_path.replace('realesr-general-x4v3', 'realesr-general-wdn-x4v3')
|
||||||
|
model_path = [model_path, wdn_model_path]
|
||||||
|
dni_weight = [args.denoise_strength, 1 - args.denoise_strength]
|
||||||
|
|
||||||
# restorer
|
# restorer
|
||||||
upsampler = RealESRGANer(
|
upsampler = RealESRGANer(
|
||||||
scale=netscale,
|
scale=netscale,
|
||||||
model_path=model_path,
|
model_path=model_path,
|
||||||
|
dni_weight=dni_weight,
|
||||||
model=model,
|
model=model,
|
||||||
tile=args.tile,
|
tile=args.tile,
|
||||||
tile_pad=args.tile_pad,
|
tile_pad=args.tile_pad,
|
||||||
pre_pad=args.pre_pad,
|
pre_pad=args.pre_pad,
|
||||||
half=args.half)
|
half=not args.fp32,
|
||||||
|
gpu_id=args.gpu_id)
|
||||||
|
|
||||||
if args.face_enhance: # Use GFPGAN for face enhancement
|
if args.face_enhance: # Use GFPGAN for face enhancement
|
||||||
from gfpgan import GFPGANer
|
from gfpgan import GFPGANer
|
||||||
face_enhancer = GFPGANer(
|
face_enhancer = GFPGANer(
|
||||||
model_path='https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth',
|
model_path='https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth',
|
||||||
upscale=args.outscale,
|
upscale=args.outscale,
|
||||||
arch='clean',
|
arch='clean',
|
||||||
channel_multiplier=2,
|
channel_multiplier=2,
|
||||||
@@ -120,6 +155,9 @@ def main():
|
|||||||
extension = args.ext
|
extension = args.ext
|
||||||
if img_mode == 'RGBA': # RGBA images should be saved in png format
|
if img_mode == 'RGBA': # RGBA images should be saved in png format
|
||||||
extension = 'png'
|
extension = 'png'
|
||||||
|
if args.suffix == '':
|
||||||
|
save_path = os.path.join(args.output, f'{imgname}.{extension}')
|
||||||
|
else:
|
||||||
save_path = os.path.join(args.output, f'{imgname}_{args.suffix}.{extension}')
|
save_path = os.path.join(args.output, f'{imgname}_{args.suffix}.{extension}')
|
||||||
cv2.imwrite(save_path, output)
|
cv2.imwrite(save_path, output)
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,327 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
import cv2
|
||||||
import glob
|
import glob
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
import queue
|
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
import torch
|
import torch
|
||||||
from basicsr.archs.rrdbnet_arch import RRDBNet
|
from basicsr.archs.rrdbnet_arch import RRDBNet
|
||||||
from basicsr.utils.logger import AvgTimer
|
from basicsr.utils.download_util import load_file_from_url
|
||||||
|
from os import path as osp
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from realesrgan import IOConsumer, PrefetchReader, RealESRGANer
|
from realesrgan import RealESRGANer
|
||||||
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
|
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
|
||||||
|
|
||||||
|
try:
|
||||||
|
import ffmpeg
|
||||||
|
except ImportError:
|
||||||
|
import pip
|
||||||
|
pip.main(['install', '--user', 'ffmpeg-python'])
|
||||||
|
import ffmpeg
|
||||||
|
|
||||||
|
|
||||||
|
def get_video_meta_info(video_path):
|
||||||
|
ret = {}
|
||||||
|
probe = ffmpeg.probe(video_path)
|
||||||
|
video_streams = [stream for stream in probe['streams'] if stream['codec_type'] == 'video']
|
||||||
|
has_audio = any(stream['codec_type'] == 'audio' for stream in probe['streams'])
|
||||||
|
ret['width'] = video_streams[0]['width']
|
||||||
|
ret['height'] = video_streams[0]['height']
|
||||||
|
ret['fps'] = eval(video_streams[0]['avg_frame_rate'])
|
||||||
|
ret['audio'] = ffmpeg.input(video_path).audio if has_audio else None
|
||||||
|
ret['nb_frames'] = int(video_streams[0]['nb_frames'])
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def get_sub_video(args, num_process, process_idx):
|
||||||
|
if num_process == 1:
|
||||||
|
return args.input
|
||||||
|
meta = get_video_meta_info(args.input)
|
||||||
|
duration = int(meta['nb_frames'] / meta['fps'])
|
||||||
|
part_time = duration // num_process
|
||||||
|
print(f'duration: {duration}, part_time: {part_time}')
|
||||||
|
os.makedirs(osp.join(args.output, f'{args.video_name}_inp_tmp_videos'), exist_ok=True)
|
||||||
|
out_path = osp.join(args.output, f'{args.video_name}_inp_tmp_videos', f'{process_idx:03d}.mp4')
|
||||||
|
cmd = [
|
||||||
|
args.ffmpeg_bin, f'-i {args.input}', '-ss', f'{part_time * process_idx}',
|
||||||
|
f'-to {part_time * (process_idx + 1)}' if process_idx != num_process - 1 else '', '-async 1', out_path, '-y'
|
||||||
|
]
|
||||||
|
print(' '.join(cmd))
|
||||||
|
subprocess.call(' '.join(cmd), shell=True)
|
||||||
|
return out_path
|
||||||
|
|
||||||
|
|
||||||
|
class Reader:
|
||||||
|
|
||||||
|
def __init__(self, args, total_workers=1, worker_idx=0):
|
||||||
|
self.args = args
|
||||||
|
input_type = mimetypes.guess_type(args.input)[0]
|
||||||
|
self.input_type = 'folder' if input_type is None else input_type
|
||||||
|
self.paths = [] # for image&folder type
|
||||||
|
self.audio = None
|
||||||
|
self.input_fps = None
|
||||||
|
if self.input_type.startswith('video'):
|
||||||
|
video_path = get_sub_video(args, total_workers, worker_idx)
|
||||||
|
self.stream_reader = (
|
||||||
|
ffmpeg.input(video_path).output('pipe:', format='rawvideo', pix_fmt='bgr24',
|
||||||
|
loglevel='error').run_async(
|
||||||
|
pipe_stdin=True, pipe_stdout=True, cmd=args.ffmpeg_bin))
|
||||||
|
meta = get_video_meta_info(video_path)
|
||||||
|
self.width = meta['width']
|
||||||
|
self.height = meta['height']
|
||||||
|
self.input_fps = meta['fps']
|
||||||
|
self.audio = meta['audio']
|
||||||
|
self.nb_frames = meta['nb_frames']
|
||||||
|
|
||||||
|
else:
|
||||||
|
if self.input_type.startswith('image'):
|
||||||
|
self.paths = [args.input]
|
||||||
|
else:
|
||||||
|
paths = sorted(glob.glob(os.path.join(args.input, '*')))
|
||||||
|
tot_frames = len(paths)
|
||||||
|
num_frame_per_worker = tot_frames // total_workers + (1 if tot_frames % total_workers else 0)
|
||||||
|
self.paths = paths[num_frame_per_worker * worker_idx:num_frame_per_worker * (worker_idx + 1)]
|
||||||
|
|
||||||
|
self.nb_frames = len(self.paths)
|
||||||
|
assert self.nb_frames > 0, 'empty folder'
|
||||||
|
from PIL import Image
|
||||||
|
tmp_img = Image.open(self.paths[0])
|
||||||
|
self.width, self.height = tmp_img.size
|
||||||
|
self.idx = 0
|
||||||
|
|
||||||
|
def get_resolution(self):
|
||||||
|
return self.height, self.width
|
||||||
|
|
||||||
|
def get_fps(self):
|
||||||
|
if self.args.fps is not None:
|
||||||
|
return self.args.fps
|
||||||
|
elif self.input_fps is not None:
|
||||||
|
return self.input_fps
|
||||||
|
return 24
|
||||||
|
|
||||||
|
def get_audio(self):
|
||||||
|
return self.audio
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return self.nb_frames
|
||||||
|
|
||||||
|
def get_frame_from_stream(self):
|
||||||
|
img_bytes = self.stream_reader.stdout.read(self.width * self.height * 3) # 3 bytes for one pixel
|
||||||
|
if not img_bytes:
|
||||||
|
return None
|
||||||
|
img = np.frombuffer(img_bytes, np.uint8).reshape([self.height, self.width, 3])
|
||||||
|
return img
|
||||||
|
|
||||||
|
def get_frame_from_list(self):
|
||||||
|
if self.idx >= self.nb_frames:
|
||||||
|
return None
|
||||||
|
img = cv2.imread(self.paths[self.idx])
|
||||||
|
self.idx += 1
|
||||||
|
return img
|
||||||
|
|
||||||
|
def get_frame(self):
|
||||||
|
if self.input_type.startswith('video'):
|
||||||
|
return self.get_frame_from_stream()
|
||||||
|
else:
|
||||||
|
return self.get_frame_from_list()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
if self.input_type.startswith('video'):
|
||||||
|
self.stream_reader.stdin.close()
|
||||||
|
self.stream_reader.wait()
|
||||||
|
|
||||||
|
|
||||||
|
class Writer:
|
||||||
|
|
||||||
|
def __init__(self, args, audio, height, width, video_save_path, fps):
|
||||||
|
out_width, out_height = int(width * args.outscale), int(height * args.outscale)
|
||||||
|
if out_height > 2160:
|
||||||
|
print('You are generating video that is larger than 4K, which will be very slow due to IO speed.',
|
||||||
|
'We highly recommend to decrease the outscale(aka, -s).')
|
||||||
|
|
||||||
|
if audio is not None:
|
||||||
|
self.stream_writer = (
|
||||||
|
ffmpeg.input('pipe:', format='rawvideo', pix_fmt='bgr24', s=f'{out_width}x{out_height}',
|
||||||
|
framerate=fps).output(
|
||||||
|
audio,
|
||||||
|
video_save_path,
|
||||||
|
pix_fmt='yuv420p',
|
||||||
|
vcodec='libx264',
|
||||||
|
loglevel='error',
|
||||||
|
acodec='copy').overwrite_output().run_async(
|
||||||
|
pipe_stdin=True, pipe_stdout=True, cmd=args.ffmpeg_bin))
|
||||||
|
else:
|
||||||
|
self.stream_writer = (
|
||||||
|
ffmpeg.input('pipe:', format='rawvideo', pix_fmt='bgr24', s=f'{out_width}x{out_height}',
|
||||||
|
framerate=fps).output(
|
||||||
|
video_save_path, pix_fmt='yuv420p', vcodec='libx264',
|
||||||
|
loglevel='error').overwrite_output().run_async(
|
||||||
|
pipe_stdin=True, pipe_stdout=True, cmd=args.ffmpeg_bin))
|
||||||
|
|
||||||
|
def write_frame(self, frame):
|
||||||
|
frame = frame.astype(np.uint8).tobytes()
|
||||||
|
self.stream_writer.stdin.write(frame)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.stream_writer.stdin.close()
|
||||||
|
self.stream_writer.wait()
|
||||||
|
|
||||||
|
|
||||||
|
def inference_video(args, video_save_path, device=None, total_workers=1, worker_idx=0):
|
||||||
|
# ---------------------- determine models according to model names ---------------------- #
|
||||||
|
args.model_name = args.model_name.split('.pth')[0]
|
||||||
|
if args.model_name == 'RealESRGAN_x4plus': # x4 RRDBNet model
|
||||||
|
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
||||||
|
netscale = 4
|
||||||
|
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth']
|
||||||
|
elif args.model_name == 'RealESRNet_x4plus': # x4 RRDBNet model
|
||||||
|
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
||||||
|
netscale = 4
|
||||||
|
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth']
|
||||||
|
elif args.model_name == 'RealESRGAN_x4plus_anime_6B': # x4 RRDBNet model with 6 blocks
|
||||||
|
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4)
|
||||||
|
netscale = 4
|
||||||
|
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth']
|
||||||
|
elif args.model_name == 'RealESRGAN_x2plus': # x2 RRDBNet model
|
||||||
|
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
|
||||||
|
netscale = 2
|
||||||
|
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth']
|
||||||
|
elif args.model_name == 'realesr-animevideov3': # x4 VGG-style model (XS size)
|
||||||
|
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu')
|
||||||
|
netscale = 4
|
||||||
|
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth']
|
||||||
|
elif args.model_name == 'realesr-general-x4v3': # x4 VGG-style model (S size)
|
||||||
|
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
||||||
|
netscale = 4
|
||||||
|
file_url = [
|
||||||
|
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth',
|
||||||
|
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth'
|
||||||
|
]
|
||||||
|
|
||||||
|
# ---------------------- determine model paths ---------------------- #
|
||||||
|
model_path = os.path.join('weights', args.model_name + '.pth')
|
||||||
|
if not os.path.isfile(model_path):
|
||||||
|
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
for url in file_url:
|
||||||
|
# model_path will be updated
|
||||||
|
model_path = load_file_from_url(
|
||||||
|
url=url, model_dir=os.path.join(ROOT_DIR, 'weights'), progress=True, file_name=None)
|
||||||
|
|
||||||
|
# use dni to control the denoise strength
|
||||||
|
dni_weight = None
|
||||||
|
if args.model_name == 'realesr-general-x4v3' and args.denoise_strength != 1:
|
||||||
|
wdn_model_path = model_path.replace('realesr-general-x4v3', 'realesr-general-wdn-x4v3')
|
||||||
|
model_path = [model_path, wdn_model_path]
|
||||||
|
dni_weight = [args.denoise_strength, 1 - args.denoise_strength]
|
||||||
|
|
||||||
|
# restorer
|
||||||
|
upsampler = RealESRGANer(
|
||||||
|
scale=netscale,
|
||||||
|
model_path=model_path,
|
||||||
|
dni_weight=dni_weight,
|
||||||
|
model=model,
|
||||||
|
tile=args.tile,
|
||||||
|
tile_pad=args.tile_pad,
|
||||||
|
pre_pad=args.pre_pad,
|
||||||
|
half=not args.fp32,
|
||||||
|
device=device,
|
||||||
|
)
|
||||||
|
|
||||||
|
if 'anime' in args.model_name and args.face_enhance:
|
||||||
|
print('face_enhance is not supported in anime models, we turned this option off for you. '
|
||||||
|
'if you insist on turning it on, please manually comment the relevant lines of code.')
|
||||||
|
args.face_enhance = False
|
||||||
|
|
||||||
|
if args.face_enhance: # Use GFPGAN for face enhancement
|
||||||
|
from gfpgan import GFPGANer
|
||||||
|
face_enhancer = GFPGANer(
|
||||||
|
model_path='https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth',
|
||||||
|
upscale=args.outscale,
|
||||||
|
arch='clean',
|
||||||
|
channel_multiplier=2,
|
||||||
|
bg_upsampler=upsampler) # TODO support custom device
|
||||||
|
else:
|
||||||
|
face_enhancer = None
|
||||||
|
|
||||||
|
reader = Reader(args, total_workers, worker_idx)
|
||||||
|
audio = reader.get_audio()
|
||||||
|
height, width = reader.get_resolution()
|
||||||
|
fps = reader.get_fps()
|
||||||
|
writer = Writer(args, audio, height, width, video_save_path, fps)
|
||||||
|
|
||||||
|
pbar = tqdm(total=len(reader), unit='frame', desc='inference')
|
||||||
|
while True:
|
||||||
|
img = reader.get_frame()
|
||||||
|
if img is None:
|
||||||
|
break
|
||||||
|
|
||||||
|
try:
|
||||||
|
if args.face_enhance:
|
||||||
|
_, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
|
||||||
|
else:
|
||||||
|
output, _ = upsampler.enhance(img, outscale=args.outscale)
|
||||||
|
except RuntimeError as error:
|
||||||
|
print('Error', error)
|
||||||
|
print('If you encounter CUDA out of memory, try to set --tile with a smaller number.')
|
||||||
|
else:
|
||||||
|
writer.write_frame(output)
|
||||||
|
|
||||||
|
torch.cuda.synchronize(device)
|
||||||
|
pbar.update(1)
|
||||||
|
|
||||||
|
reader.close()
|
||||||
|
writer.close()
|
||||||
|
|
||||||
|
|
||||||
|
def run(args):
|
||||||
|
args.video_name = osp.splitext(os.path.basename(args.input))[0]
|
||||||
|
video_save_path = osp.join(args.output, f'{args.video_name}_{args.suffix}.mp4')
|
||||||
|
|
||||||
|
if args.extract_frame_first:
|
||||||
|
tmp_frames_folder = osp.join(args.output, f'{args.video_name}_inp_tmp_frames')
|
||||||
|
os.makedirs(tmp_frames_folder, exist_ok=True)
|
||||||
|
os.system(f'ffmpeg -i {args.input} -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 {tmp_frames_folder}/frame%08d.png')
|
||||||
|
args.input = tmp_frames_folder
|
||||||
|
|
||||||
|
num_gpus = torch.cuda.device_count()
|
||||||
|
num_process = num_gpus * args.num_process_per_gpu
|
||||||
|
if num_process == 1:
|
||||||
|
inference_video(args, video_save_path)
|
||||||
|
return
|
||||||
|
|
||||||
|
ctx = torch.multiprocessing.get_context('spawn')
|
||||||
|
pool = ctx.Pool(num_process)
|
||||||
|
os.makedirs(osp.join(args.output, f'{args.video_name}_out_tmp_videos'), exist_ok=True)
|
||||||
|
pbar = tqdm(total=num_process, unit='sub_video', desc='inference')
|
||||||
|
for i in range(num_process):
|
||||||
|
sub_video_save_path = osp.join(args.output, f'{args.video_name}_out_tmp_videos', f'{i:03d}.mp4')
|
||||||
|
pool.apply_async(
|
||||||
|
inference_video,
|
||||||
|
args=(args, sub_video_save_path, torch.device(i % num_gpus), num_process, i),
|
||||||
|
callback=lambda arg: pbar.update(1))
|
||||||
|
pool.close()
|
||||||
|
pool.join()
|
||||||
|
|
||||||
|
# combine sub videos
|
||||||
|
# prepare vidlist.txt
|
||||||
|
with open(f'{args.output}/{args.video_name}_vidlist.txt', 'w') as f:
|
||||||
|
for i in range(num_process):
|
||||||
|
f.write(f'file \'{args.video_name}_out_tmp_videos/{i:03d}.mp4\'\n')
|
||||||
|
|
||||||
|
cmd = [
|
||||||
|
args.ffmpeg_bin, '-f', 'concat', '-safe', '0', '-i', f'{args.output}/{args.video_name}_vidlist.txt', '-c',
|
||||||
|
'copy', f'{video_save_path}'
|
||||||
|
]
|
||||||
|
print(' '.join(cmd))
|
||||||
|
subprocess.call(cmd)
|
||||||
|
shutil.rmtree(osp.join(args.output, f'{args.video_name}_out_tmp_videos'))
|
||||||
|
if osp.exists(osp.join(args.output, f'{args.video_name}_inp_tmp_videos')):
|
||||||
|
shutil.rmtree(osp.join(args.output, f'{args.video_name}_inp_tmp_videos'))
|
||||||
|
os.remove(f'{args.output}/{args.video_name}_vidlist.txt')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Inference demo for Real-ESRGAN.
|
"""Inference demo for Real-ESRGAN.
|
||||||
@@ -19,27 +329,35 @@ def main():
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-i', '--input', type=str, default='inputs', help='Input image or folder')
|
parser.add_argument('-i', '--input', type=str, default='inputs', help='Input video, image or folder')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-n',
|
'-n',
|
||||||
'--model_name',
|
'--model_name',
|
||||||
type=str,
|
type=str,
|
||||||
default='RealESRGAN_x4plus',
|
default='realesr-animevideov3',
|
||||||
help=('Model names: RealESRGAN_x4plus | RealESRNet_x4plus | RealESRGAN_x4plus_anime_6B | RealESRGAN_x2plus'
|
help=('Model names: realesr-animevideov3 | RealESRGAN_x4plus_anime_6B | RealESRGAN_x4plus | RealESRNet_x4plus |'
|
||||||
'RealESRGANv2-anime-xsx2 | RealESRGANv2-animevideo-xsx2-nousm | RealESRGANv2-animevideo-xsx2'
|
' RealESRGAN_x2plus | realesr-general-x4v3'
|
||||||
'RealESRGANv2-anime-xsx4 | RealESRGANv2-animevideo-xsx4-nousm | RealESRGANv2-animevideo-xsx4'))
|
'Default:realesr-animevideov3'))
|
||||||
parser.add_argument('-o', '--output', type=str, default='results', help='Output folder')
|
parser.add_argument('-o', '--output', type=str, default='results', help='Output folder')
|
||||||
|
parser.add_argument(
|
||||||
|
'-dn',
|
||||||
|
'--denoise_strength',
|
||||||
|
type=float,
|
||||||
|
default=0.5,
|
||||||
|
help=('Denoise strength. 0 for weak denoise (keep noise), 1 for strong denoise ability. '
|
||||||
|
'Only used for the realesr-general-x4v3 model'))
|
||||||
parser.add_argument('-s', '--outscale', type=float, default=4, help='The final upsampling scale of the image')
|
parser.add_argument('-s', '--outscale', type=float, default=4, help='The final upsampling scale of the image')
|
||||||
parser.add_argument('--suffix', type=str, default='out', help='Suffix of the restored video')
|
parser.add_argument('--suffix', type=str, default='out', help='Suffix of the restored video')
|
||||||
parser.add_argument('-t', '--tile', type=int, default=0, help='Tile size, 0 for no tile during testing')
|
parser.add_argument('-t', '--tile', type=int, default=0, help='Tile size, 0 for no tile during testing')
|
||||||
parser.add_argument('--tile_pad', type=int, default=10, help='Tile padding')
|
parser.add_argument('--tile_pad', type=int, default=10, help='Tile padding')
|
||||||
parser.add_argument('--pre_pad', type=int, default=0, help='Pre padding size at each border')
|
parser.add_argument('--pre_pad', type=int, default=0, help='Pre padding size at each border')
|
||||||
parser.add_argument('--face_enhance', action='store_true', help='Use GFPGAN to enhance face')
|
parser.add_argument('--face_enhance', action='store_true', help='Use GFPGAN to enhance face')
|
||||||
parser.add_argument('--half', action='store_true', help='Use half precision during inference')
|
parser.add_argument(
|
||||||
parser.add_argument('-v', '--video', action='store_true', help='Output a video using ffmpeg')
|
'--fp32', action='store_true', help='Use fp32 precision during inference. Default: fp16 (half precision).')
|
||||||
parser.add_argument('-a', '--audio', action='store_true', help='Keep audio')
|
|
||||||
parser.add_argument('--fps', type=float, default=None, help='FPS of the output video')
|
parser.add_argument('--fps', type=float, default=None, help='FPS of the output video')
|
||||||
parser.add_argument('--consumer', type=int, default=4, help='Number of IO consumers')
|
parser.add_argument('--ffmpeg_bin', type=str, default='ffmpeg', help='The path to ffmpeg')
|
||||||
|
parser.add_argument('--extract_frame_first', action='store_true')
|
||||||
|
parser.add_argument('--num_process_per_gpu', type=int, default=1)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--alpha_upsampler',
|
'--alpha_upsampler',
|
||||||
@@ -53,146 +371,27 @@ def main():
|
|||||||
help='Image extension. Options: auto | jpg | png, auto means using the same extension as inputs')
|
help='Image extension. Options: auto | jpg | png, auto means using the same extension as inputs')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# ---------------------- determine models according to model names ---------------------- #
|
args.input = args.input.rstrip('/').rstrip('\\')
|
||||||
args.model_name = args.model_name.split('.')[0]
|
|
||||||
if args.model_name in ['RealESRGAN_x4plus', 'RealESRNet_x4plus']: # x4 RRDBNet model
|
|
||||||
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
|
||||||
netscale = 4
|
|
||||||
elif args.model_name in ['RealESRGAN_x4plus_anime_6B']: # x4 RRDBNet model with 6 blocks
|
|
||||||
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4)
|
|
||||||
netscale = 4
|
|
||||||
elif args.model_name in ['RealESRGAN_x2plus']: # x2 RRDBNet model
|
|
||||||
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
|
|
||||||
netscale = 2
|
|
||||||
elif args.model_name in [
|
|
||||||
'RealESRGANv2-anime-xsx2', 'RealESRGANv2-animevideo-xsx2-nousm', 'RealESRGANv2-animevideo-xsx2'
|
|
||||||
]: # x2 VGG-style model (XS size)
|
|
||||||
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=2, act_type='prelu')
|
|
||||||
netscale = 2
|
|
||||||
elif args.model_name in [
|
|
||||||
'RealESRGANv2-anime-xsx4', 'RealESRGANv2-animevideo-xsx4-nousm', 'RealESRGANv2-animevideo-xsx4'
|
|
||||||
]: # x4 VGG-style model (XS size)
|
|
||||||
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu')
|
|
||||||
netscale = 4
|
|
||||||
|
|
||||||
# ---------------------- determine model paths ---------------------- #
|
|
||||||
model_path = os.path.join('experiments/pretrained_models', args.model_name + '.pth')
|
|
||||||
if not os.path.isfile(model_path):
|
|
||||||
model_path = os.path.join('realesrgan/weights', args.model_name + '.pth')
|
|
||||||
if not os.path.isfile(model_path):
|
|
||||||
raise ValueError(f'Model {args.model_name} does not exist.')
|
|
||||||
|
|
||||||
# restorer
|
|
||||||
upsampler = RealESRGANer(
|
|
||||||
scale=netscale,
|
|
||||||
model_path=model_path,
|
|
||||||
model=model,
|
|
||||||
tile=args.tile,
|
|
||||||
tile_pad=args.tile_pad,
|
|
||||||
pre_pad=args.pre_pad,
|
|
||||||
half=args.half)
|
|
||||||
|
|
||||||
if args.face_enhance: # Use GFPGAN for face enhancement
|
|
||||||
from gfpgan import GFPGANer
|
|
||||||
face_enhancer = GFPGANer(
|
|
||||||
model_path='https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth',
|
|
||||||
upscale=args.outscale,
|
|
||||||
arch='clean',
|
|
||||||
channel_multiplier=2,
|
|
||||||
bg_upsampler=upsampler)
|
|
||||||
os.makedirs(args.output, exist_ok=True)
|
os.makedirs(args.output, exist_ok=True)
|
||||||
# for saving restored frames
|
|
||||||
save_frame_folder = os.path.join(args.output, 'frames_tmpout')
|
|
||||||
os.makedirs(save_frame_folder, exist_ok=True)
|
|
||||||
|
|
||||||
if mimetypes.guess_type(args.input)[0].startswith('video'): # is a video file
|
if mimetypes.guess_type(args.input)[0] is not None and mimetypes.guess_type(args.input)[0].startswith('video'):
|
||||||
video_name = os.path.splitext(os.path.basename(args.input))[0]
|
is_video = True
|
||||||
frame_folder = os.path.join('tmp_frames', video_name)
|
|
||||||
os.makedirs(frame_folder, exist_ok=True)
|
|
||||||
# use ffmpeg to extract frames
|
|
||||||
os.system(f'ffmpeg -i {args.input} -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 {frame_folder}/frame%08d.png')
|
|
||||||
# get image path list
|
|
||||||
paths = sorted(glob.glob(os.path.join(frame_folder, '*')))
|
|
||||||
if args.video:
|
|
||||||
if args.fps is None:
|
|
||||||
# get input video fps
|
|
||||||
import ffmpeg
|
|
||||||
probe = ffmpeg.probe(args.input)
|
|
||||||
video_streams = [stream for stream in probe['streams'] if stream['codec_type'] == 'video']
|
|
||||||
args.fps = eval(video_streams[0]['avg_frame_rate'])
|
|
||||||
elif mimetypes.guess_type(args.input)[0].startswith('image'): # is an image file
|
|
||||||
paths = [args.input]
|
|
||||||
video_name = 'video'
|
|
||||||
else:
|
else:
|
||||||
paths = sorted(glob.glob(os.path.join(args.input, '*')))
|
is_video = False
|
||||||
video_name = 'video'
|
|
||||||
|
|
||||||
timer = AvgTimer()
|
if is_video and args.input.endswith('.flv'):
|
||||||
timer.start()
|
mp4_path = args.input.replace('.flv', '.mp4')
|
||||||
pbar = tqdm(total=len(paths), unit='frame', desc='inference')
|
os.system(f'ffmpeg -i {args.input} -codec copy {mp4_path}')
|
||||||
# set up prefetch reader
|
args.input = mp4_path
|
||||||
reader = PrefetchReader(paths, num_prefetch_queue=4)
|
|
||||||
reader.start()
|
|
||||||
|
|
||||||
que = queue.Queue()
|
if args.extract_frame_first and not is_video:
|
||||||
consumers = [IOConsumer(args, que, f'IO_{i}') for i in range(args.consumer)]
|
args.extract_frame_first = False
|
||||||
for consumer in consumers:
|
|
||||||
consumer.start()
|
|
||||||
|
|
||||||
for idx, (path, img) in enumerate(zip(paths, reader)):
|
run(args)
|
||||||
imgname, extension = os.path.splitext(os.path.basename(path))
|
|
||||||
if len(img.shape) == 3 and img.shape[2] == 4:
|
|
||||||
img_mode = 'RGBA'
|
|
||||||
else:
|
|
||||||
img_mode = None
|
|
||||||
|
|
||||||
try:
|
if args.extract_frame_first:
|
||||||
if args.face_enhance:
|
tmp_frames_folder = osp.join(args.output, f'{args.video_name}_inp_tmp_frames')
|
||||||
_, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
|
shutil.rmtree(tmp_frames_folder)
|
||||||
else:
|
|
||||||
output, _ = upsampler.enhance(img, outscale=args.outscale)
|
|
||||||
except RuntimeError as error:
|
|
||||||
print('Error', error)
|
|
||||||
print('If you encounter CUDA out of memory, try to set --tile with a smaller number.')
|
|
||||||
|
|
||||||
else:
|
|
||||||
if args.ext == 'auto':
|
|
||||||
extension = extension[1:]
|
|
||||||
else:
|
|
||||||
extension = args.ext
|
|
||||||
if img_mode == 'RGBA': # RGBA images should be saved in png format
|
|
||||||
extension = 'png'
|
|
||||||
save_path = os.path.join(save_frame_folder, f'{imgname}_out.{extension}')
|
|
||||||
|
|
||||||
que.put({'output': output, 'save_path': save_path})
|
|
||||||
|
|
||||||
pbar.update(1)
|
|
||||||
torch.cuda.synchronize()
|
|
||||||
timer.record()
|
|
||||||
avg_fps = 1. / (timer.get_avg_time() + 1e-7)
|
|
||||||
pbar.set_description(f'idx {idx}, fps {avg_fps:.2f}')
|
|
||||||
|
|
||||||
for _ in range(args.consumer):
|
|
||||||
que.put('quit')
|
|
||||||
for consumer in consumers:
|
|
||||||
consumer.join()
|
|
||||||
pbar.close()
|
|
||||||
|
|
||||||
# merge frames to video
|
|
||||||
if args.video:
|
|
||||||
video_save_path = os.path.join(args.output, f'{video_name}_{args.suffix}.mp4')
|
|
||||||
if args.audio:
|
|
||||||
os.system(
|
|
||||||
f'ffmpeg -r {args.fps} -i {save_frame_folder}/frame%08d_out.{extension} -i {args.input}'
|
|
||||||
f' -map 0:v:0 -map 1:a:0 -c:a copy -c:v libx264 -r {args.fps} -pix_fmt yuv420p {video_save_path}')
|
|
||||||
else:
|
|
||||||
os.system(f'ffmpeg -i {save_frame_folder}/frame%08d_out.{extension} '
|
|
||||||
f'-c:v libx264 -r {args.fps} -pix_fmt yuv420p {video_save_path}')
|
|
||||||
|
|
||||||
# delete tmp file
|
|
||||||
shutil.rmtree(save_frame_folder)
|
|
||||||
if os.path.isdir(frame_folder):
|
|
||||||
shutil.rmtree(frame_folder)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
BIN
inputs/00017_gray.png
Normal file
|
After Width: | Height: | Size: 68 KiB |
BIN
inputs/children-alpha.png
Normal file
|
After Width: | Height: | Size: 268 KiB |
@@ -26,7 +26,17 @@ class RealESRGANer():
|
|||||||
half (float): Whether to use half precision during inference. Default: False.
|
half (float): Whether to use half precision during inference. Default: False.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, scale, model_path, model=None, tile=0, tile_pad=10, pre_pad=10, half=False):
|
def __init__(self,
|
||||||
|
scale,
|
||||||
|
model_path,
|
||||||
|
dni_weight=None,
|
||||||
|
model=None,
|
||||||
|
tile=0,
|
||||||
|
tile_pad=10,
|
||||||
|
pre_pad=10,
|
||||||
|
half=False,
|
||||||
|
device=None,
|
||||||
|
gpu_id=None):
|
||||||
self.scale = scale
|
self.scale = scale
|
||||||
self.tile_size = tile
|
self.tile_size = tile
|
||||||
self.tile_pad = tile_pad
|
self.tile_pad = tile_pad
|
||||||
@@ -35,23 +45,46 @@ class RealESRGANer():
|
|||||||
self.half = half
|
self.half = half
|
||||||
|
|
||||||
# initialize model
|
# initialize model
|
||||||
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
if gpu_id:
|
||||||
# if the model_path starts with https, it will first download models to the folder: realesrgan/weights
|
self.device = torch.device(
|
||||||
|
f'cuda:{gpu_id}' if torch.cuda.is_available() else 'cpu') if device is None else device
|
||||||
|
else:
|
||||||
|
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') if device is None else device
|
||||||
|
|
||||||
|
if isinstance(model_path, list):
|
||||||
|
# dni
|
||||||
|
assert len(model_path) == len(dni_weight), 'model_path and dni_weight should have the save length.'
|
||||||
|
loadnet = self.dni(model_path[0], model_path[1], dni_weight)
|
||||||
|
else:
|
||||||
|
# if the model_path starts with https, it will first download models to the folder: weights
|
||||||
if model_path.startswith('https://'):
|
if model_path.startswith('https://'):
|
||||||
model_path = load_file_from_url(
|
model_path = load_file_from_url(
|
||||||
url=model_path, model_dir=os.path.join(ROOT_DIR, 'realesrgan/weights'), progress=True, file_name=None)
|
url=model_path, model_dir=os.path.join(ROOT_DIR, 'weights'), progress=True, file_name=None)
|
||||||
loadnet = torch.load(model_path, map_location=torch.device('cpu'))
|
loadnet = torch.load(model_path, map_location=torch.device('cpu'))
|
||||||
|
|
||||||
# prefer to use params_ema
|
# prefer to use params_ema
|
||||||
if 'params_ema' in loadnet:
|
if 'params_ema' in loadnet:
|
||||||
keyname = 'params_ema'
|
keyname = 'params_ema'
|
||||||
else:
|
else:
|
||||||
keyname = 'params'
|
keyname = 'params'
|
||||||
model.load_state_dict(loadnet[keyname], strict=True)
|
model.load_state_dict(loadnet[keyname], strict=True)
|
||||||
|
|
||||||
model.eval()
|
model.eval()
|
||||||
self.model = model.to(self.device)
|
self.model = model.to(self.device)
|
||||||
if self.half:
|
if self.half:
|
||||||
self.model = self.model.half()
|
self.model = self.model.half()
|
||||||
|
|
||||||
|
def dni(self, net_a, net_b, dni_weight, key='params', loc='cpu'):
|
||||||
|
"""Deep network interpolation.
|
||||||
|
|
||||||
|
``Paper: Deep Network Interpolation for Continuous Imagery Effect Transition``
|
||||||
|
"""
|
||||||
|
net_a = torch.load(net_a, map_location=torch.device(loc))
|
||||||
|
net_b = torch.load(net_b, map_location=torch.device(loc))
|
||||||
|
for k, v_a in net_a[key].items():
|
||||||
|
net_a[key][k] = dni_weight[0] * v_a + dni_weight[1] * net_b[key][k]
|
||||||
|
return net_a
|
||||||
|
|
||||||
def pre_process(self, img):
|
def pre_process(self, img):
|
||||||
"""Pre-process, such as pre-pad and mod pad, so that the images can be divisible
|
"""Pre-process, such as pre-pad and mod pad, so that the images can be divisible
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
basicsr>=1.3.3.11
|
basicsr>=1.4.2
|
||||||
facexlib>=0.2.0.3
|
facexlib>=0.2.5
|
||||||
gfpgan>=0.2.1
|
gfpgan>=1.3.5
|
||||||
numpy
|
numpy
|
||||||
opencv-python
|
opencv-python
|
||||||
Pillow
|
Pillow
|
||||||
|
|||||||