Spaces:
Runtime error
Runtime error
Upload 247 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- LICENSE +28 -0
- README.md +2 -13
- README_HG.md +12 -0
- RealESRGANv030/.github/workflows/no-response.yml +33 -0
- RealESRGANv030/.github/workflows/publish-pip.yml +33 -0
- RealESRGANv030/.github/workflows/pylint.yml +31 -0
- RealESRGANv030/.github/workflows/release.yml +41 -0
- RealESRGANv030/.gitignore +140 -0
- RealESRGANv030/.pre-commit-config.yaml +46 -0
- RealESRGANv030/.vscode/settings.json +19 -0
- RealESRGANv030/CODE_OF_CONDUCT.md +128 -0
- RealESRGANv030/LICENSE +29 -0
- RealESRGANv030/MANIFEST.in +8 -0
- RealESRGANv030/README.md +272 -0
- RealESRGANv030/README_CN.md +276 -0
- RealESRGANv030/VERSION +1 -0
- RealESRGANv030/__init__.py +0 -0
- RealESRGANv030/assets/realesrgan_logo.png +0 -0
- RealESRGANv030/assets/realesrgan_logo_ai.png +0 -0
- RealESRGANv030/assets/realesrgan_logo_av.png +0 -0
- RealESRGANv030/assets/realesrgan_logo_gi.png +0 -0
- RealESRGANv030/assets/realesrgan_logo_gv.png +0 -0
- RealESRGANv030/assets/teaser-text.png +0 -0
- RealESRGANv030/assets/teaser.jpg +0 -0
- RealESRGANv030/cog.yaml +22 -0
- RealESRGANv030/cog_predict.py +148 -0
- RealESRGANv030/docs/CONTRIBUTING.md +44 -0
- RealESRGANv030/docs/FAQ.md +10 -0
- RealESRGANv030/docs/Training.md +271 -0
- RealESRGANv030/docs/Training_CN.md +271 -0
- RealESRGANv030/docs/anime_comparisons.md +66 -0
- RealESRGANv030/docs/anime_comparisons_CN.md +68 -0
- RealESRGANv030/docs/anime_model.md +68 -0
- RealESRGANv030/docs/anime_video_model.md +136 -0
- RealESRGANv030/docs/feedback.md +11 -0
- RealESRGANv030/docs/model_zoo.md +49 -0
- RealESRGANv030/docs/ncnn_conversion.md +11 -0
- RealESRGANv030/experiments/pretrained_models/README.md +1 -0
- RealESRGANv030/inference_realesrgan.py +166 -0
- RealESRGANv030/inference_realesrgan_video.py +398 -0
- RealESRGANv030/inputs/00003.png +0 -0
- RealESRGANv030/inputs/00017_gray.png +0 -0
- RealESRGANv030/inputs/0014.jpg +0 -0
- RealESRGANv030/inputs/0030.jpg +0 -0
- RealESRGANv030/inputs/ADE_val_00000114.jpg +0 -0
- RealESRGANv030/inputs/OST_009.png +0 -0
- RealESRGANv030/inputs/children-alpha.png +0 -0
- RealESRGANv030/inputs/tree_alpha_16bit.png +0 -0
- RealESRGANv030/inputs/video/onepiece_demo.mp4 +0 -0
.gitattributes
CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
results/00003_out.png filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
BSD 3-Clause License
|
2 |
+
|
3 |
+
Copyright (c) 2023, Mension
|
4 |
+
|
5 |
+
Redistribution and use in source and binary forms, with or without
|
6 |
+
modification, are permitted provided that the following conditions are met:
|
7 |
+
|
8 |
+
1. Redistributions of source code must retain the above copyright notice, this
|
9 |
+
list of conditions and the following disclaimer.
|
10 |
+
|
11 |
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
12 |
+
this list of conditions and the following disclaimer in the documentation
|
13 |
+
and/or other materials provided with the distribution.
|
14 |
+
|
15 |
+
3. Neither the name of the copyright holder nor the names of its
|
16 |
+
contributors may be used to endorse or promote products derived from
|
17 |
+
this software without specific prior written permission.
|
18 |
+
|
19 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
20 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
23 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
README.md
CHANGED
@@ -1,13 +1,2 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
emoji: 🚀
|
4 |
-
colorFrom: gray
|
5 |
-
colorTo: indigo
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 3.16.1
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: bsd-3-clause-clear
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
# Real-ESRGAN-Enhanced-Anime-Diffusion
|
2 |
+
Generate high resolution and quality anime pictures from texts or existed images.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README_HG.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Anything V3.0
|
3 |
+
emoji: 🏃
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.10.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
11 |
+
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
RealESRGANv030/.github/workflows/no-response.yml
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: No Response
|
2 |
+
|
3 |
+
# TODO: it seems not to work
|
4 |
+
# Modified from: https://raw.githubusercontent.com/github/docs/main/.github/workflows/no-response.yaml
|
5 |
+
|
6 |
+
# **What it does**: Closes issues that don't have enough information to be actionable.
|
7 |
+
# **Why we have it**: To remove the need for maintainers to remember to check back on issues periodically
|
8 |
+
# to see if contributors have responded.
|
9 |
+
# **Who does it impact**: Everyone that works on docs or docs-internal.
|
10 |
+
|
11 |
+
on:
|
12 |
+
issue_comment:
|
13 |
+
types: [created]
|
14 |
+
|
15 |
+
schedule:
|
16 |
+
# Schedule for five minutes after the hour every hour
|
17 |
+
- cron: '5 * * * *'
|
18 |
+
|
19 |
+
jobs:
|
20 |
+
noResponse:
|
21 |
+
runs-on: ubuntu-latest
|
22 |
+
steps:
|
23 |
+
- uses: lee-dohm/no-response@v0.5.0
|
24 |
+
with:
|
25 |
+
token: ${{ github.token }}
|
26 |
+
closeComment: >
|
27 |
+
This issue has been automatically closed because there has been no response
|
28 |
+
to our request for more information from the original author. With only the
|
29 |
+
information that is currently in the issue, we don't have enough information
|
30 |
+
to take action. Please reach out if you have or find the answers we need so
|
31 |
+
that we can investigate further.
|
32 |
+
If you still have questions, please improve your description and re-open it.
|
33 |
+
Thanks :-)
|
RealESRGANv030/.github/workflows/publish-pip.yml
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: PyPI Publish
|
2 |
+
|
3 |
+
on: push
|
4 |
+
|
5 |
+
jobs:
|
6 |
+
build-n-publish:
|
7 |
+
runs-on: ubuntu-latest
|
8 |
+
if: startsWith(github.event.ref, 'refs/tags')
|
9 |
+
|
10 |
+
steps:
|
11 |
+
- uses: actions/checkout@v2
|
12 |
+
- name: Set up Python 3.8
|
13 |
+
uses: actions/setup-python@v1
|
14 |
+
with:
|
15 |
+
python-version: 3.8
|
16 |
+
- name: Upgrade pip
|
17 |
+
run: pip install pip --upgrade
|
18 |
+
- name: Install PyTorch (cpu)
|
19 |
+
run: pip install torch==1.7.0+cpu torchvision==0.8.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
|
20 |
+
- name: Install dependencies
|
21 |
+
run: |
|
22 |
+
pip install basicsr
|
23 |
+
pip install facexlib
|
24 |
+
pip install gfpgan
|
25 |
+
pip install -r requirements.txt
|
26 |
+
- name: Build and install
|
27 |
+
run: rm -rf .eggs && pip install -e .
|
28 |
+
- name: Build for distribution
|
29 |
+
run: python setup.py sdist bdist_wheel
|
30 |
+
- name: Publish distribution to PyPI
|
31 |
+
uses: pypa/gh-action-pypi-publish@master
|
32 |
+
with:
|
33 |
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
RealESRGANv030/.github/workflows/pylint.yml
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: PyLint
|
2 |
+
|
3 |
+
on: [push, pull_request]
|
4 |
+
|
5 |
+
jobs:
|
6 |
+
build:
|
7 |
+
|
8 |
+
runs-on: ubuntu-latest
|
9 |
+
strategy:
|
10 |
+
matrix:
|
11 |
+
python-version: [3.8]
|
12 |
+
|
13 |
+
steps:
|
14 |
+
- uses: actions/checkout@v2
|
15 |
+
- name: Set up Python ${{ matrix.python-version }}
|
16 |
+
uses: actions/setup-python@v2
|
17 |
+
with:
|
18 |
+
python-version: ${{ matrix.python-version }}
|
19 |
+
|
20 |
+
- name: Install dependencies
|
21 |
+
run: |
|
22 |
+
python -m pip install --upgrade pip
|
23 |
+
pip install codespell flake8 isort yapf
|
24 |
+
|
25 |
+
# modify the folders accordingly
|
26 |
+
- name: Lint
|
27 |
+
run: |
|
28 |
+
codespell
|
29 |
+
flake8 .
|
30 |
+
isort --check-only --diff realesrgan/ scripts/ inference_realesrgan.py setup.py
|
31 |
+
yapf -r -d realesrgan/ scripts/ inference_realesrgan.py setup.py
|
RealESRGANv030/.github/workflows/release.yml
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: release
|
2 |
+
on:
|
3 |
+
push:
|
4 |
+
tags:
|
5 |
+
- '*'
|
6 |
+
|
7 |
+
jobs:
|
8 |
+
build:
|
9 |
+
permissions: write-all
|
10 |
+
name: Create Release
|
11 |
+
runs-on: ubuntu-latest
|
12 |
+
steps:
|
13 |
+
- name: Checkout code
|
14 |
+
uses: actions/checkout@v2
|
15 |
+
- name: Create Release
|
16 |
+
id: create_release
|
17 |
+
uses: actions/create-release@v1
|
18 |
+
env:
|
19 |
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
20 |
+
with:
|
21 |
+
tag_name: ${{ github.ref }}
|
22 |
+
release_name: Real-ESRGAN ${{ github.ref }} Release Note
|
23 |
+
body: |
|
24 |
+
🚀 See you again 😸
|
25 |
+
🚀Have a nice day 😸 and happy everyday 😃
|
26 |
+
🚀 Long time no see ☄️
|
27 |
+
|
28 |
+
✨ **Highlights**
|
29 |
+
✅ [Features] Support ...
|
30 |
+
|
31 |
+
🐛 **Bug Fixes**
|
32 |
+
|
33 |
+
🌴 **Improvements**
|
34 |
+
|
35 |
+
📢📢📢
|
36 |
+
|
37 |
+
<p align="center">
|
38 |
+
<img src="https://raw.githubusercontent.com/xinntao/Real-ESRGAN/master/assets/realesrgan_logo.png" height=150>
|
39 |
+
</p>
|
40 |
+
draft: true
|
41 |
+
prerelease: false
|
RealESRGANv030/.gitignore
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ignored folders
|
2 |
+
datasets/*
|
3 |
+
experiments/*
|
4 |
+
results/*
|
5 |
+
tb_logger/*
|
6 |
+
wandb/*
|
7 |
+
tmp/*
|
8 |
+
weights/*
|
9 |
+
|
10 |
+
version.py
|
11 |
+
|
12 |
+
# Byte-compiled / optimized / DLL files
|
13 |
+
__pycache__/
|
14 |
+
*.py[cod]
|
15 |
+
*$py.class
|
16 |
+
|
17 |
+
# C extensions
|
18 |
+
*.so
|
19 |
+
|
20 |
+
# Distribution / packaging
|
21 |
+
.Python
|
22 |
+
build/
|
23 |
+
develop-eggs/
|
24 |
+
dist/
|
25 |
+
downloads/
|
26 |
+
eggs/
|
27 |
+
.eggs/
|
28 |
+
lib/
|
29 |
+
lib64/
|
30 |
+
parts/
|
31 |
+
sdist/
|
32 |
+
var/
|
33 |
+
wheels/
|
34 |
+
pip-wheel-metadata/
|
35 |
+
share/python-wheels/
|
36 |
+
*.egg-info/
|
37 |
+
.installed.cfg
|
38 |
+
*.egg
|
39 |
+
MANIFEST
|
40 |
+
|
41 |
+
# PyInstaller
|
42 |
+
# Usually these files are written by a python script from a template
|
43 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
44 |
+
*.manifest
|
45 |
+
*.spec
|
46 |
+
|
47 |
+
# Installer logs
|
48 |
+
pip-log.txt
|
49 |
+
pip-delete-this-directory.txt
|
50 |
+
|
51 |
+
# Unit test / coverage reports
|
52 |
+
htmlcov/
|
53 |
+
.tox/
|
54 |
+
.nox/
|
55 |
+
.coverage
|
56 |
+
.coverage.*
|
57 |
+
.cache
|
58 |
+
nosetests.xml
|
59 |
+
coverage.xml
|
60 |
+
*.cover
|
61 |
+
*.py,cover
|
62 |
+
.hypothesis/
|
63 |
+
.pytest_cache/
|
64 |
+
|
65 |
+
# Translations
|
66 |
+
*.mo
|
67 |
+
*.pot
|
68 |
+
|
69 |
+
# Django stuff:
|
70 |
+
*.log
|
71 |
+
local_settings.py
|
72 |
+
db.sqlite3
|
73 |
+
db.sqlite3-journal
|
74 |
+
|
75 |
+
# Flask stuff:
|
76 |
+
instance/
|
77 |
+
.webassets-cache
|
78 |
+
|
79 |
+
# Scrapy stuff:
|
80 |
+
.scrapy
|
81 |
+
|
82 |
+
# Sphinx documentation
|
83 |
+
docs/_build/
|
84 |
+
|
85 |
+
# PyBuilder
|
86 |
+
target/
|
87 |
+
|
88 |
+
# Jupyter Notebook
|
89 |
+
.ipynb_checkpoints
|
90 |
+
|
91 |
+
# IPython
|
92 |
+
profile_default/
|
93 |
+
ipython_config.py
|
94 |
+
|
95 |
+
# pyenv
|
96 |
+
.python-version
|
97 |
+
|
98 |
+
# pipenv
|
99 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
100 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
101 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
102 |
+
# install all needed dependencies.
|
103 |
+
#Pipfile.lock
|
104 |
+
|
105 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
106 |
+
__pypackages__/
|
107 |
+
|
108 |
+
# Celery stuff
|
109 |
+
celerybeat-schedule
|
110 |
+
celerybeat.pid
|
111 |
+
|
112 |
+
# SageMath parsed files
|
113 |
+
*.sage.py
|
114 |
+
|
115 |
+
# Environments
|
116 |
+
.env
|
117 |
+
.venv
|
118 |
+
env/
|
119 |
+
venv/
|
120 |
+
ENV/
|
121 |
+
env.bak/
|
122 |
+
venv.bak/
|
123 |
+
|
124 |
+
# Spyder project settings
|
125 |
+
.spyderproject
|
126 |
+
.spyproject
|
127 |
+
|
128 |
+
# Rope project settings
|
129 |
+
.ropeproject
|
130 |
+
|
131 |
+
# mkdocs documentation
|
132 |
+
/site
|
133 |
+
|
134 |
+
# mypy
|
135 |
+
.mypy_cache/
|
136 |
+
.dmypy.json
|
137 |
+
dmypy.json
|
138 |
+
|
139 |
+
# Pyre type checker
|
140 |
+
.pyre/
|
RealESRGANv030/.pre-commit-config.yaml
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
repos:
|
2 |
+
# flake8
|
3 |
+
- repo: https://github.com/PyCQA/flake8
|
4 |
+
rev: 3.8.3
|
5 |
+
hooks:
|
6 |
+
- id: flake8
|
7 |
+
args: ["--config=setup.cfg", "--ignore=W504, W503"]
|
8 |
+
|
9 |
+
# modify known_third_party
|
10 |
+
- repo: https://github.com/asottile/seed-isort-config
|
11 |
+
rev: v2.2.0
|
12 |
+
hooks:
|
13 |
+
- id: seed-isort-config
|
14 |
+
|
15 |
+
# isort
|
16 |
+
- repo: https://github.com/timothycrosley/isort
|
17 |
+
rev: 5.2.2
|
18 |
+
hooks:
|
19 |
+
- id: isort
|
20 |
+
|
21 |
+
# yapf
|
22 |
+
- repo: https://github.com/pre-commit/mirrors-yapf
|
23 |
+
rev: v0.30.0
|
24 |
+
hooks:
|
25 |
+
- id: yapf
|
26 |
+
|
27 |
+
# codespell
|
28 |
+
- repo: https://github.com/codespell-project/codespell
|
29 |
+
rev: v2.1.0
|
30 |
+
hooks:
|
31 |
+
- id: codespell
|
32 |
+
|
33 |
+
# pre-commit-hooks
|
34 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
35 |
+
rev: v3.2.0
|
36 |
+
hooks:
|
37 |
+
- id: trailing-whitespace # Trim trailing whitespace
|
38 |
+
- id: check-yaml # Attempt to load all yaml files to verify syntax
|
39 |
+
- id: check-merge-conflict # Check for files that contain merge conflict strings
|
40 |
+
- id: double-quote-string-fixer # Replace double quoted strings with single quoted strings
|
41 |
+
- id: end-of-file-fixer # Make sure files end in a newline and only a newline
|
42 |
+
- id: requirements-txt-fixer # Sort entries in requirements.txt and remove incorrect entry for pkg-resources==0.0.0
|
43 |
+
- id: fix-encoding-pragma # Remove the coding pragma: # -*- coding: utf-8 -*-
|
44 |
+
args: ["--remove"]
|
45 |
+
- id: mixed-line-ending # Replace or check mixed line ending
|
46 |
+
args: ["--fix=lf"]
|
RealESRGANv030/.vscode/settings.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"files.trimTrailingWhitespace": true,
|
3 |
+
"editor.wordWrap": "on",
|
4 |
+
"editor.rulers": [
|
5 |
+
80,
|
6 |
+
120
|
7 |
+
],
|
8 |
+
"editor.renderWhitespace": "all",
|
9 |
+
"editor.renderControlCharacters": true,
|
10 |
+
"python.formatting.provider": "yapf",
|
11 |
+
"python.formatting.yapfArgs": [
|
12 |
+
"--style",
|
13 |
+
"{BASED_ON_STYLE = pep8, BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = true, SPLIT_BEFORE_EXPRESSION_AFTER_OPENING_PAREN = true, COLUMN_LIMIT = 120}"
|
14 |
+
],
|
15 |
+
"python.linting.flake8Enabled": true,
|
16 |
+
"python.linting.flake8Args": [
|
17 |
+
"max-line-length=120"
|
18 |
+
],
|
19 |
+
}
|
RealESRGANv030/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Contributor Covenant Code of Conduct
|
2 |
+
|
3 |
+
## Our Pledge
|
4 |
+
|
5 |
+
We as members, contributors, and leaders pledge to make participation in our
|
6 |
+
community a harassment-free experience for everyone, regardless of age, body
|
7 |
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8 |
+
identity and expression, level of experience, education, socio-economic status,
|
9 |
+
nationality, personal appearance, race, religion, or sexual identity
|
10 |
+
and orientation.
|
11 |
+
|
12 |
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13 |
+
diverse, inclusive, and healthy community.
|
14 |
+
|
15 |
+
## Our Standards
|
16 |
+
|
17 |
+
Examples of behavior that contributes to a positive environment for our
|
18 |
+
community include:
|
19 |
+
|
20 |
+
* Demonstrating empathy and kindness toward other people
|
21 |
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22 |
+
* Giving and gracefully accepting constructive feedback
|
23 |
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24 |
+
and learning from the experience
|
25 |
+
* Focusing on what is best not just for us as individuals, but for the
|
26 |
+
overall community
|
27 |
+
|
28 |
+
Examples of unacceptable behavior include:
|
29 |
+
|
30 |
+
* The use of sexualized language or imagery, and sexual attention or
|
31 |
+
advances of any kind
|
32 |
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33 |
+
* Public or private harassment
|
34 |
+
* Publishing others' private information, such as a physical or email
|
35 |
+
address, without their explicit permission
|
36 |
+
* Other conduct which could reasonably be considered inappropriate in a
|
37 |
+
professional setting
|
38 |
+
|
39 |
+
## Enforcement Responsibilities
|
40 |
+
|
41 |
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42 |
+
acceptable behavior and will take appropriate and fair corrective action in
|
43 |
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44 |
+
or harmful.
|
45 |
+
|
46 |
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47 |
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48 |
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49 |
+
decisions when appropriate.
|
50 |
+
|
51 |
+
## Scope
|
52 |
+
|
53 |
+
This Code of Conduct applies within all community spaces, and also applies when
|
54 |
+
an individual is officially representing the community in public spaces.
|
55 |
+
Examples of representing our community include using an official e-mail address,
|
56 |
+
posting via an official social media account, or acting as an appointed
|
57 |
+
representative at an online or offline event.
|
58 |
+
|
59 |
+
## Enforcement
|
60 |
+
|
61 |
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62 |
+
reported to the community leaders responsible for enforcement at
|
63 |
+
xintao.wang@outlook.com or xintaowang@tencent.com.
|
64 |
+
All complaints will be reviewed and investigated promptly and fairly.
|
65 |
+
|
66 |
+
All community leaders are obligated to respect the privacy and security of the
|
67 |
+
reporter of any incident.
|
68 |
+
|
69 |
+
## Enforcement Guidelines
|
70 |
+
|
71 |
+
Community leaders will follow these Community Impact Guidelines in determining
|
72 |
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73 |
+
|
74 |
+
### 1. Correction
|
75 |
+
|
76 |
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77 |
+
unprofessional or unwelcome in the community.
|
78 |
+
|
79 |
+
**Consequence**: A private, written warning from community leaders, providing
|
80 |
+
clarity around the nature of the violation and an explanation of why the
|
81 |
+
behavior was inappropriate. A public apology may be requested.
|
82 |
+
|
83 |
+
### 2. Warning
|
84 |
+
|
85 |
+
**Community Impact**: A violation through a single incident or series
|
86 |
+
of actions.
|
87 |
+
|
88 |
+
**Consequence**: A warning with consequences for continued behavior. No
|
89 |
+
interaction with the people involved, including unsolicited interaction with
|
90 |
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91 |
+
includes avoiding interactions in community spaces as well as external channels
|
92 |
+
like social media. Violating these terms may lead to a temporary or
|
93 |
+
permanent ban.
|
94 |
+
|
95 |
+
### 3. Temporary Ban
|
96 |
+
|
97 |
+
**Community Impact**: A serious violation of community standards, including
|
98 |
+
sustained inappropriate behavior.
|
99 |
+
|
100 |
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101 |
+
communication with the community for a specified period of time. No public or
|
102 |
+
private interaction with the people involved, including unsolicited interaction
|
103 |
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104 |
+
Violating these terms may lead to a permanent ban.
|
105 |
+
|
106 |
+
### 4. Permanent Ban
|
107 |
+
|
108 |
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109 |
+
standards, including sustained inappropriate behavior, harassment of an
|
110 |
+
individual, or aggression toward or disparagement of classes of individuals.
|
111 |
+
|
112 |
+
**Consequence**: A permanent ban from any sort of public interaction within
|
113 |
+
the community.
|
114 |
+
|
115 |
+
## Attribution
|
116 |
+
|
117 |
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118 |
+
version 2.0, available at
|
119 |
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
120 |
+
|
121 |
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
122 |
+
enforcement ladder](https://github.com/mozilla/diversity).
|
123 |
+
|
124 |
+
[homepage]: https://www.contributor-covenant.org
|
125 |
+
|
126 |
+
For answers to common questions about this code of conduct, see the FAQ at
|
127 |
+
https://www.contributor-covenant.org/faq. Translations are available at
|
128 |
+
https://www.contributor-covenant.org/translations.
|
RealESRGANv030/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
BSD 3-Clause License
|
2 |
+
|
3 |
+
Copyright (c) 2021, Xintao Wang
|
4 |
+
All rights reserved.
|
5 |
+
|
6 |
+
Redistribution and use in source and binary forms, with or without
|
7 |
+
modification, are permitted provided that the following conditions are met:
|
8 |
+
|
9 |
+
1. Redistributions of source code must retain the above copyright notice, this
|
10 |
+
list of conditions and the following disclaimer.
|
11 |
+
|
12 |
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
this list of conditions and the following disclaimer in the documentation
|
14 |
+
and/or other materials provided with the distribution.
|
15 |
+
|
16 |
+
3. Neither the name of the copyright holder nor the names of its
|
17 |
+
contributors may be used to endorse or promote products derived from
|
18 |
+
this software without specific prior written permission.
|
19 |
+
|
20 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
RealESRGANv030/MANIFEST.in
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
include assets/*
|
2 |
+
include inputs/*
|
3 |
+
include scripts/*.py
|
4 |
+
include inference_realesrgan.py
|
5 |
+
include VERSION
|
6 |
+
include LICENSE
|
7 |
+
include requirements.txt
|
8 |
+
include weights/README.md
|
RealESRGANv030/README.md
ADDED
@@ -0,0 +1,272 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p align="center">
|
2 |
+
<img src="assets/realesrgan_logo.png" height=120>
|
3 |
+
</p>
|
4 |
+
|
5 |
+
## <div align="center"><b><a href="README.md">English</a> | <a href="README_CN.md">简体中文</a></b></div>
|
6 |
+
|
7 |
+
<div align="center">
|
8 |
+
|
9 |
+
👀[**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)
|
10 |
+
|
11 |
+
[![download](https://img.shields.io/github/downloads/xinntao/Real-ESRGAN/total.svg)](https://github.com/xinntao/Real-ESRGAN/releases)
|
12 |
+
[![PyPI](https://img.shields.io/pypi/v/realesrgan)](https://pypi.org/project/realesrgan/)
|
13 |
+
[![Open issue](https://img.shields.io/github/issues/xinntao/Real-ESRGAN)](https://github.com/xinntao/Real-ESRGAN/issues)
|
14 |
+
[![Closed issue](https://img.shields.io/github/issues-closed/xinntao/Real-ESRGAN)](https://github.com/xinntao/Real-ESRGAN/issues)
|
15 |
+
[![LICENSE](https://img.shields.io/github/license/xinntao/Real-ESRGAN.svg)](https://github.com/xinntao/Real-ESRGAN/blob/master/LICENSE)
|
16 |
+
[![python lint](https://github.com/xinntao/Real-ESRGAN/actions/workflows/pylint.yml/badge.svg)](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/pylint.yml)
|
17 |
+
[![Publish-pip](https://github.com/xinntao/Real-ESRGAN/actions/workflows/publish-pip.yml/badge.svg)](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/publish-pip.yml)
|
18 |
+
|
19 |
+
</div>
|
20 |
+
|
21 |
+
🔥 **AnimeVideo-v3 model (动漫视频小模型)**. Please see [[*anime video models*](docs/anime_video_model.md)] and [[*comparisons*](docs/anime_comparisons.md)]<br>
|
22 |
+
🔥 **RealESRGAN_x4plus_anime_6B** for anime images **(动漫插图模型)**. Please see [[*anime_model*](docs/anime_model.md)]
|
23 |
+
|
24 |
+
<!-- 1. You can try in our website: [ARC Demo](https://arc.tencent.com/en/ai-demos/imgRestore) (now only support RealESRGAN_x4plus_anime_6B) -->
|
25 |
+
1. :boom: **Update** online Replicate demo: [![Replicate](https://img.shields.io/static/v1?label=Demo&message=Replicate&color=blue)](https://replicate.com/xinntao/realesrgan)
|
26 |
+
1. Online Colab demo for Real-ESRGAN: [![Colab](https://img.shields.io/static/v1?label=Demo&message=Colab&color=orange)](https://colab.research.google.com/drive/1k2Zod6kSHEvraybHl50Lys0LerhyTMCo?usp=sharing) **|** Online Colab demo for for Real-ESRGAN (**anime videos**): [![Colab](https://img.shields.io/static/v1?label=Demo&message=Colab&color=orange)](https://colab.research.google.com/drive/1yNl9ORUxxlL4N0keJa2SEPB61imPQd1B?usp=sharing)
|
27 |
+
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)
|
28 |
+
<!-- 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) -->
|
29 |
+
|
30 |
+
Real-ESRGAN aims at developing **Practical Algorithms for General Image/Video Restoration**.<br>
|
31 |
+
We extend the powerful ESRGAN to a practical restoration application (namely, Real-ESRGAN), which is trained with pure synthetic data.
|
32 |
+
|
33 |
+
🌌 Thanks for your valuable feedbacks/suggestions. All the feedbacks are updated in [feedback.md](docs/feedback.md).
|
34 |
+
|
35 |
+
---
|
36 |
+
|
37 |
+
If Real-ESRGAN is helpful, please help to ⭐ this repo or recommend it to your friends 😊 <br>
|
38 |
+
Other recommended projects:<br>
|
39 |
+
▶️ [GFPGAN](https://github.com/TencentARC/GFPGAN): A practical algorithm for real-world face restoration <br>
|
40 |
+
▶️ [BasicSR](https://github.com/xinntao/BasicSR): An open-source image and video restoration toolbox<br>
|
41 |
+
▶️ [facexlib](https://github.com/xinntao/facexlib): A collection that provides useful face-relation functions.<br>
|
42 |
+
▶️ [HandyView](https://github.com/xinntao/HandyView): A PyQt5-based image viewer that is handy for view and comparison <br>
|
43 |
+
▶️ [HandyFigure](https://github.com/xinntao/HandyFigure): Open source of paper figures <br>
|
44 |
+
|
45 |
+
---
|
46 |
+
|
47 |
+
### 📖 Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data
|
48 |
+
|
49 |
+
> [[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>
|
50 |
+
> [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>
|
51 |
+
> [Tencent ARC Lab](https://arc.tencent.com/en/ai-demos/imgRestore); Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences
|
52 |
+
|
53 |
+
<p align="center">
|
54 |
+
<img src="assets/teaser.jpg">
|
55 |
+
</p>
|
56 |
+
|
57 |
+
---
|
58 |
+
|
59 |
+
<!---------------------------------- Updates --------------------------->
|
60 |
+
## 🚩 Updates
|
61 |
+
|
62 |
+
- ✅ 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.
|
63 |
+
- ✅ 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.
|
64 |
+
- ✅ Add small models for anime videos. More details are in [anime video models](docs/anime_video_model.md).
|
65 |
+
- ✅ Add the ncnn implementation [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan).
|
66 |
+
- ✅ 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)
|
67 |
+
- ✅ 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)
|
68 |
+
- ✅ Integrate [GFPGAN](https://github.com/TencentARC/GFPGAN) to support **face enhancement**.
|
69 |
+
- ✅ 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)
|
70 |
+
- ✅ Support arbitrary scale with `--outscale` (It actually further resizes outputs with `LANCZOS4`). Add *RealESRGAN_x2plus.pth* model.
|
71 |
+
- ✅ [The inference code](inference_realesrgan.py) supports: 1) **tile** options; 2) images with **alpha channel**; 3) **gray** images; 4) **16-bit** images.
|
72 |
+
- ✅ The training codes have been released. A detailed guide can be found in [Training.md](docs/Training.md).
|
73 |
+
|
74 |
+
---
|
75 |
+
|
76 |
+
<!---------------------------------- Demo videos --------------------------->
|
77 |
+
## 👀 Demos Videos
|
78 |
+
|
79 |
+
#### Bilibili
|
80 |
+
|
81 |
+
- [大闹天宫片段](https://www.bilibili.com/video/BV1ja41117zb)
|
82 |
+
- [Anime dance cut 动漫魔性舞蹈](https://www.bilibili.com/video/BV1wY4y1L7hT/)
|
83 |
+
- [海贼王片段](https://www.bilibili.com/video/BV1i3411L7Gy/)
|
84 |
+
|
85 |
+
#### YouTube
|
86 |
+
|
87 |
+
## 🔧 Dependencies and Installation
|
88 |
+
|
89 |
+
- Python >= 3.7 (Recommend to use [Anaconda](https://www.anaconda.com/download/#linux) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html))
|
90 |
+
- [PyTorch >= 1.7](https://pytorch.org/)
|
91 |
+
|
92 |
+
### Installation
|
93 |
+
|
94 |
+
1. Clone repo
|
95 |
+
|
96 |
+
```bash
|
97 |
+
git clone https://github.com/xinntao/Real-ESRGAN.git
|
98 |
+
cd Real-ESRGAN
|
99 |
+
```
|
100 |
+
|
101 |
+
1. Install dependent packages
|
102 |
+
|
103 |
+
```bash
|
104 |
+
# Install basicsr - https://github.com/xinntao/BasicSR
|
105 |
+
# We use BasicSR for both training and inference
|
106 |
+
pip install basicsr
|
107 |
+
# facexlib and gfpgan are for face enhancement
|
108 |
+
pip install facexlib
|
109 |
+
pip install gfpgan
|
110 |
+
pip install -r requirements.txt
|
111 |
+
python setup.py develop
|
112 |
+
```
|
113 |
+
|
114 |
+
---
|
115 |
+
|
116 |
+
## ⚡ Quick Inference
|
117 |
+
|
118 |
+
There are usually three ways to inference Real-ESRGAN.
|
119 |
+
|
120 |
+
1. [Online inference](#online-inference)
|
121 |
+
1. [Portable executable files (NCNN)](#portable-executable-files-ncnn)
|
122 |
+
1. [Python script](#python-script)
|
123 |
+
|
124 |
+
### Online inference
|
125 |
+
|
126 |
+
1. You can try in our website: [ARC Demo](https://arc.tencent.com/en/ai-demos/imgRestore) (now only support RealESRGAN_x4plus_anime_6B)
|
127 |
+
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**).
|
128 |
+
|
129 |
+
### Portable executable files (NCNN)
|
130 |
+
|
131 |
+
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**.
|
132 |
+
|
133 |
+
This executable file is **portable** and includes all the binaries and models required. No CUDA or PyTorch environment is needed.<br>
|
134 |
+
|
135 |
+
You can simply run the following command (the Windows example, more information is in the README.md of each executable files):
|
136 |
+
|
137 |
+
```bash
|
138 |
+
./realesrgan-ncnn-vulkan.exe -i input.jpg -o output.png -n model_name
|
139 |
+
```
|
140 |
+
|
141 |
+
We have provided five models:
|
142 |
+
|
143 |
+
1. realesrgan-x4plus (default)
|
144 |
+
2. realesrnet-x4plus
|
145 |
+
3. realesrgan-x4plus-anime (optimized for anime images, small model size)
|
146 |
+
4. realesr-animevideov3 (animation video)
|
147 |
+
|
148 |
+
You can use the `-n` argument for other models, for example, `./realesrgan-ncnn-vulkan.exe -i input.jpg -o output.png -n realesrnet-x4plus`
|
149 |
+
|
150 |
+
#### Usage of portable executable files
|
151 |
+
|
152 |
+
1. Please refer to [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan#computer-usages) for more details.
|
153 |
+
1. Note that it does not support all the functions (such as `outscale`) as the python script `inference_realesrgan.py`.
|
154 |
+
|
155 |
+
```console
|
156 |
+
Usage: realesrgan-ncnn-vulkan.exe -i infile -o outfile [options]...
|
157 |
+
|
158 |
+
-h show this help
|
159 |
+
-i input-path input image path (jpg/png/webp) or directory
|
160 |
+
-o output-path output image path (jpg/png/webp) or directory
|
161 |
+
-s scale upscale ratio (can be 2, 3, 4. default=4)
|
162 |
+
-t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu
|
163 |
+
-m model-path folder path to the pre-trained models. default=models
|
164 |
+
-n model-name model name (default=realesr-animevideov3, can be realesr-animevideov3 | realesrgan-x4plus | realesrgan-x4plus-anime | realesrnet-x4plus)
|
165 |
+
-g gpu-id gpu device to use (default=auto) can be 0,1,2 for multi-gpu
|
166 |
+
-j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu
|
167 |
+
-x enable tta mode"
|
168 |
+
-f format output image format (jpg/png/webp, default=ext/png)
|
169 |
+
-v verbose output
|
170 |
+
```
|
171 |
+
|
172 |
+
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.
|
173 |
+
|
174 |
+
### Python script
|
175 |
+
|
176 |
+
#### Usage of python script
|
177 |
+
|
178 |
+
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.
|
179 |
+
|
180 |
+
```console
|
181 |
+
Usage: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]...
|
182 |
+
|
183 |
+
A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile --outscale 3.5 --face_enhance
|
184 |
+
|
185 |
+
-h show this help
|
186 |
+
-i --input Input image or folder. Default: inputs
|
187 |
+
-o --output Output folder. Default: results
|
188 |
+
-n --model_name Model name. Default: RealESRGAN_x4plus
|
189 |
+
-s, --outscale The final upsampling scale of the image. Default: 4
|
190 |
+
--suffix Suffix of the restored image. Default: out
|
191 |
+
-t, --tile Tile size, 0 for no tile during testing. Default: 0
|
192 |
+
--face_enhance Whether to use GFPGAN to enhance face. Default: False
|
193 |
+
--fp32 Use fp32 precision during inference. Default: fp16 (half precision).
|
194 |
+
--ext Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto
|
195 |
+
```
|
196 |
+
|
197 |
+
#### Inference general images
|
198 |
+
|
199 |
+
Download pre-trained models: [RealESRGAN_x4plus.pth](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth)
|
200 |
+
|
201 |
+
```bash
|
202 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P weights
|
203 |
+
```
|
204 |
+
|
205 |
+
Inference!
|
206 |
+
|
207 |
+
```bash
|
208 |
+
python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance
|
209 |
+
```
|
210 |
+
|
211 |
+
Results are in the `results` folder
|
212 |
+
|
213 |
+
#### Inference anime images
|
214 |
+
|
215 |
+
<p align="center">
|
216 |
+
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_1.png">
|
217 |
+
</p>
|
218 |
+
|
219 |
+
Pre-trained models: [RealESRGAN_x4plus_anime_6B](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth)<br>
|
220 |
+
More details and comparisons with [waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan) are in [**anime_model.md**](docs/anime_model.md)
|
221 |
+
|
222 |
+
```bash
|
223 |
+
# download model
|
224 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights
|
225 |
+
# inference
|
226 |
+
python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
|
227 |
+
```
|
228 |
+
|
229 |
+
Results are in the `results` folder
|
230 |
+
|
231 |
+
---
|
232 |
+
|
233 |
+
## BibTeX
|
234 |
+
|
235 |
+
@InProceedings{wang2021realesrgan,
|
236 |
+
author = {Xintao Wang and Liangbin Xie and Chao Dong and Ying Shan},
|
237 |
+
title = {Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data},
|
238 |
+
booktitle = {International Conference on Computer Vision Workshops (ICCVW)},
|
239 |
+
date = {2021}
|
240 |
+
}
|
241 |
+
|
242 |
+
## 📧 Contact
|
243 |
+
|
244 |
+
If you have any question, please email `xintao.wang@outlook.com` or `xintaowang@tencent.com`.
|
245 |
+
|
246 |
+
<!---------------------------------- Projects that use Real-ESRGAN --------------------------->
|
247 |
+
## 🧩 Projects that use Real-ESRGAN
|
248 |
+
|
249 |
+
If you develop/use Real-ESRGAN in your projects, welcome to let me know.
|
250 |
+
|
251 |
+
- NCNN-Android: [RealSR-NCNN-Android](https://github.com/tumuyan/RealSR-NCNN-Android) by [tumuyan](https://github.com/tumuyan)
|
252 |
+
- VapourSynth: [vs-realesrgan](https://github.com/HolyWu/vs-realesrgan) by [HolyWu](https://github.com/HolyWu)
|
253 |
+
- NCNN: [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan)
|
254 |
+
|
255 |
+
**GUI**
|
256 |
+
|
257 |
+
- [Waifu2x-Extension-GUI](https://github.com/AaronFeng753/Waifu2x-Extension-GUI) by [AaronFeng753](https://github.com/AaronFeng753)
|
258 |
+
- [Squirrel-RIFE](https://github.com/Justin62628/Squirrel-RIFE) by [Justin62628](https://github.com/Justin62628)
|
259 |
+
- [Real-GUI](https://github.com/scifx/Real-GUI) by [scifx](https://github.com/scifx)
|
260 |
+
- [Real-ESRGAN_GUI](https://github.com/net2cn/Real-ESRGAN_GUI) by [net2cn](https://github.com/net2cn)
|
261 |
+
- [Real-ESRGAN-EGUI](https://github.com/WGzeyu/Real-ESRGAN-EGUI) by [WGzeyu](https://github.com/WGzeyu)
|
262 |
+
- [anime_upscaler](https://github.com/shangar21/anime_upscaler) by [shangar21](https://github.com/shangar21)
|
263 |
+
- [Upscayl](https://github.com/upscayl/upscayl) by [Nayam Amarshe](https://github.com/NayamAmarshe) and [TGS963](https://github.com/TGS963)
|
264 |
+
|
265 |
+
## 🤗 Acknowledgement
|
266 |
+
|
267 |
+
Thanks for all the contributors.
|
268 |
+
|
269 |
+
- [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).
|
270 |
+
- [Asiimoviet](https://github.com/Asiimoviet): Translate the README.md to Chinese (中文).
|
271 |
+
- [2ji3150](https://github.com/2ji3150): Thanks for the [detailed and valuable feedbacks/suggestions](https://github.com/xinntao/Real-ESRGAN/issues/131).
|
272 |
+
- [Jared-02](https://github.com/Jared-02): Translate the Training.md to Chinese (中文).
|
RealESRGANv030/README_CN.md
ADDED
@@ -0,0 +1,276 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p align="center">
|
2 |
+
<img src="assets/realesrgan_logo.png" height=120>
|
3 |
+
</p>
|
4 |
+
|
5 |
+
## <div align="center"><b><a href="README.md">English</a> | <a href="README_CN.md">简体中文</a></b></div>
|
6 |
+
|
7 |
+
[![download](https://img.shields.io/github/downloads/xinntao/Real-ESRGAN/total.svg)](https://github.com/xinntao/Real-ESRGAN/releases)
|
8 |
+
[![PyPI](https://img.shields.io/pypi/v/realesrgan)](https://pypi.org/project/realesrgan/)
|
9 |
+
[![Open issue](https://img.shields.io/github/issues/xinntao/Real-ESRGAN)](https://github.com/xinntao/Real-ESRGAN/issues)
|
10 |
+
[![Closed issue](https://img.shields.io/github/issues-closed/xinntao/Real-ESRGAN)](https://github.com/xinntao/Real-ESRGAN/issues)
|
11 |
+
[![LICENSE](https://img.shields.io/github/license/xinntao/Real-ESRGAN.svg)](https://github.com/xinntao/Real-ESRGAN/blob/master/LICENSE)
|
12 |
+
[![python lint](https://github.com/xinntao/Real-ESRGAN/actions/workflows/pylint.yml/badge.svg)](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/pylint.yml)
|
13 |
+
[![Publish-pip](https://github.com/xinntao/Real-ESRGAN/actions/workflows/publish-pip.yml/badge.svg)](https://github.com/xinntao/Real-ESRGAN/blob/master/.github/workflows/publish-pip.yml)
|
14 |
+
|
15 |
+
:fire: 更新动漫视频的小模型 **RealESRGAN AnimeVideo-v3**. 更多信息在 [[动漫视频模型介绍](docs/anime_video_model.md)] 和 [[比较](docs/anime_comparisons_CN.md)] 中.
|
16 |
+
|
17 |
+
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)
|
18 |
+
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)。
|
19 |
+
|
20 |
+
Real-ESRGAN 的目标是开发出**实用的图像/视频修复算法**。<br>
|
21 |
+
我们在 ESRGAN 的基础上使用纯合成的数据来进行训练,以使其能被应用于实际的图片修复的场景(顾名思义:Real-ESRGAN)。
|
22 |
+
|
23 |
+
:art: Real-ESRGAN 需要,也很欢迎你的贡献,如新功能、模型、bug修复、建议、维护等等。详情可以查看[CONTRIBUTING.md](docs/CONTRIBUTING.md),所有的贡献者都会被列在[此处](README_CN.md#hugs-感谢)。
|
24 |
+
|
25 |
+
:milky_way: 感谢大家提供了很好的反馈。这些反馈会逐步更新在 [这个文档](docs/feedback.md)。
|
26 |
+
|
27 |
+
:question: 常见的问题可以在[FAQ.md](docs/FAQ.md)中找到答案。(好吧,现在还是空白的=-=||)
|
28 |
+
|
29 |
+
---
|
30 |
+
|
31 |
+
如果 Real-ESRGAN 对你有帮助,可以给本项目一个 Star :star: ,或者推荐给你的朋友们,谢谢!:blush: <br/>
|
32 |
+
其他推荐的项目:<br/>
|
33 |
+
:arrow_forward: [GFPGAN](https://github.com/TencentARC/GFPGAN): 实用的人脸复原算法 <br>
|
34 |
+
:arrow_forward: [BasicSR](https://github.com/xinntao/BasicSR): 开源的图像和视频工具箱<br>
|
35 |
+
:arrow_forward: [facexlib](https://github.com/xinntao/facexlib): 提供与人脸相关的工具箱<br>
|
36 |
+
:arrow_forward: [HandyView](https://github.com/xinntao/HandyView): 基于PyQt5的图片查看器,方便查看以及比较 <br>
|
37 |
+
|
38 |
+
---
|
39 |
+
|
40 |
+
<!---------------------------------- Updates --------------------------->
|
41 |
+
<details>
|
42 |
+
<summary>🚩<b>更新</b></summary>
|
43 |
+
|
44 |
+
- ✅ 更新动漫视频的小模型 **RealESRGAN AnimeVideo-v3**. 更多信息在 [anime video models](docs/anime_video_model.md) 和 [comparisons](docs/anime_comparisons.md)中.
|
45 |
+
- ✅ 添加了针对动漫视频的小模型, 更多信息在 [anime video models](docs/anime_video_model.md) 中.
|
46 |
+
- ✅ 添加了ncnn 实现:[Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan).
|
47 |
+
- ✅ 添加了 [*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)
|
48 |
+
- ✅支持用户在自己的数据上进行微调 (finetune):[详情](docs/Training.md#Finetune-Real-ESRGAN-on-your-own-dataset)
|
49 |
+
- ✅ 支持使用[GFPGAN](https://github.com/TencentARC/GFPGAN)**增强人脸**
|
50 |
+
- ✅ 通过[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)
|
51 |
+
- ✅ 支持任意比例的缩放:`--outscale`(实际上使用`LANCZOS4`来更进一步调整输出图像的尺寸)。添加了*RealESRGAN_x2plus.pth*模型
|
52 |
+
- ✅ [推断脚本](inference_realesrgan.py)支持: 1) 分块处理**tile**; 2) 带**alpha通道**的图像; 3) **灰色**图像; 4) **16-bit**图像.
|
53 |
+
- ✅ 训练代码已经发布,具体做法可查看:[Training.md](docs/Training.md)。
|
54 |
+
|
55 |
+
</details>
|
56 |
+
|
57 |
+
<!---------------------------------- Projects that use Real-ESRGAN --------------------------->
|
58 |
+
<details>
|
59 |
+
<summary>🧩<b>使用Real-ESRGAN的项目</b></summary>
|
60 |
+
|
61 |
+
👋 如果你开发/使用/集成了Real-ESRGAN, 欢迎联系我添加
|
62 |
+
|
63 |
+
- NCNN-Android: [RealSR-NCNN-Android](https://github.com/tumuyan/RealSR-NCNN-Android) by [tumuyan](https://github.com/tumuyan)
|
64 |
+
- VapourSynth: [vs-realesrgan](https://github.com/HolyWu/vs-realesrgan) by [HolyWu](https://github.com/HolyWu)
|
65 |
+
- NCNN: [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan)
|
66 |
+
|
67 |
+
**易用的图形界面**
|
68 |
+
|
69 |
+
- [Waifu2x-Extension-GUI](https://github.com/AaronFeng753/Waifu2x-Extension-GUI) by [AaronFeng753](https://github.com/AaronFeng753)
|
70 |
+
- [Squirrel-RIFE](https://github.com/Justin62628/Squirrel-RIFE) by [Justin62628](https://github.com/Justin62628)
|
71 |
+
- [Real-GUI](https://github.com/scifx/Real-GUI) by [scifx](https://github.com/scifx)
|
72 |
+
- [Real-ESRGAN_GUI](https://github.com/net2cn/Real-ESRGAN_GUI) by [net2cn](https://github.com/net2cn)
|
73 |
+
- [Real-ESRGAN-EGUI](https://github.com/WGzeyu/Real-ESRGAN-EGUI) by [WGzeyu](https://github.com/WGzeyu)
|
74 |
+
- [anime_upscaler](https://github.com/shangar21/anime_upscaler) by [shangar21](https://github.com/shangar21)
|
75 |
+
- [RealESRGAN-GUI](https://github.com/Baiyuetribe/paper2gui/blob/main/Video%20Super%20Resolution/RealESRGAN-GUI.md) by [Baiyuetribe](https://github.com/Baiyuetribe)
|
76 |
+
|
77 |
+
</details>
|
78 |
+
|
79 |
+
<details>
|
80 |
+
<summary>👀<b>Demo视频(B站)</b></summary>
|
81 |
+
|
82 |
+
- [大闹天宫片段](https://www.bilibili.com/video/BV1ja41117zb)
|
83 |
+
|
84 |
+
</details>
|
85 |
+
|
86 |
+
### :book: Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data
|
87 |
+
|
88 |
+
> [[论文](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>
|
89 |
+
> [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>
|
90 |
+
> Tencent ARC Lab; Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences
|
91 |
+
|
92 |
+
<p align="center">
|
93 |
+
<img src="assets/teaser.jpg">
|
94 |
+
</p>
|
95 |
+
|
96 |
+
---
|
97 |
+
|
98 |
+
我们提供了一套训练好的模型(*RealESRGAN_x4plus.pth*),可以进行4倍的超分辨率。<br>
|
99 |
+
**现在的 Real-ESRGAN 还是有几率失败的,因为现实生活的降质过程比较复杂。**<br>
|
100 |
+
而且,本项目对**人脸以及文字之类**的效果还不是太好,但是我们会持续进行优化的。<br>
|
101 |
+
|
102 |
+
Real-ESRGAN 将会被长期支持,我会在空闲的时间中持续维护更新。
|
103 |
+
|
104 |
+
这些是未来计划的几个新功能:
|
105 |
+
|
106 |
+
- [ ] 优化人脸
|
107 |
+
- [ ] 优化文字
|
108 |
+
- [x] 优化动画图像
|
109 |
+
- [ ] 支持更多的超分辨率比例
|
110 |
+
- [ ] 可调节的复原
|
111 |
+
|
112 |
+
如果你有好主意或需求,欢迎在 issue 或 discussion 中提出。<br/>
|
113 |
+
如果你有一些 Real-ESRGAN 中有问题的照片,你也可以在 issue 或者 discussion 中发出来。我会留意(但是不一定能解决:stuck_out_tongue:)。如果有必要的话,我还会专门开一页来记录那些有待解决的图像。
|
114 |
+
|
115 |
+
---
|
116 |
+
|
117 |
+
### 便携版(绿色版)可执行文件
|
118 |
+
|
119 |
+
你可以下载**支持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)。
|
120 |
+
|
121 |
+
绿色版指的是这些exe你可以直接运行(放U盘里拷走都没问题),因为里面已经有所需的文件和模型了。它不需要 CUDA 或者 PyTorch运行环境。<br>
|
122 |
+
|
123 |
+
你可以通过下面这个命令来运行(Windows版本的例子,更多信息请查看对应版本的README.md):
|
124 |
+
|
125 |
+
```bash
|
126 |
+
./realesrgan-ncnn-vulkan.exe -i 输入图像.jpg -o 输出图像.png -n 模型名字
|
127 |
+
```
|
128 |
+
|
129 |
+
我们提供了五种模型:
|
130 |
+
|
131 |
+
1. realesrgan-x4plus(默认)
|
132 |
+
2. reaesrnet-x4plus
|
133 |
+
3. realesrgan-x4plus-anime(针对动漫插画图像优化,有更小的体积)
|
134 |
+
4. realesr-animevideov3 (针对动漫视频)
|
135 |
+
|
136 |
+
你可以通过`-n`参数来使用其他模型,例如`./realesrgan-ncnn-vulkan.exe -i 二次元图片.jpg -o 二刺螈图片.png -n realesrgan-x4plus-anime`
|
137 |
+
|
138 |
+
### 可执行文件的用法
|
139 |
+
|
140 |
+
1. 更多细节可以参考 [Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan#computer-usages).
|
141 |
+
2. 注意:可执行文件并没有支持 python 脚本 `inference_realesrgan.py` 中所有的功能,比如 `outscale` 选项) .
|
142 |
+
|
143 |
+
```console
|
144 |
+
Usage: realesrgan-ncnn-vulkan.exe -i infile -o outfile [options]...
|
145 |
+
|
146 |
+
-h show this help
|
147 |
+
-i input-path input image path (jpg/png/webp) or directory
|
148 |
+
-o output-path output image path (jpg/png/webp) or directory
|
149 |
+
-s scale upscale ratio (can be 2, 3, 4. default=4)
|
150 |
+
-t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu
|
151 |
+
-m model-path folder path to the pre-trained models. default=models
|
152 |
+
-n model-name model name (default=realesr-animevideov3, can be realesr-animevideov3 | realesrgan-x4plus | realesrgan-x4plus-anime | realesrnet-x4plus)
|
153 |
+
-g gpu-id gpu device to use (default=auto) can be 0,1,2 for multi-gpu
|
154 |
+
-j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu
|
155 |
+
-x enable tta mode"
|
156 |
+
-f format output image format (jpg/png/webp, default=ext/png)
|
157 |
+
-v verbose output
|
158 |
+
```
|
159 |
+
|
160 |
+
由于这些exe文件会把图像分成几个板块,然后来分别进行处理,再合成导出,输出的图像可能会有一点割裂感(而且可能跟PyTorch的输出不太一样)
|
161 |
+
|
162 |
+
---
|
163 |
+
|
164 |
+
## :wrench: 依赖以及安装
|
165 |
+
|
166 |
+
- Python >= 3.7 (推荐使用[Anaconda](https://www.anaconda.com/download/#linux)或[Miniconda](https://docs.conda.io/en/latest/miniconda.html))
|
167 |
+
- [PyTorch >= 1.7](https://pytorch.org/)
|
168 |
+
|
169 |
+
#### 安装
|
170 |
+
|
171 |
+
1. 把项目克隆到本地
|
172 |
+
|
173 |
+
```bash
|
174 |
+
git clone https://github.com/xinntao/Real-ESRGAN.git
|
175 |
+
cd Real-ESRGAN
|
176 |
+
```
|
177 |
+
|
178 |
+
2. 安装各种依赖
|
179 |
+
|
180 |
+
```bash
|
181 |
+
# 安装 basicsr - https://github.com/xinntao/BasicSR
|
182 |
+
# 我们使用BasicSR来训练以及推断
|
183 |
+
pip install basicsr
|
184 |
+
# facexlib和gfpgan是用来增强人脸的
|
185 |
+
pip install facexlib
|
186 |
+
pip install gfpgan
|
187 |
+
pip install -r requirements.txt
|
188 |
+
python setup.py develop
|
189 |
+
```
|
190 |
+
|
191 |
+
## :zap: 快速上手
|
192 |
+
|
193 |
+
### 普通图片
|
194 |
+
|
195 |
+
下载我们训练好的模型: [RealESRGAN_x4plus.pth](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth)
|
196 |
+
|
197 |
+
```bash
|
198 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P weights
|
199 |
+
```
|
200 |
+
|
201 |
+
推断!
|
202 |
+
|
203 |
+
```bash
|
204 |
+
python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance
|
205 |
+
```
|
206 |
+
|
207 |
+
结果在`results`文件夹
|
208 |
+
|
209 |
+
### 动画图片
|
210 |
+
|
211 |
+
<p align="center">
|
212 |
+
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_1.png">
|
213 |
+
</p>
|
214 |
+
|
215 |
+
训练好的模型: [RealESRGAN_x4plus_anime_6B](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth)<br>
|
216 |
+
有关[waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan)的更多信息和对比在[**anime_model.md**](docs/anime_model.md)中。
|
217 |
+
|
218 |
+
```bash
|
219 |
+
# 下载模型
|
220 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights
|
221 |
+
# 推断
|
222 |
+
python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
|
223 |
+
```
|
224 |
+
|
225 |
+
结果在`results`文件夹
|
226 |
+
|
227 |
+
### Python 脚本的用法
|
228 |
+
|
229 |
+
1. 虽然你使用了 X4 模型,但是你可以 **输出任意尺寸比例的图片**,只要实用了 `outscale` 参数. 程序会进一步对模型的输出图像进行缩放。
|
230 |
+
|
231 |
+
```console
|
232 |
+
Usage: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]...
|
233 |
+
|
234 |
+
A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile --outscale 3.5 --face_enhance
|
235 |
+
|
236 |
+
-h show this help
|
237 |
+
-i --input Input image or folder. Default: inputs
|
238 |
+
-o --output Output folder. Default: results
|
239 |
+
-n --model_name Model name. Default: RealESRGAN_x4plus
|
240 |
+
-s, --outscale The final upsampling scale of the image. Default: 4
|
241 |
+
--suffix Suffix of the restored image. Default: out
|
242 |
+
-t, --tile Tile size, 0 for no tile during testing. Default: 0
|
243 |
+
--face_enhance Whether to use GFPGAN to enhance face. Default: False
|
244 |
+
--fp32 Whether to use half precision during inference. Default: False
|
245 |
+
--ext Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto
|
246 |
+
```
|
247 |
+
|
248 |
+
## :european_castle: 模型库
|
249 |
+
|
250 |
+
请参见 [docs/model_zoo.md](docs/model_zoo.md)
|
251 |
+
|
252 |
+
## :computer: 训练,在你的数据上微调(Fine-tune)
|
253 |
+
|
254 |
+
这里有一份详细的指南:[Training.md](docs/Training.md).
|
255 |
+
|
256 |
+
## BibTeX 引用
|
257 |
+
|
258 |
+
@Article{wang2021realesrgan,
|
259 |
+
title={Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data},
|
260 |
+
author={Xintao Wang and Liangbin Xie and Chao Dong and Ying Shan},
|
261 |
+
journal={arXiv:2107.10833},
|
262 |
+
year={2021}
|
263 |
+
}
|
264 |
+
|
265 |
+
## :e-mail: 联系我们
|
266 |
+
|
267 |
+
如果你有任何问题,请通过 `xintao.wang@outlook.com` 或 `xintaowang@tencent.com` 联系我们。
|
268 |
+
|
269 |
+
## :hugs: 感谢
|
270 |
+
|
271 |
+
感谢所有的贡献者大大们~
|
272 |
+
|
273 |
+
- [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)。
|
274 |
+
- [Asiimoviet](https://github.com/Asiimoviet): 把 README.md 文档 翻译成了中文。
|
275 |
+
- [2ji3150](https://github.com/2ji3150): 感谢详尽并且富有价值的[反馈、建议](https://github.com/xinntao/Real-ESRGAN/issues/131).
|
276 |
+
- [Jared-02](https://github.com/Jared-02): 把 Training.md 文档 翻译成了中文。
|
RealESRGANv030/VERSION
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
0.3.0
|
RealESRGANv030/__init__.py
ADDED
File without changes
|
RealESRGANv030/assets/realesrgan_logo.png
ADDED
RealESRGANv030/assets/realesrgan_logo_ai.png
ADDED
RealESRGANv030/assets/realesrgan_logo_av.png
ADDED
RealESRGANv030/assets/realesrgan_logo_gi.png
ADDED
RealESRGANv030/assets/realesrgan_logo_gv.png
ADDED
RealESRGANv030/assets/teaser-text.png
ADDED
RealESRGANv030/assets/teaser.jpg
ADDED
RealESRGANv030/cog.yaml
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file is used for constructing replicate env
|
2 |
+
image: "r8.im/tencentarc/realesrgan"
|
3 |
+
|
4 |
+
build:
|
5 |
+
gpu: true
|
6 |
+
python_version: "3.8"
|
7 |
+
system_packages:
|
8 |
+
- "libgl1-mesa-glx"
|
9 |
+
- "libglib2.0-0"
|
10 |
+
python_packages:
|
11 |
+
- "torch==1.7.1"
|
12 |
+
- "torchvision==0.8.2"
|
13 |
+
- "numpy==1.21.1"
|
14 |
+
- "lmdb==1.2.1"
|
15 |
+
- "opencv-python==4.5.3.56"
|
16 |
+
- "PyYAML==5.4.1"
|
17 |
+
- "tqdm==4.62.2"
|
18 |
+
- "yapf==0.31.0"
|
19 |
+
- "basicsr==1.4.2"
|
20 |
+
- "facexlib==0.2.5"
|
21 |
+
|
22 |
+
predict: "cog_predict.py:Predictor"
|
RealESRGANv030/cog_predict.py
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# flake8: noqa
|
2 |
+
# This file is used for deploying replicate models
|
3 |
+
# running: cog predict -i img=@inputs/00017_gray.png -i version='General - v3' -i scale=2 -i face_enhance=True -i tile=0
|
4 |
+
# push: cog push r8.im/xinntao/realesrgan
|
5 |
+
|
6 |
+
import os
|
7 |
+
|
8 |
+
os.system('pip install gfpgan')
|
9 |
+
os.system('python setup.py develop')
|
10 |
+
|
11 |
+
import cv2
|
12 |
+
import shutil
|
13 |
+
import tempfile
|
14 |
+
import torch
|
15 |
+
from basicsr.archs.rrdbnet_arch import RRDBNet
|
16 |
+
from basicsr.archs.srvgg_arch import SRVGGNetCompact
|
17 |
+
|
18 |
+
from realesrgan.utils import RealESRGANer
|
19 |
+
|
20 |
+
try:
|
21 |
+
from cog import BasePredictor, Input, Path
|
22 |
+
from gfpgan import GFPGANer
|
23 |
+
except Exception:
|
24 |
+
print('please install cog and realesrgan package')
|
25 |
+
|
26 |
+
|
27 |
+
class Predictor(BasePredictor):
|
28 |
+
|
29 |
+
def setup(self):
|
30 |
+
os.makedirs('output', exist_ok=True)
|
31 |
+
# download weights
|
32 |
+
if not os.path.exists('weights/realesr-general-x4v3.pth'):
|
33 |
+
os.system(
|
34 |
+
'wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth -P ./weights'
|
35 |
+
)
|
36 |
+
if not os.path.exists('weights/GFPGANv1.4.pth'):
|
37 |
+
os.system('wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth -P ./weights')
|
38 |
+
if not os.path.exists('weights/RealESRGAN_x4plus.pth'):
|
39 |
+
os.system(
|
40 |
+
'wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P ./weights'
|
41 |
+
)
|
42 |
+
if not os.path.exists('weights/RealESRGAN_x4plus_anime_6B.pth'):
|
43 |
+
os.system(
|
44 |
+
'wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P ./weights'
|
45 |
+
)
|
46 |
+
if not os.path.exists('weights/realesr-animevideov3.pth'):
|
47 |
+
os.system(
|
48 |
+
'wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth -P ./weights'
|
49 |
+
)
|
50 |
+
|
51 |
+
def choose_model(self, scale, version, tile=0):
|
52 |
+
half = True if torch.cuda.is_available() else False
|
53 |
+
if version == 'General - RealESRGANplus':
|
54 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
55 |
+
model_path = 'weights/RealESRGAN_x4plus.pth'
|
56 |
+
self.upsampler = RealESRGANer(
|
57 |
+
scale=4, model_path=model_path, model=model, tile=tile, tile_pad=10, pre_pad=0, half=half)
|
58 |
+
elif version == 'General - v3':
|
59 |
+
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
60 |
+
model_path = 'weights/realesr-general-x4v3.pth'
|
61 |
+
self.upsampler = RealESRGANer(
|
62 |
+
scale=4, model_path=model_path, model=model, tile=tile, tile_pad=10, pre_pad=0, half=half)
|
63 |
+
elif version == 'Anime - anime6B':
|
64 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4)
|
65 |
+
model_path = 'weights/RealESRGAN_x4plus_anime_6B.pth'
|
66 |
+
self.upsampler = RealESRGANer(
|
67 |
+
scale=4, model_path=model_path, model=model, tile=tile, tile_pad=10, pre_pad=0, half=half)
|
68 |
+
elif version == 'AnimeVideo - v3':
|
69 |
+
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu')
|
70 |
+
model_path = 'weights/realesr-animevideov3.pth'
|
71 |
+
self.upsampler = RealESRGANer(
|
72 |
+
scale=4, model_path=model_path, model=model, tile=tile, tile_pad=10, pre_pad=0, half=half)
|
73 |
+
|
74 |
+
self.face_enhancer = GFPGANer(
|
75 |
+
model_path='weights/GFPGANv1.4.pth',
|
76 |
+
upscale=scale,
|
77 |
+
arch='clean',
|
78 |
+
channel_multiplier=2,
|
79 |
+
bg_upsampler=self.upsampler)
|
80 |
+
|
81 |
+
def predict(
|
82 |
+
self,
|
83 |
+
img: Path = Input(description='Input'),
|
84 |
+
version: str = Input(
|
85 |
+
description='RealESRGAN version. Please see [Readme] below for more descriptions',
|
86 |
+
choices=['General - RealESRGANplus', 'General - v3', 'Anime - anime6B', 'AnimeVideo - v3'],
|
87 |
+
default='General - v3'),
|
88 |
+
scale: float = Input(description='Rescaling factor', default=2),
|
89 |
+
face_enhance: bool = Input(
|
90 |
+
description='Enhance faces with GFPGAN. Note that it does not work for anime images/vidoes', default=False),
|
91 |
+
tile: int = Input(
|
92 |
+
description=
|
93 |
+
'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',
|
94 |
+
default=0)
|
95 |
+
) -> Path:
|
96 |
+
if tile <= 100 or tile is None:
|
97 |
+
tile = 0
|
98 |
+
print(f'img: {img}. version: {version}. scale: {scale}. face_enhance: {face_enhance}. tile: {tile}.')
|
99 |
+
try:
|
100 |
+
extension = os.path.splitext(os.path.basename(str(img)))[1]
|
101 |
+
img = cv2.imread(str(img), cv2.IMREAD_UNCHANGED)
|
102 |
+
if len(img.shape) == 3 and img.shape[2] == 4:
|
103 |
+
img_mode = 'RGBA'
|
104 |
+
elif len(img.shape) == 2:
|
105 |
+
img_mode = None
|
106 |
+
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
|
107 |
+
else:
|
108 |
+
img_mode = None
|
109 |
+
|
110 |
+
h, w = img.shape[0:2]
|
111 |
+
if h < 300:
|
112 |
+
img = cv2.resize(img, (w * 2, h * 2), interpolation=cv2.INTER_LANCZOS4)
|
113 |
+
|
114 |
+
self.choose_model(scale, version, tile)
|
115 |
+
|
116 |
+
try:
|
117 |
+
if face_enhance:
|
118 |
+
_, _, output = self.face_enhancer.enhance(
|
119 |
+
img, has_aligned=False, only_center_face=False, paste_back=True)
|
120 |
+
else:
|
121 |
+
output, _ = self.upsampler.enhance(img, outscale=scale)
|
122 |
+
except RuntimeError as error:
|
123 |
+
print('Error', error)
|
124 |
+
print('If you encounter CUDA out of memory, try to set "tile" to a smaller size, e.g., 400.')
|
125 |
+
|
126 |
+
if img_mode == 'RGBA': # RGBA images should be saved in png format
|
127 |
+
extension = 'png'
|
128 |
+
# save_path = f'output/out.{extension}'
|
129 |
+
# cv2.imwrite(save_path, output)
|
130 |
+
out_path = Path(tempfile.mkdtemp()) / f'out.{extension}'
|
131 |
+
cv2.imwrite(str(out_path), output)
|
132 |
+
except Exception as error:
|
133 |
+
print('global exception: ', error)
|
134 |
+
finally:
|
135 |
+
clean_folder('output')
|
136 |
+
return out_path
|
137 |
+
|
138 |
+
|
139 |
+
def clean_folder(folder):
|
140 |
+
for filename in os.listdir(folder):
|
141 |
+
file_path = os.path.join(folder, filename)
|
142 |
+
try:
|
143 |
+
if os.path.isfile(file_path) or os.path.islink(file_path):
|
144 |
+
os.unlink(file_path)
|
145 |
+
elif os.path.isdir(file_path):
|
146 |
+
shutil.rmtree(file_path)
|
147 |
+
except Exception as e:
|
148 |
+
print(f'Failed to delete {file_path}. Reason: {e}')
|
RealESRGANv030/docs/CONTRIBUTING.md
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Contributing to Real-ESRGAN
|
2 |
+
|
3 |
+
: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).
|
4 |
+
|
5 |
+
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:
|
6 |
+
|
7 |
+
- New features
|
8 |
+
- New models (your fine-tuned models)
|
9 |
+
- Bug fixes
|
10 |
+
- Typo fixes
|
11 |
+
- Suggestions
|
12 |
+
- Maintenance
|
13 |
+
- Documents
|
14 |
+
- *etc*
|
15 |
+
|
16 |
+
## Workflow
|
17 |
+
|
18 |
+
1. Fork and pull the latest Real-ESRGAN repository
|
19 |
+
1. Checkout a new branch (do not use master branch for PRs)
|
20 |
+
1. Commit your changes
|
21 |
+
1. Create a PR
|
22 |
+
|
23 |
+
**Note**:
|
24 |
+
|
25 |
+
1. Please check the code style and linting
|
26 |
+
1. The style configuration is specified in [setup.cfg](setup.cfg)
|
27 |
+
1. If you use VSCode, the settings are configured in [.vscode/settings.json](.vscode/settings.json)
|
28 |
+
1. Strongly recommend using `pre-commit hook`. It will check your code style and linting before your commit.
|
29 |
+
1. In the root path of project folder, run `pre-commit install`
|
30 |
+
1. The pre-commit configuration is listed in [.pre-commit-config.yaml](.pre-commit-config.yaml)
|
31 |
+
1. Better to [open a discussion](https://github.com/xinntao/Real-ESRGAN/discussions) before large changes.
|
32 |
+
1. Welcome to discuss :sunglasses:. I will try my best to join the discussion.
|
33 |
+
|
34 |
+
## TODO List
|
35 |
+
|
36 |
+
:zero: The most straightforward way of improving model performance is to fine-tune on some specific datasets.
|
37 |
+
|
38 |
+
Here are some TODOs:
|
39 |
+
|
40 |
+
- [ ] optimize for human faces
|
41 |
+
- [ ] optimize for texts
|
42 |
+
- [ ] support controllable restoration strength
|
43 |
+
|
44 |
+
:one: There are also [several issues](https://github.com/xinntao/Real-ESRGAN/issues) that require helpers to improve. If you can help, please let me know :smile:
|
RealESRGANv030/docs/FAQ.md
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# FAQ
|
2 |
+
|
3 |
+
1. **Q: How to select models?**<br>
|
4 |
+
A: Please refer to [docs/model_zoo.md](docs/model_zoo.md)
|
5 |
+
|
6 |
+
1. **Q: Can `face_enhance` be used for anime images/animation videos?**<br>
|
7 |
+
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.
|
8 |
+
|
9 |
+
1. **Q: Error "slow_conv2d_cpu" not implemented for 'Half'**<br>
|
10 |
+
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`.
|
RealESRGANv030/docs/Training.md
ADDED
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# :computer: How to Train/Finetune Real-ESRGAN
|
2 |
+
|
3 |
+
- [Train Real-ESRGAN](#train-real-esrgan)
|
4 |
+
- [Overview](#overview)
|
5 |
+
- [Dataset Preparation](#dataset-preparation)
|
6 |
+
- [Train Real-ESRNet](#Train-Real-ESRNet)
|
7 |
+
- [Train Real-ESRGAN](#Train-Real-ESRGAN)
|
8 |
+
- [Finetune Real-ESRGAN on your own dataset](#Finetune-Real-ESRGAN-on-your-own-dataset)
|
9 |
+
- [Generate degraded images on the fly](#Generate-degraded-images-on-the-fly)
|
10 |
+
- [Use paired training data](#use-your-own-paired-data)
|
11 |
+
|
12 |
+
[English](Training.md) **|** [简体中文](Training_CN.md)
|
13 |
+
|
14 |
+
## Train Real-ESRGAN
|
15 |
+
|
16 |
+
### Overview
|
17 |
+
|
18 |
+
The training has been divided into two stages. These two stages have the same data synthesis process and training pipeline, except for the loss functions. Specifically,
|
19 |
+
|
20 |
+
1. We first train Real-ESRNet with L1 loss from the pre-trained model ESRGAN.
|
21 |
+
1. We then use the trained Real-ESRNet model as an initialization of the generator, and train the Real-ESRGAN with a combination of L1 loss, perceptual loss and GAN loss.
|
22 |
+
|
23 |
+
### Dataset Preparation
|
24 |
+
|
25 |
+
We use DF2K (DIV2K and Flickr2K) + OST datasets for our training. Only HR images are required. <br>
|
26 |
+
You can download from :
|
27 |
+
|
28 |
+
1. DIV2K: http://data.vision.ee.ethz.ch/cvl/DIV2K/DIV2K_train_HR.zip
|
29 |
+
2. Flickr2K: https://cv.snu.ac.kr/research/EDSR/Flickr2K.tar
|
30 |
+
3. OST: https://openmmlab.oss-cn-hangzhou.aliyuncs.com/datasets/OST_dataset.zip
|
31 |
+
|
32 |
+
Here are steps for data preparation.
|
33 |
+
|
34 |
+
#### Step 1: [Optional] Generate multi-scale images
|
35 |
+
|
36 |
+
For the DF2K dataset, we use a multi-scale strategy, *i.e.*, we downsample HR images to obtain several Ground-Truth images with different scales. <br>
|
37 |
+
You can use the [scripts/generate_multiscale_DF2K.py](scripts/generate_multiscale_DF2K.py) script to generate multi-scale images. <br>
|
38 |
+
Note that this step can be omitted if you just want to have a fast try.
|
39 |
+
|
40 |
+
```bash
|
41 |
+
python scripts/generate_multiscale_DF2K.py --input datasets/DF2K/DF2K_HR --output datasets/DF2K/DF2K_multiscale
|
42 |
+
```
|
43 |
+
|
44 |
+
#### Step 2: [Optional] Crop to sub-images
|
45 |
+
|
46 |
+
We then crop DF2K images into sub-images for faster IO and processing.<br>
|
47 |
+
This step is optional if your IO is enough or your disk space is limited.
|
48 |
+
|
49 |
+
You can use the [scripts/extract_subimages.py](scripts/extract_subimages.py) script. Here is the example:
|
50 |
+
|
51 |
+
```bash
|
52 |
+
python scripts/extract_subimages.py --input datasets/DF2K/DF2K_multiscale --output datasets/DF2K/DF2K_multiscale_sub --crop_size 400 --step 200
|
53 |
+
```
|
54 |
+
|
55 |
+
#### Step 3: Prepare a txt for meta information
|
56 |
+
|
57 |
+
You need to prepare a txt file containing the image paths. The following are some examples in `meta_info_DF2Kmultiscale+OST_sub.txt` (As different users may have different sub-images partitions, this file is not suitable for your purpose and you need to prepare your own txt file):
|
58 |
+
|
59 |
+
```txt
|
60 |
+
DF2K_HR_sub/000001_s001.png
|
61 |
+
DF2K_HR_sub/000001_s002.png
|
62 |
+
DF2K_HR_sub/000001_s003.png
|
63 |
+
...
|
64 |
+
```
|
65 |
+
|
66 |
+
You can use the [scripts/generate_meta_info.py](scripts/generate_meta_info.py) script to generate the txt file. <br>
|
67 |
+
You can merge several folders into one meta_info txt. Here is the example:
|
68 |
+
|
69 |
+
```bash
|
70 |
+
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
|
71 |
+
```
|
72 |
+
|
73 |
+
### Train Real-ESRNet
|
74 |
+
|
75 |
+
1. Download pre-trained model [ESRGAN](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth) into `experiments/pretrained_models`.
|
76 |
+
```bash
|
77 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth -P experiments/pretrained_models
|
78 |
+
```
|
79 |
+
1. Modify the content in the option file `options/train_realesrnet_x4plus.yml` accordingly:
|
80 |
+
```yml
|
81 |
+
train:
|
82 |
+
name: DF2K+OST
|
83 |
+
type: RealESRGANDataset
|
84 |
+
dataroot_gt: datasets/DF2K # modify to the root path of your folder
|
85 |
+
meta_info: realesrgan/meta_info/meta_info_DF2Kmultiscale+OST_sub.txt # modify to your own generate meta info txt
|
86 |
+
io_backend:
|
87 |
+
type: disk
|
88 |
+
```
|
89 |
+
1. If you want to perform validation during training, uncomment those lines and modify accordingly:
|
90 |
+
```yml
|
91 |
+
# Uncomment these for validation
|
92 |
+
# val:
|
93 |
+
# name: validation
|
94 |
+
# type: PairedImageDataset
|
95 |
+
# dataroot_gt: path_to_gt
|
96 |
+
# dataroot_lq: path_to_lq
|
97 |
+
# io_backend:
|
98 |
+
# type: disk
|
99 |
+
|
100 |
+
...
|
101 |
+
|
102 |
+
# Uncomment these for validation
|
103 |
+
# validation settings
|
104 |
+
# val:
|
105 |
+
# val_freq: !!float 5e3
|
106 |
+
# save_img: True
|
107 |
+
|
108 |
+
# metrics:
|
109 |
+
# psnr: # metric name, can be arbitrary
|
110 |
+
# type: calculate_psnr
|
111 |
+
# crop_border: 4
|
112 |
+
# test_y_channel: false
|
113 |
+
```
|
114 |
+
1. Before the formal training, you may run in the `--debug` mode to see whether everything is OK. We use four GPUs for training:
|
115 |
+
```bash
|
116 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
117 |
+
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --launcher pytorch --debug
|
118 |
+
```
|
119 |
+
|
120 |
+
Train with **a single GPU** in the *debug* mode:
|
121 |
+
```bash
|
122 |
+
python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --debug
|
123 |
+
```
|
124 |
+
1. The formal training. We use four GPUs for training. We use the `--auto_resume` argument to automatically resume the training if necessary.
|
125 |
+
```bash
|
126 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
127 |
+
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
|
128 |
+
```
|
129 |
+
|
130 |
+
Train with **a single GPU**:
|
131 |
+
```bash
|
132 |
+
python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --auto_resume
|
133 |
+
```
|
134 |
+
|
135 |
+
### Train Real-ESRGAN
|
136 |
+
|
137 |
+
1. After the training of Real-ESRNet, you now have the file `experiments/train_RealESRNetx4plus_1000k_B12G4_fromESRGAN/model/net_g_1000000.pth`. If you need to specify the pre-trained path to other files, modify the `pretrain_network_g` value in the option file `train_realesrgan_x4plus.yml`.
|
138 |
+
1. Modify the option file `train_realesrgan_x4plus.yml` accordingly. Most modifications are similar to those listed above.
|
139 |
+
1. Before the formal training, you may run in the `--debug` mode to see whether everything is OK. We use four GPUs for training:
|
140 |
+
```bash
|
141 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
142 |
+
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --launcher pytorch --debug
|
143 |
+
```
|
144 |
+
|
145 |
+
Train with **a single GPU** in the *debug* mode:
|
146 |
+
```bash
|
147 |
+
python realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --debug
|
148 |
+
```
|
149 |
+
1. The formal training. We use four GPUs for training. We use the `--auto_resume` argument to automatically resume the training if necessary.
|
150 |
+
```bash
|
151 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
152 |
+
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
|
153 |
+
```
|
154 |
+
|
155 |
+
Train with **a single GPU**:
|
156 |
+
```bash
|
157 |
+
python realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --auto_resume
|
158 |
+
```
|
159 |
+
|
160 |
+
## Finetune Real-ESRGAN on your own dataset
|
161 |
+
|
162 |
+
You can finetune Real-ESRGAN on your own dataset. Typically, the fine-tuning process can be divided into two cases:
|
163 |
+
|
164 |
+
1. [Generate degraded images on the fly](#Generate-degraded-images-on-the-fly)
|
165 |
+
1. [Use your own **paired** data](#Use-paired-training-data)
|
166 |
+
|
167 |
+
### Generate degraded images on the fly
|
168 |
+
|
169 |
+
Only high-resolution images are required. The low-quality images are generated with the degradation process described in Real-ESRGAN during training.
|
170 |
+
|
171 |
+
**1. Prepare dataset**
|
172 |
+
|
173 |
+
See [this section](#dataset-preparation) for more details.
|
174 |
+
|
175 |
+
**2. Download pre-trained models**
|
176 |
+
|
177 |
+
Download pre-trained models into `experiments/pretrained_models`.
|
178 |
+
|
179 |
+
- *RealESRGAN_x4plus.pth*:
|
180 |
+
```bash
|
181 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models
|
182 |
+
```
|
183 |
+
|
184 |
+
- *RealESRGAN_x4plus_netD.pth*:
|
185 |
+
```bash
|
186 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth -P experiments/pretrained_models
|
187 |
+
```
|
188 |
+
|
189 |
+
**3. Finetune**
|
190 |
+
|
191 |
+
Modify [options/finetune_realesrgan_x4plus.yml](options/finetune_realesrgan_x4plus.yml) accordingly, especially the `datasets` part:
|
192 |
+
|
193 |
+
```yml
|
194 |
+
train:
|
195 |
+
name: DF2K+OST
|
196 |
+
type: RealESRGANDataset
|
197 |
+
dataroot_gt: datasets/DF2K # modify to the root path of your folder
|
198 |
+
meta_info: realesrgan/meta_info/meta_info_DF2Kmultiscale+OST_sub.txt # modify to your own generate meta info txt
|
199 |
+
io_backend:
|
200 |
+
type: disk
|
201 |
+
```
|
202 |
+
|
203 |
+
We use four GPUs for training. We use the `--auto_resume` argument to automatically resume the training if necessary.
|
204 |
+
|
205 |
+
```bash
|
206 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
207 |
+
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
|
208 |
+
```
|
209 |
+
|
210 |
+
Finetune with **a single GPU**:
|
211 |
+
```bash
|
212 |
+
python realesrgan/train.py -opt options/finetune_realesrgan_x4plus.yml --auto_resume
|
213 |
+
```
|
214 |
+
|
215 |
+
### Use your own paired data
|
216 |
+
|
217 |
+
You can also finetune RealESRGAN with your own paired data. It is more similar to fine-tuning ESRGAN.
|
218 |
+
|
219 |
+
**1. Prepare dataset**
|
220 |
+
|
221 |
+
Assume that you already have two folders:
|
222 |
+
|
223 |
+
- **gt folder** (Ground-truth, high-resolution images): *datasets/DF2K/DIV2K_train_HR_sub*
|
224 |
+
- **lq folder** (Low quality, low-resolution images): *datasets/DF2K/DIV2K_train_LR_bicubic_X4_sub*
|
225 |
+
|
226 |
+
Then, you can prepare the meta_info txt file using the script [scripts/generate_meta_info_pairdata.py](scripts/generate_meta_info_pairdata.py):
|
227 |
+
|
228 |
+
```bash
|
229 |
+
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
|
230 |
+
```
|
231 |
+
|
232 |
+
**2. Download pre-trained models**
|
233 |
+
|
234 |
+
Download pre-trained models into `experiments/pretrained_models`.
|
235 |
+
|
236 |
+
- *RealESRGAN_x4plus.pth*
|
237 |
+
```bash
|
238 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models
|
239 |
+
```
|
240 |
+
|
241 |
+
- *RealESRGAN_x4plus_netD.pth*
|
242 |
+
```bash
|
243 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth -P experiments/pretrained_models
|
244 |
+
```
|
245 |
+
|
246 |
+
**3. Finetune**
|
247 |
+
|
248 |
+
Modify [options/finetune_realesrgan_x4plus_pairdata.yml](options/finetune_realesrgan_x4plus_pairdata.yml) accordingly, especially the `datasets` part:
|
249 |
+
|
250 |
+
```yml
|
251 |
+
train:
|
252 |
+
name: DIV2K
|
253 |
+
type: RealESRGANPairedDataset
|
254 |
+
dataroot_gt: datasets/DF2K # modify to the root path of your folder
|
255 |
+
dataroot_lq: datasets/DF2K # modify to the root path of your folder
|
256 |
+
meta_info: datasets/DF2K/meta_info/meta_info_DIV2K_sub_pair.txt # modify to your own generate meta info txt
|
257 |
+
io_backend:
|
258 |
+
type: disk
|
259 |
+
```
|
260 |
+
|
261 |
+
We use four GPUs for training. We use the `--auto_resume` argument to automatically resume the training if necessary.
|
262 |
+
|
263 |
+
```bash
|
264 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
265 |
+
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
|
266 |
+
```
|
267 |
+
|
268 |
+
Finetune with **a single GPU**:
|
269 |
+
```bash
|
270 |
+
python realesrgan/train.py -opt options/finetune_realesrgan_x4plus_pairdata.yml --auto_resume
|
271 |
+
```
|
RealESRGANv030/docs/Training_CN.md
ADDED
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# :computer: 如何训练/微调 Real-ESRGAN
|
2 |
+
|
3 |
+
- [训练 Real-ESRGAN](#训练-real-esrgan)
|
4 |
+
- [概述](#概述)
|
5 |
+
- [准备数据集](#准备数据集)
|
6 |
+
- [训练 Real-ESRNet 模型](#训练-real-esrnet-模型)
|
7 |
+
- [训练 Real-ESRGAN 模型](#训练-real-esrgan-模型)
|
8 |
+
- [用自己的数据集微调 Real-ESRGAN](#用自己的数据集微调-real-esrgan)
|
9 |
+
- [动态生成降级图像](#动态生成降级图像)
|
10 |
+
- [使用已配对的数据](#使用已配对的数据)
|
11 |
+
|
12 |
+
[English](Training.md) **|** [简体中文](Training_CN.md)
|
13 |
+
|
14 |
+
## 训练 Real-ESRGAN
|
15 |
+
|
16 |
+
### 概述
|
17 |
+
|
18 |
+
训练分为两个步骤。除了 loss 函数外,这两个步骤拥有相同数据合成以及训练的一条龙流程。具体点说:
|
19 |
+
|
20 |
+
1. 首先使用 L1 loss 训练 Real-ESRNet 模型,其中 L1 loss 来自预先训练的 ESRGAN 模型。
|
21 |
+
|
22 |
+
2. 然后我们将 Real-ESRNet 模型作为生成器初始化,结合L1 loss、感知 loss、GAN loss 三者的参数对 Real-ESRGAN 进行训练。
|
23 |
+
|
24 |
+
### 准备数据集
|
25 |
+
|
26 |
+
我们使用 DF2K ( DIV2K 和 Flickr2K ) + OST 数据集进行训练。只需要HR图像!<br>
|
27 |
+
下面是网站链接:
|
28 |
+
1. DIV2K: http://data.vision.ee.ethz.ch/cvl/DIV2K/DIV2K_train_HR.zip
|
29 |
+
2. Flickr2K: https://cv.snu.ac.kr/research/EDSR/Flickr2K.tar
|
30 |
+
3. OST: https://openmmlab.oss-cn-hangzhou.aliyuncs.com/datasets/OST_dataset.zip
|
31 |
+
|
32 |
+
以下是数据的准备步骤。
|
33 |
+
|
34 |
+
#### 第1步:【可选】生成多尺寸图片
|
35 |
+
|
36 |
+
针对 DF2K 数据集,我们使用多尺寸缩放策略,*换言之*,我们对 HR 图像进行下采样,就能获得多尺寸的标准参考(Ground-Truth)图像。 <br>
|
37 |
+
您可以使用这个 [scripts/generate_multiscale_DF2K.py](scripts/generate_multiscale_DF2K.py) 脚本快速生成多尺寸的图像。<br>
|
38 |
+
注意:如果您只想简单试试,那么可以跳过此步骤。
|
39 |
+
|
40 |
+
```bash
|
41 |
+
python scripts/generate_multiscale_DF2K.py --input datasets/DF2K/DF2K_HR --output datasets/DF2K/DF2K_multiscale
|
42 |
+
```
|
43 |
+
|
44 |
+
#### 第2步:【可选】裁切为子图像
|
45 |
+
|
46 |
+
我们可以将 DF2K 图像裁切为子图像,以加快 IO 和处理速度。<br>
|
47 |
+
如果你的 IO 够好或储存空间有限,那么此步骤是可选的。<br>
|
48 |
+
|
49 |
+
您可以使用脚本 [scripts/extract_subimages.py](scripts/extract_subimages.py)。这是使用示例:
|
50 |
+
|
51 |
+
```bash
|
52 |
+
python scripts/extract_subimages.py --input datasets/DF2K/DF2K_multiscale --output datasets/DF2K/DF2K_multiscale_sub --crop_size 400 --step 200
|
53 |
+
```
|
54 |
+
|
55 |
+
#### 第3步:准备元信息 txt
|
56 |
+
|
57 |
+
您需要准备一个包含图像路径的 txt 文件。下面是 `meta_info_DF2Kmultiscale+OST_sub.txt` 中的部分展示(由于各个用户可能有截然不同的子图像划分,这个文件不适合你的需求,你得准备自己的 txt 文件):
|
58 |
+
|
59 |
+
```txt
|
60 |
+
DF2K_HR_sub/000001_s001.png
|
61 |
+
DF2K_HR_sub/000001_s002.png
|
62 |
+
DF2K_HR_sub/000001_s003.png
|
63 |
+
...
|
64 |
+
```
|
65 |
+
|
66 |
+
你可以使用该脚本 [scripts/generate_meta_info.py](scripts/generate_meta_info.py) 生成包含图像路径的 txt 文件。<br>
|
67 |
+
你还可以合并多个文件夹的图像路径到一个元信息(meta_info)txt。这是使用示例:
|
68 |
+
|
69 |
+
```bash
|
70 |
+
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
|
71 |
+
```
|
72 |
+
|
73 |
+
### 训练 Real-ESRNet 模型
|
74 |
+
|
75 |
+
1. 下载预先训练的模型 [ESRGAN](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth),放到 `experiments/pretrained_models`目录下。
|
76 |
+
```bash
|
77 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth -P experiments/pretrained_models
|
78 |
+
```
|
79 |
+
2. 相应地修改选项文件 `options/train_realesrnet_x4plus.yml` 中的内容:
|
80 |
+
```yml
|
81 |
+
train:
|
82 |
+
name: DF2K+OST
|
83 |
+
type: RealESRGANDataset
|
84 |
+
dataroot_gt: datasets/DF2K # 修改为你的数据集文件夹根目录
|
85 |
+
meta_info: realesrgan/meta_info/meta_info_DF2Kmultiscale+OST_sub.txt # 修改为你自己生成的元信息txt
|
86 |
+
io_backend:
|
87 |
+
type: disk
|
88 |
+
```
|
89 |
+
3. 如果你想在训练过程中执行验证,就取消注释这些内容并进行相应的修改:
|
90 |
+
```yml
|
91 |
+
# 取消注释这些以进行验证
|
92 |
+
# val:
|
93 |
+
# name: validation
|
94 |
+
# type: PairedImageDataset
|
95 |
+
# dataroot_gt: path_to_gt
|
96 |
+
# dataroot_lq: path_to_lq
|
97 |
+
# io_backend:
|
98 |
+
# type: disk
|
99 |
+
|
100 |
+
...
|
101 |
+
|
102 |
+
# 取消注释这些以进行验证
|
103 |
+
# 验证设置
|
104 |
+
# val:
|
105 |
+
# val_freq: !!float 5e3
|
106 |
+
# save_img: True
|
107 |
+
|
108 |
+
# metrics:
|
109 |
+
# psnr: # 指标名称,可以是任意的
|
110 |
+
# type: calculate_psnr
|
111 |
+
# crop_border: 4
|
112 |
+
# test_y_channel: false
|
113 |
+
```
|
114 |
+
4. 正式训练之前,你可以用 `--debug` 模式检查是否正常运行。我们用了4个GPU进行训练:
|
115 |
+
```bash
|
116 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
117 |
+
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --launcher pytorch --debug
|
118 |
+
```
|
119 |
+
|
120 |
+
用 **1个GPU** 训练的 debug 模式示例:
|
121 |
+
```bash
|
122 |
+
python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --debug
|
123 |
+
```
|
124 |
+
5. 正式训练开始。我们用了4个GPU进行训练。还可以使用参数 `--auto_resume` 在必要时自动恢复训练。
|
125 |
+
```bash
|
126 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
127 |
+
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
|
128 |
+
```
|
129 |
+
|
130 |
+
用 **1个GPU** 训练:
|
131 |
+
```bash
|
132 |
+
python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --auto_resume
|
133 |
+
```
|
134 |
+
|
135 |
+
### 训练 Real-ESRGAN 模型
|
136 |
+
|
137 |
+
1. 训练 Real-ESRNet 模型后,您得到了这个 `experiments/train_RealESRNetx4plus_1000k_B12G4_fromESRGAN/model/net_g_1000000.pth` 文件。如果需要指定预训练路径到其他文件,请修改选项文件 `train_realesrgan_x4plus.yml` 中 `pretrain_network_g` 的值。
|
138 |
+
1. 修改选项文件 `train_realesrgan_x4plus.yml` 的内容。大多数修改与上节提到的类似。
|
139 |
+
1. 正式训练之前,你可以以 `--debug` 模式检查是否正常运行。我们使用了4个GPU进行训练:
|
140 |
+
```bash
|
141 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
142 |
+
python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --launcher pytorch --debug
|
143 |
+
```
|
144 |
+
|
145 |
+
用 **1个GPU** 训练的 debug 模式示例:
|
146 |
+
```bash
|
147 |
+
python realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --debug
|
148 |
+
```
|
149 |
+
1. 正式训练开始。我们使用4个GPU进行训练。还可以使用参数 `--auto_resume` 在必要时自动恢复训练。
|
150 |
+
```bash
|
151 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
152 |
+
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
|
153 |
+
```
|
154 |
+
|
155 |
+
用 **1个GPU** 训练:
|
156 |
+
```bash
|
157 |
+
python realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --auto_resume
|
158 |
+
```
|
159 |
+
|
160 |
+
## 用自己的数据集微调 Real-ESRGAN
|
161 |
+
|
162 |
+
你可以用自己的数据集微调 Real-ESRGAN。一般地,微调(Fine-Tune)程序可以分为两种类型:
|
163 |
+
|
164 |
+
1. [动态生成降级图像](#动态生成降级图像)
|
165 |
+
2. [使用**已配对**的数据](#使用已配对的数据)
|
166 |
+
|
167 |
+
### 动态生成降级图像
|
168 |
+
|
169 |
+
只需要高分辨率图像。在训练过程中,使用 Real-ESRGAN 描述的降级模型生成低质量图像。
|
170 |
+
|
171 |
+
**1. 准备数据集**
|
172 |
+
|
173 |
+
完整信息请参见[本节](#准备数据集)。
|
174 |
+
|
175 |
+
**2. 下载预训练模型**
|
176 |
+
|
177 |
+
下载预先训练的模型到 `experiments/pretrained_models` 目录下。
|
178 |
+
|
179 |
+
- *RealESRGAN_x4plus.pth*:
|
180 |
+
```bash
|
181 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models
|
182 |
+
```
|
183 |
+
|
184 |
+
- *RealESRGAN_x4plus_netD.pth*:
|
185 |
+
```bash
|
186 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth -P experiments/pretrained_models
|
187 |
+
```
|
188 |
+
|
189 |
+
**3. 微调**
|
190 |
+
|
191 |
+
修改选项文件 [options/finetune_realesrgan_x4plus.yml](options/finetune_realesrgan_x4plus.yml) ,特别是 `datasets` 部分:
|
192 |
+
|
193 |
+
```yml
|
194 |
+
train:
|
195 |
+
name: DF2K+OST
|
196 |
+
type: RealESRGANDataset
|
197 |
+
dataroot_gt: datasets/DF2K # 修改为你的数据集文件夹根目录
|
198 |
+
meta_info: realesrgan/meta_info/meta_info_DF2Kmultiscale+OST_sub.txt # 修改为你自己生成的元信息txt
|
199 |
+
io_backend:
|
200 |
+
type: disk
|
201 |
+
```
|
202 |
+
|
203 |
+
我们使用4个GPU进行训练。还可以使用参数 `--auto_resume` 在必要时自动恢复训练。
|
204 |
+
|
205 |
+
```bash
|
206 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
207 |
+
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
|
208 |
+
```
|
209 |
+
|
210 |
+
用 **1个GPU** 训练:
|
211 |
+
```bash
|
212 |
+
python realesrgan/train.py -opt options/finetune_realesrgan_x4plus.yml --auto_resume
|
213 |
+
```
|
214 |
+
|
215 |
+
### 使用已配对的数据
|
216 |
+
|
217 |
+
你还可以用自己已经配对的数据微调 RealESRGAN。这个过程更类似于微调 ESRGAN。
|
218 |
+
|
219 |
+
**1. 准备数据集**
|
220 |
+
|
221 |
+
假设你已经有两个文件夹(folder):
|
222 |
+
|
223 |
+
- **gt folder**(标准参考,高分辨率图像):*datasets/DF2K/DIV2K_train_HR_sub*
|
224 |
+
- **lq folder**(低质量,低分辨率图像):*datasets/DF2K/DIV2K_train_LR_bicubic_X4_sub*
|
225 |
+
|
226 |
+
然后,您可以使用脚本 [scripts/generate_meta_info_pairdata.py](scripts/generate_meta_info_pairdata.py) 生成元信息(meta_info)txt 文件。
|
227 |
+
|
228 |
+
```bash
|
229 |
+
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
|
230 |
+
```
|
231 |
+
|
232 |
+
**2. 下载预训练模型**
|
233 |
+
|
234 |
+
下载预先训练的模型到 `experiments/pretrained_models` 目录下。
|
235 |
+
|
236 |
+
- *RealESRGAN_x4plus.pth*:
|
237 |
+
```bash
|
238 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models
|
239 |
+
```
|
240 |
+
|
241 |
+
- *RealESRGAN_x4plus_netD.pth*:
|
242 |
+
```bash
|
243 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth -P experiments/pretrained_models
|
244 |
+
```
|
245 |
+
|
246 |
+
**3. 微调**
|
247 |
+
|
248 |
+
修改选项文件 [options/finetune_realesrgan_x4plus_pairdata.yml](options/finetune_realesrgan_x4plus_pairdata.yml) ,特别是 `datasets` 部分:
|
249 |
+
|
250 |
+
```yml
|
251 |
+
train:
|
252 |
+
name: DIV2K
|
253 |
+
type: RealESRGANPairedDataset
|
254 |
+
dataroot_gt: datasets/DF2K # 修改为你的 gt folder 文件夹根目录
|
255 |
+
dataroot_lq: datasets/DF2K # 修改为你的 lq folder 文件夹根目录
|
256 |
+
meta_info: datasets/DF2K/meta_info/meta_info_DIV2K_sub_pair.txt # 修改为你自己生成的元信息txt
|
257 |
+
io_backend:
|
258 |
+
type: disk
|
259 |
+
```
|
260 |
+
|
261 |
+
我们使用4个GPU进行训练。还可以使用参数 `--auto_resume` 在必要时自动恢复训练。
|
262 |
+
|
263 |
+
```bash
|
264 |
+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
|
265 |
+
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
|
266 |
+
```
|
267 |
+
|
268 |
+
用 **1个GPU** 训练:
|
269 |
+
```bash
|
270 |
+
python realesrgan/train.py -opt options/finetune_realesrgan_x4plus_pairdata.yml --auto_resume
|
271 |
+
```
|
RealESRGANv030/docs/anime_comparisons.md
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Comparisons among different anime models
|
2 |
+
|
3 |
+
[English](anime_comparisons.md) **|** [简体中文](anime_comparisons_CN.md)
|
4 |
+
|
5 |
+
## Update News
|
6 |
+
|
7 |
+
- 2022/04/24: Release **AnimeVideo-v3**. We have made the following improvements:
|
8 |
+
- **better naturalness**
|
9 |
+
- **Fewer artifacts**
|
10 |
+
- **more faithful to the original colors**
|
11 |
+
- **better texture restoration**
|
12 |
+
- **better background restoration**
|
13 |
+
|
14 |
+
## Comparisons
|
15 |
+
|
16 |
+
We have compared our RealESRGAN-AnimeVideo-v3 with the following methods.
|
17 |
+
Our RealESRGAN-AnimeVideo-v3 can achieve better results with faster inference speed.
|
18 |
+
|
19 |
+
- [waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan) with the hyperparameters: `tile=0`, `noiselevel=2`
|
20 |
+
- [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`.
|
21 |
+
- our RealESRGAN-AnimeVideo-v3
|
22 |
+
|
23 |
+
## Results
|
24 |
+
|
25 |
+
You may need to **zoom in** for comparing details, or **click the image** to see in the full size. Please note that the images
|
26 |
+
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) .
|
27 |
+
|
28 |
+
**More natural results, better background restoration**
|
29 |
+
| Input | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
30 |
+
| :---: | :---: | :---: | :---: |
|
31 |
+
|![157083983-bec52c67-9a5e-4eed-afef-01fe6cd2af85_patch](https://user-images.githubusercontent.com/11482921/164452769-5d8cb4f8-1708-42d2-b941-f44a6f136feb.png) | ![](https://user-images.githubusercontent.com/11482921/164452767-c825cdec-f721-4ff1-aef1-fec41f146c4c.png) | ![](https://user-images.githubusercontent.com/11482921/164452755-3be50895-e3d4-432d-a7b9-9085c2a8e771.png) | ![](https://user-images.githubusercontent.com/11482921/164452771-be300656-379a-4323-a755-df8025a8c451.png) |
|
32 |
+
|![a0010_patch](https://user-images.githubusercontent.com/11482921/164454047-22eeb493-3fa9-4142-9fc2-6f2a1c074cd5.png) | ![](https://user-images.githubusercontent.com/11482921/164454046-d5e79f8f-00a0-4b55-bc39-295d0d69747a.png) | ![](https://user-images.githubusercontent.com/11482921/164454040-87886b11-9d08-48bd-862f-0d4aed72eb19.png) | ![](https://user-images.githubusercontent.com/11482921/164454055-73dc9f02-286e-4d5c-8f70-c13742e08f42.png) |
|
33 |
+
|![00000044_patch](https://user-images.githubusercontent.com/11482921/164451232-bacf64fc-e55a-44db-afbb-6b31ab0f8973.png) | ![](https://user-images.githubusercontent.com/11482921/164451318-f309b61a-75b8-4b74-b5f3-595725f1cf0b.png) | ![](https://user-images.githubusercontent.com/11482921/164451348-994f8a35-adbe-4a4b-9c61-feaa294af06a.png) | ![](https://user-images.githubusercontent.com/11482921/164451361-9b7d376e-6f75-4648-b752-542b44845d1c.png) |
|
34 |
+
|
35 |
+
**Fewer artifacts, better detailed textures**
|
36 |
+
| Input | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
37 |
+
| :---: | :---: | :---: | :---: |
|
38 |
+
|![00000053_patch](https://user-images.githubusercontent.com/11482921/164448411-148a7e5c-cfcd-4504-8bc7-e318eb883bb6.png) | ![](https://user-images.githubusercontent.com/11482921/164448633-dfc15224-b6d2-4403-a3c9-4bb819979364.png) | ![](https://user-images.githubusercontent.com/11482921/164448771-0d359509-5293-4d4c-8e3c-86a2a314ea88.png) | ![](https://user-images.githubusercontent.com/11482921/164448848-1a4ff99e-075b-4458-9db7-2c89e8160aa0.png) |
|
39 |
+
|![Disney_v4_22_018514_s2_patch](https://user-images.githubusercontent.com/11482921/164451898-83311cdf-bd3e-450f-b9f6-34d7fea3ab79.png) | ![](https://user-images.githubusercontent.com/11482921/164451894-6c56521c-6561-40d6-a3a5-8dde2c167b8a.png) | ![](https://user-images.githubusercontent.com/11482921/164451888-af9b47e3-39dc-4f3e-b0d7-d372d8191e2a.png) | ![](https://user-images.githubusercontent.com/11482921/164451901-31ca4dd4-9847-4baa-8cde-ad50f4053dcf.png) |
|
40 |
+
|![Japan_v2_0_007261_s2_patch](https://user-images.githubusercontent.com/11482921/164454578-73c77392-77de-49c5-b03c-c36631723192.png) | ![](https://user-images.githubusercontent.com/11482921/164454574-b1ede5f0-4520-4eaa-8f59-086751a34e62.png) | ![](https://user-images.githubusercontent.com/11482921/164454567-4cb3fdd8-6a2d-4016-85b2-a305a8ff80e4.png) | ![](https://user-images.githubusercontent.com/11482921/164454583-7f243f20-eca3-4500-ac43-eb058a4a101a.png) |
|
41 |
+
|![huluxiongdi_2_patch](https://user-images.githubusercontent.com/11482921/164453482-0726c842-337e-40ec-bf6c-f902ee956a8b.png) | ![](https://user-images.githubusercontent.com/11482921/164453480-71d5e091-5bfa-4c77-9c57-4e37f66ca0a3.png) | ![](https://user-images.githubusercontent.com/11482921/164453468-c295d3c9-3661-45f0-9ecd-406a1877f76e.png) | ![](https://user-images.githubusercontent.com/11482921/164453486-3091887c-587c-450e-b6fe-905cb518d57e.png) |
|
42 |
+
|
43 |
+
**Other better results**
|
44 |
+
| Input | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
45 |
+
| :---: | :---: | :---: | :---: |
|
46 |
+
|![Japan_v2_1_128525_s1_patch](https://user-images.githubusercontent.com/11482921/164454933-67697f7c-b6ef-47dc-bfca-822a78af8acf.png) | ![](https://user-images.githubusercontent.com/11482921/164454931-9450de7c-f0b3-4638-9c1e-0668e0c41ef0.png) | ![](https://user-images.githubusercontent.com/11482921/164454926-ed746976-786d-41c5-8a83-7693cd774c3a.png) | ![](https://user-images.githubusercontent.com/11482921/164454936-8abdf0f0-fb30-40eb-8281-3b46c0bcb9ae.png) |
|
47 |
+
|![tianshuqitan_2_patch](https://user-images.githubusercontent.com/11482921/164456948-807c1476-90b6-4507-81da-cb986d01600c.png) | ![](https://user-images.githubusercontent.com/11482921/164456943-25e89de9-d7e5-4f61-a2e1-96786af6ae9e.png) | ![](https://user-images.githubusercontent.com/11482921/164456954-b468c447-59f5-4594-9693-3683e44ba3e6.png) | ![](https://user-images.githubusercontent.com/11482921/164456957-640f910c-3b04-407c-ac20-044d72e19735.png) |
|
48 |
+
|![00000051_patch](https://user-images.githubusercontent.com/11482921/164456044-e9a6b3fa-b24e-4eb7-acf9-1f7746551b1e.png) ![00000051_patch](https://user-images.githubusercontent.com/11482921/164456421-b67245b0-767d-4250-9105-80bbe507ecfc.png) | ![](https://user-images.githubusercontent.com/11482921/164456040-85763cf2-cb28-4ba3-abb6-1dbb48c55713.png) ![](https://user-images.githubusercontent.com/11482921/164456419-59cf342e-bc1e-4044-868c-e1090abad313.png) | ![](https://user-images.githubusercontent.com/11482921/164456031-4244bb7b-8649-4e01-86f4-40c2099c5afd.png) ![](https://user-images.githubusercontent.com/11482921/164456411-b6afcbe9-c054-448d-a6df-96d3ba3047f8.png) | ![](https://user-images.githubusercontent.com/11482921/164456035-12e270be-fd52-46d4-b18a-3d3b680731fe.png) ![](https://user-images.githubusercontent.com/11482921/164456417-dcaa8b62-f497-427d-b2d2-f390f1200fb9.png) |
|
49 |
+
|![00000099_patch](https://user-images.githubusercontent.com/11482921/164455312-6411b6e1-5823-4131-a4b0-a6be8a9ae89f.png) | ![](https://user-images.githubusercontent.com/11482921/164455310-f2b99646-3a22-47a4-805b-dc451ac86ddb.png) | ![](https://user-images.githubusercontent.com/11482921/164455294-35471b42-2826-4451-b7ec-6de01344954c.png) | ![](https://user-images.githubusercontent.com/11482921/164455305-fa4c9758-564a-4081-8b4e-f11057a0404d.png) |
|
50 |
+
|![00000016_patch](https://user-images.githubusercontent.com/11482921/164455672-447353c9-2da2-4fcb-ba4a-7dd6b94c19c1.png) | ![](https://user-images.githubusercontent.com/11482921/164455669-df384631-baaa-42f8-9150-40f658471558.png) | ![](https://user-images.githubusercontent.com/11482921/164455657-68006bf0-138d-4981-aaca-8aa927d2f78a.png) | ![](https://user-images.githubusercontent.com/11482921/164455664-0342b93e-a62a-4b36-a90e-7118f3f1e45d.png) |
|
51 |
+
|
52 |
+
## Inference Speed
|
53 |
+
|
54 |
+
### PyTorch
|
55 |
+
|
56 |
+
Note that we only report the **model** time, and ignore the IO time.
|
57 |
+
|
58 |
+
| GPU | Input Resolution | waifu2x | Real-CUGAN | RealESRGAN-AnimeVideo-v3
|
59 |
+
| :---: | :---: | :---: | :---: | :---: |
|
60 |
+
| V100 | 1921 x 1080 | - | 3.4 fps | **10.0** fps |
|
61 |
+
| V100 | 1280 x 720 | - | 7.2 fps | **22.6** fps |
|
62 |
+
| V100 | 640 x 480 | - | 24.4 fps | **65.9** fps |
|
63 |
+
|
64 |
+
### ncnn
|
65 |
+
|
66 |
+
- [ ] TODO
|
RealESRGANv030/docs/anime_comparisons_CN.md
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 动漫视频模型比较
|
2 |
+
|
3 |
+
[English](anime_comparisons.md) **|** [简体中文](anime_comparisons_CN.md)
|
4 |
+
|
5 |
+
## 更新
|
6 |
+
|
7 |
+
- 2022/04/24: 发布 **AnimeVideo-v3**. 主要做了以下更新:
|
8 |
+
- **更自然**
|
9 |
+
- **更少瑕疵**
|
10 |
+
- **颜色保持得更好**
|
11 |
+
- **更好的纹理恢复**
|
12 |
+
- **虚化背景处理**
|
13 |
+
|
14 |
+
## 比较
|
15 |
+
|
16 |
+
我们将 RealESRGAN-AnimeVideo-v3 与以下方法进行了比较。我们的 RealESRGAN-AnimeVideo-v3 可以以更快的推理速度获得更好的结果。
|
17 |
+
|
18 |
+
- [waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan). 超参数: `tile=0`, `noiselevel=2`
|
19 |
+
- [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`.
|
20 |
+
- 我们的 RealESRGAN-AnimeVideo-v3
|
21 |
+
|
22 |
+
## 结果
|
23 |
+
|
24 |
+
您可能需要**放大**以比较详细信息, 或者**单击图像**以查看完整尺寸。 请注意下面表格的图片是从原图里裁剪patch并且resize后的结果,您可以从
|
25 |
+
[Google Drive](https://drive.google.com/drive/folders/1bc_Hje1Nqop9NDkUvci2VACSjL7HZMRp?usp=sharing) 里下载原始的输入和输出。
|
26 |
+
|
27 |
+
**更自然的结果,更好的虚化背景恢复**
|
28 |
+
|
29 |
+
| 输入 | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
30 |
+
| :---: | :---: | :---: | :---: |
|
31 |
+
|![157083983-bec52c67-9a5e-4eed-afef-01fe6cd2af85_patch](https://user-images.githubusercontent.com/11482921/164452769-5d8cb4f8-1708-42d2-b941-f44a6f136feb.png) | ![](https://user-images.githubusercontent.com/11482921/164452767-c825cdec-f721-4ff1-aef1-fec41f146c4c.png) | ![](https://user-images.githubusercontent.com/11482921/164452755-3be50895-e3d4-432d-a7b9-9085c2a8e771.png) | ![](https://user-images.githubusercontent.com/11482921/164452771-be300656-379a-4323-a755-df8025a8c451.png) |
|
32 |
+
|![a0010_patch](https://user-images.githubusercontent.com/11482921/164454047-22eeb493-3fa9-4142-9fc2-6f2a1c074cd5.png) | ![](https://user-images.githubusercontent.com/11482921/164454046-d5e79f8f-00a0-4b55-bc39-295d0d69747a.png) | ![](https://user-images.githubusercontent.com/11482921/164454040-87886b11-9d08-48bd-862f-0d4aed72eb19.png) | ![](https://user-images.githubusercontent.com/11482921/164454055-73dc9f02-286e-4d5c-8f70-c13742e08f42.png) |
|
33 |
+
|![00000044_patch](https://user-images.githubusercontent.com/11482921/164451232-bacf64fc-e55a-44db-afbb-6b31ab0f8973.png) | ![](https://user-images.githubusercontent.com/11482921/164451318-f309b61a-75b8-4b74-b5f3-595725f1cf0b.png) | ![](https://user-images.githubusercontent.com/11482921/164451348-994f8a35-adbe-4a4b-9c61-feaa294af06a.png) | ![](https://user-images.githubusercontent.com/11482921/164451361-9b7d376e-6f75-4648-b752-542b44845d1c.png) |
|
34 |
+
|
35 |
+
**更少瑕疵,更好的细节纹理**
|
36 |
+
|
37 |
+
| 输入 | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
38 |
+
| :---: | :---: | :---: | :---: |
|
39 |
+
|![00000053_patch](https://user-images.githubusercontent.com/11482921/164448411-148a7e5c-cfcd-4504-8bc7-e318eb883bb6.png) | ![](https://user-images.githubusercontent.com/11482921/164448633-dfc15224-b6d2-4403-a3c9-4bb819979364.png) | ![](https://user-images.githubusercontent.com/11482921/164448771-0d359509-5293-4d4c-8e3c-86a2a314ea88.png) | ![](https://user-images.githubusercontent.com/11482921/164448848-1a4ff99e-075b-4458-9db7-2c89e8160aa0.png) |
|
40 |
+
|![Disney_v4_22_018514_s2_patch](https://user-images.githubusercontent.com/11482921/164451898-83311cdf-bd3e-450f-b9f6-34d7fea3ab79.png) | ![](https://user-images.githubusercontent.com/11482921/164451894-6c56521c-6561-40d6-a3a5-8dde2c167b8a.png) | ![](https://user-images.githubusercontent.com/11482921/164451888-af9b47e3-39dc-4f3e-b0d7-d372d8191e2a.png) | ![](https://user-images.githubusercontent.com/11482921/164451901-31ca4dd4-9847-4baa-8cde-ad50f4053dcf.png) |
|
41 |
+
|![Japan_v2_0_007261_s2_patch](https://user-images.githubusercontent.com/11482921/164454578-73c77392-77de-49c5-b03c-c36631723192.png) | ![](https://user-images.githubusercontent.com/11482921/164454574-b1ede5f0-4520-4eaa-8f59-086751a34e62.png) | ![](https://user-images.githubusercontent.com/11482921/164454567-4cb3fdd8-6a2d-4016-85b2-a305a8ff80e4.png) | ![](https://user-images.githubusercontent.com/11482921/164454583-7f243f20-eca3-4500-ac43-eb058a4a101a.png) |
|
42 |
+
|![huluxiongdi_2_patch](https://user-images.githubusercontent.com/11482921/164453482-0726c842-337e-40ec-bf6c-f902ee956a8b.png) | ![](https://user-images.githubusercontent.com/11482921/164453480-71d5e091-5bfa-4c77-9c57-4e37f66ca0a3.png) | ![](https://user-images.githubusercontent.com/11482921/164453468-c295d3c9-3661-45f0-9ecd-406a1877f76e.png) | ![](https://user-images.githubusercontent.com/11482921/164453486-3091887c-587c-450e-b6fe-905cb518d57e.png) |
|
43 |
+
|
44 |
+
**其他更好的结果**
|
45 |
+
|
46 |
+
| 输入 | waifu2x | Real-CUGAN | RealESRGAN<br>AnimeVideo-v3 |
|
47 |
+
| :---: | :---: | :---: | :---: |
|
48 |
+
|![Japan_v2_1_128525_s1_patch](https://user-images.githubusercontent.com/11482921/164454933-67697f7c-b6ef-47dc-bfca-822a78af8acf.png) | ![](https://user-images.githubusercontent.com/11482921/164454931-9450de7c-f0b3-4638-9c1e-0668e0c41ef0.png) | ![](https://user-images.githubusercontent.com/11482921/164454926-ed746976-786d-41c5-8a83-7693cd774c3a.png) | ![](https://user-images.githubusercontent.com/11482921/164454936-8abdf0f0-fb30-40eb-8281-3b46c0bcb9ae.png) |
|
49 |
+
|![tianshuqitan_2_patch](https://user-images.githubusercontent.com/11482921/164456948-807c1476-90b6-4507-81da-cb986d01600c.png) | ![](https://user-images.githubusercontent.com/11482921/164456943-25e89de9-d7e5-4f61-a2e1-96786af6ae9e.png) | ![](https://user-images.githubusercontent.com/11482921/164456954-b468c447-59f5-4594-9693-3683e44ba3e6.png) | ![](https://user-images.githubusercontent.com/11482921/164456957-640f910c-3b04-407c-ac20-044d72e19735.png) |
|
50 |
+
|![00000051_patch](https://user-images.githubusercontent.com/11482921/164456044-e9a6b3fa-b24e-4eb7-acf9-1f7746551b1e.png) ![00000051_patch](https://user-images.githubusercontent.com/11482921/164456421-b67245b0-767d-4250-9105-80bbe507ecfc.png) | ![](https://user-images.githubusercontent.com/11482921/164456040-85763cf2-cb28-4ba3-abb6-1dbb48c55713.png) ![](https://user-images.githubusercontent.com/11482921/164456419-59cf342e-bc1e-4044-868c-e1090abad313.png) | ![](https://user-images.githubusercontent.com/11482921/164456031-4244bb7b-8649-4e01-86f4-40c2099c5afd.png) ![](https://user-images.githubusercontent.com/11482921/164456411-b6afcbe9-c054-448d-a6df-96d3ba3047f8.png) | ![](https://user-images.githubusercontent.com/11482921/164456035-12e270be-fd52-46d4-b18a-3d3b680731fe.png) ![](https://user-images.githubusercontent.com/11482921/164456417-dcaa8b62-f497-427d-b2d2-f390f1200fb9.png) |
|
51 |
+
|![00000099_patch](https://user-images.githubusercontent.com/11482921/164455312-6411b6e1-5823-4131-a4b0-a6be8a9ae89f.png) | ![](https://user-images.githubusercontent.com/11482921/164455310-f2b99646-3a22-47a4-805b-dc451ac86ddb.png) | ![](https://user-images.githubusercontent.com/11482921/164455294-35471b42-2826-4451-b7ec-6de01344954c.png) | ![](https://user-images.githubusercontent.com/11482921/164455305-fa4c9758-564a-4081-8b4e-f11057a0404d.png) |
|
52 |
+
|![00000016_patch](https://user-images.githubusercontent.com/11482921/164455672-447353c9-2da2-4fcb-ba4a-7dd6b94c19c1.png) | ![](https://user-images.githubusercontent.com/11482921/164455669-df384631-baaa-42f8-9150-40f658471558.png) | ![](https://user-images.githubusercontent.com/11482921/164455657-68006bf0-138d-4981-aaca-8aa927d2f78a.png) | ![](https://user-images.githubusercontent.com/11482921/164455664-0342b93e-a62a-4b36-a90e-7118f3f1e45d.png) |
|
53 |
+
|
54 |
+
## 推理速度比较
|
55 |
+
|
56 |
+
### PyTorch
|
57 |
+
|
58 |
+
请注意,我们只报告了**模型推理**的时间, 而忽略了读写硬盘的时间.
|
59 |
+
|
60 |
+
| GPU | 输入尺寸 | waifu2x | Real-CUGAN | RealESRGAN-AnimeVideo-v3
|
61 |
+
| :---: | :---: | :---: | :---: | :---: |
|
62 |
+
| V100 | 1921 x 1080 | - | 3.4 fps | **10.0** fps |
|
63 |
+
| V100 | 1280 x 720 | - | 7.2 fps | **22.6** fps |
|
64 |
+
| V100 | 640 x 480 | - | 24.4 fps | **65.9** fps |
|
65 |
+
|
66 |
+
### ncnn
|
67 |
+
|
68 |
+
- [ ] TODO
|
RealESRGANv030/docs/anime_model.md
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Anime Model
|
2 |
+
|
3 |
+
: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.
|
4 |
+
|
5 |
+
- [How to Use](#how-to-use)
|
6 |
+
- [PyTorch Inference](#pytorch-inference)
|
7 |
+
- [ncnn Executable File](#ncnn-executable-file)
|
8 |
+
- [Comparisons with waifu2x](#comparisons-with-waifu2x)
|
9 |
+
- [Comparisons with Sliding Bars](#comparisons-with-sliding-bars)
|
10 |
+
|
11 |
+
<p align="center">
|
12 |
+
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_1.png">
|
13 |
+
</p>
|
14 |
+
|
15 |
+
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.
|
16 |
+
|
17 |
+
<https://user-images.githubusercontent.com/17445847/131535127-613250d4-f754-4e20-9720-2f9608ad0675.mp4>
|
18 |
+
|
19 |
+
## How to Use
|
20 |
+
|
21 |
+
### PyTorch Inference
|
22 |
+
|
23 |
+
Pre-trained models: [RealESRGAN_x4plus_anime_6B](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth)
|
24 |
+
|
25 |
+
```bash
|
26 |
+
# download model
|
27 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights
|
28 |
+
# inference
|
29 |
+
python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
|
30 |
+
```
|
31 |
+
|
32 |
+
### ncnn Executable File
|
33 |
+
|
34 |
+
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**.
|
35 |
+
|
36 |
+
Taking the Windows as example, run:
|
37 |
+
|
38 |
+
```bash
|
39 |
+
./realesrgan-ncnn-vulkan.exe -i input.jpg -o output.png -n realesrgan-x4plus-anime
|
40 |
+
```
|
41 |
+
|
42 |
+
## Comparisons with waifu2x
|
43 |
+
|
44 |
+
We compare Real-ESRGAN-anime with [waifu2x](https://github.com/nihui/waifu2x-ncnn-vulkan). We use the `-n 2 -s 4` for waifu2x.
|
45 |
+
|
46 |
+
<p align="center">
|
47 |
+
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_1.png">
|
48 |
+
</p>
|
49 |
+
<p align="center">
|
50 |
+
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_2.png">
|
51 |
+
</p>
|
52 |
+
<p align="center">
|
53 |
+
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_3.png">
|
54 |
+
</p>
|
55 |
+
<p align="center">
|
56 |
+
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_4.png">
|
57 |
+
</p>
|
58 |
+
<p align="center">
|
59 |
+
<img src="https://raw.githubusercontent.com/xinntao/public-figures/master/Real-ESRGAN/cmp_realesrgan_anime_5.png">
|
60 |
+
</p>
|
61 |
+
|
62 |
+
## Comparisons with Sliding Bars
|
63 |
+
|
64 |
+
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.
|
65 |
+
|
66 |
+
<https://user-images.githubusercontent.com/17445847/131536647-a2fbf896-b495-4a9f-b1dd-ca7bbc90101a.mp4>
|
67 |
+
|
68 |
+
<https://user-images.githubusercontent.com/17445847/131536742-6d9d82b6-9765-4296-a15f-18f9aeaa5465.mp4>
|
RealESRGANv030/docs/anime_video_model.md
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Anime Video Models
|
2 |
+
|
3 |
+
:white_check_mark: We add small models that are optimized for anime videos :-)<br>
|
4 |
+
More comparisons can be found in [anime_comparisons.md](anime_comparisons.md)
|
5 |
+
|
6 |
+
- [How to Use](#how-to-use)
|
7 |
+
- [PyTorch Inference](#pytorch-inference)
|
8 |
+
- [ncnn Executable File](#ncnn-executable-file)
|
9 |
+
- [Step 1: Use ffmpeg to extract frames from video](#step-1-use-ffmpeg-to-extract-frames-from-video)
|
10 |
+
- [Step 2: Inference with Real-ESRGAN executable file](#step-2-inference-with-real-esrgan-executable-file)
|
11 |
+
- [Step 3: Merge the enhanced frames back into a video](#step-3-merge-the-enhanced-frames-back-into-a-video)
|
12 |
+
- [More Demos](#more-demos)
|
13 |
+
|
14 |
+
| Models | Scale | Description |
|
15 |
+
| ---------------------------------------------------------------------------------------------------------------------------------- | :---- | :----------------------------- |
|
16 |
+
| [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 |
|
17 |
+
|
18 |
+
Note: <br>
|
19 |
+
<sup>1</sup> This model can also be used for X1, X2, X3.
|
20 |
+
|
21 |
+
---
|
22 |
+
|
23 |
+
The following are some demos (best view in the full screen mode).
|
24 |
+
|
25 |
+
<https://user-images.githubusercontent.com/17445847/145706977-98bc64a4-af27-481c-8abe-c475e15db7ff.MP4>
|
26 |
+
|
27 |
+
<https://user-images.githubusercontent.com/17445847/145707055-6a4b79cb-3d9d-477f-8610-c6be43797133.MP4>
|
28 |
+
|
29 |
+
<https://user-images.githubusercontent.com/17445847/145783523-f4553729-9f03-44a8-a7cc-782aadf67b50.MP4>
|
30 |
+
|
31 |
+
## How to Use
|
32 |
+
|
33 |
+
### PyTorch Inference
|
34 |
+
|
35 |
+
```bash
|
36 |
+
# download model
|
37 |
+
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth -P weights
|
38 |
+
# single gpu and single process inference
|
39 |
+
CUDA_VISIBLE_DEVICES=0 python inference_realesrgan_video.py -i inputs/video/onepiece_demo.mp4 -n realesr-animevideov3 -s 2 --suffix outx2
|
40 |
+
# single gpu and multi process inference (you can use multi-processing to improve GPU utilization)
|
41 |
+
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
|
42 |
+
# multi gpu and multi process inference
|
43 |
+
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
|
44 |
+
```
|
45 |
+
|
46 |
+
```console
|
47 |
+
Usage:
|
48 |
+
--num_process_per_gpu The total number of process is num_gpu * num_process_per_gpu. The bottleneck of
|
49 |
+
the program lies on the IO, so the GPUs are usually not fully utilized. To alleviate
|
50 |
+
this issue, you can use multi-processing by setting this parameter. As long as it
|
51 |
+
does not exceed the CUDA memory
|
52 |
+
--extract_frame_first If you encounter ffmpeg error when using multi-processing, you can turn this option on.
|
53 |
+
```
|
54 |
+
|
55 |
+
### NCNN Executable File
|
56 |
+
|
57 |
+
#### Step 1: Use ffmpeg to extract frames from video
|
58 |
+
|
59 |
+
```bash
|
60 |
+
ffmpeg -i onepiece_demo.mp4 -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 tmp_frames/frame%08d.png
|
61 |
+
```
|
62 |
+
|
63 |
+
- Remember to create the folder `tmp_frames` ahead
|
64 |
+
|
65 |
+
#### Step 2: Inference with Real-ESRGAN executable file
|
66 |
+
|
67 |
+
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**
|
68 |
+
|
69 |
+
1. Taking the Windows as example, run:
|
70 |
+
|
71 |
+
```bash
|
72 |
+
./realesrgan-ncnn-vulkan.exe -i tmp_frames -o out_frames -n realesr-animevideov3 -s 2 -f jpg
|
73 |
+
```
|
74 |
+
|
75 |
+
- Remember to create the folder `out_frames` ahead
|
76 |
+
|
77 |
+
#### Step 3: Merge the enhanced frames back into a video
|
78 |
+
|
79 |
+
1. First obtain fps from input videos by
|
80 |
+
|
81 |
+
```bash
|
82 |
+
ffmpeg -i onepiece_demo.mp4
|
83 |
+
```
|
84 |
+
|
85 |
+
```console
|
86 |
+
Usage:
|
87 |
+
-i input video path
|
88 |
+
```
|
89 |
+
|
90 |
+
You will get the output similar to the following screenshot.
|
91 |
+
|
92 |
+
<p align="center">
|
93 |
+
<img src="https://user-images.githubusercontent.com/17445847/145710145-c4f3accf-b82f-4307-9f20-3803a2c73f57.png">
|
94 |
+
</p>
|
95 |
+
|
96 |
+
2. Merge frames
|
97 |
+
|
98 |
+
```bash
|
99 |
+
ffmpeg -r 23.98 -i out_frames/frame%08d.jpg -c:v libx264 -r 23.98 -pix_fmt yuv420p output.mp4
|
100 |
+
```
|
101 |
+
|
102 |
+
```console
|
103 |
+
Usage:
|
104 |
+
-i input video path
|
105 |
+
-c:v video encoder (usually we use libx264)
|
106 |
+
-r fps, remember to modify it to meet your needs
|
107 |
+
-pix_fmt pixel format in video
|
108 |
+
```
|
109 |
+
|
110 |
+
If you also want to copy audio from the input videos, run:
|
111 |
+
|
112 |
+
```bash
|
113 |
+
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
|
114 |
+
```
|
115 |
+
|
116 |
+
```console
|
117 |
+
Usage:
|
118 |
+
-i input video path, here we use two input streams
|
119 |
+
-c:v video encoder (usually we use libx264)
|
120 |
+
-r fps, remember to modify it to meet your needs
|
121 |
+
-pix_fmt pixel format in video
|
122 |
+
```
|
123 |
+
|
124 |
+
## More Demos
|
125 |
+
|
126 |
+
- Input video for One Piece:
|
127 |
+
|
128 |
+
<https://user-images.githubusercontent.com/17445847/145706822-0e83d9c4-78ef-40ee-b2a4-d8b8c3692d17.mp4>
|
129 |
+
|
130 |
+
- Out video for One Piece
|
131 |
+
|
132 |
+
<https://user-images.githubusercontent.com/17445847/164960481-759658cf-fcb8-480c-b888-cecb606e8744.mp4>
|
133 |
+
|
134 |
+
**More comparisons**
|
135 |
+
|
136 |
+
<https://user-images.githubusercontent.com/17445847/145707458-04a5e9b9-2edd-4d1f-b400-380a72e5f5e6.MP4>
|
RealESRGANv030/docs/feedback.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Feedback 反馈
|
2 |
+
|
3 |
+
## 动漫插画模型
|
4 |
+
|
5 |
+
1. 视频处理不了: 目前的模型,不是针对视频的,所以视频效果很很不好。我们在探究针对视频的模型了
|
6 |
+
1. 景深虚化有问题: 现在的模型把一些景深 和 特意的虚化 都复原了,感觉不好。这个后面我们会考虑把这个信息结合进入。一个简单的做法是识别景深和虚化,然后作为条件告诉神经网络,哪些地方复原强一些,哪些地方复原要弱一些
|
7 |
+
1. 不可以调节: 像 Waifu2X 可以调节。可以根据自己的喜好,做调整,但是 Real-ESRGAN-anime 并不可以。导致有些恢复效果过了
|
8 |
+
1. 把原来的风格改变了: 不同的动漫插画都有自己的风格,现在的 Real-ESRGAN-anime 倾向于恢复成一种风格(这是受到训练数据集影响的)。风格是动漫很重要的一个要素,所以要尽可能保持
|
9 |
+
1. 模型太大: 目前的模型处理太慢,能够更快。这个我们有相关的工作在探究,希望能够尽快有结果,并应用到 Real-ESRGAN 这一系列的模型上
|
10 |
+
|
11 |
+
Thanks for the [detailed and valuable feedbacks/suggestions](https://github.com/xinntao/Real-ESRGAN/issues/131) by [2ji3150](https://github.com/2ji3150).
|
RealESRGANv030/docs/model_zoo.md
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# :european_castle: Model Zoo
|
2 |
+
|
3 |
+
- [For General Images](#for-general-images)
|
4 |
+
- [For Anime Images](#for-anime-images)
|
5 |
+
- [For Anime Videos](#for-anime-videos)
|
6 |
+
|
7 |
+
---
|
8 |
+
|
9 |
+
## For General Images
|
10 |
+
|
11 |
+
| Models | Scale | Description |
|
12 |
+
| ------------------------------------------------------------------------------------------------------------------------------- | :---- | :------------------------------------------- |
|
13 |
+
| [RealESRGAN_x4plus](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth) | X4 | X4 model for general images |
|
14 |
+
| [RealESRGAN_x2plus](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth) | X2 | X2 model for general images |
|
15 |
+
| [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) |
|
16 |
+
| [official ESRGAN_x4](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth) | X4 | official ESRGAN model |
|
17 |
+
| [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 |
|
18 |
+
|
19 |
+
The following models are **discriminators**, which are usually used for fine-tuning.
|
20 |
+
|
21 |
+
| Models | Corresponding model |
|
22 |
+
| ---------------------------------------------------------------------------------------------------------------------- | :------------------ |
|
23 |
+
| [RealESRGAN_x4plus_netD](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth) | RealESRGAN_x4plus |
|
24 |
+
| [RealESRGAN_x2plus_netD](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x2plus_netD.pth) | RealESRGAN_x2plus |
|
25 |
+
|
26 |
+
## For Anime Images / Illustrations
|
27 |
+
|
28 |
+
| Models | Scale | Description |
|
29 |
+
| ------------------------------------------------------------------------------------------------------------------------------ | :---- | :---------------------------------------------------------- |
|
30 |
+
| [RealESRGAN_x4plus_anime_6B](https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth) | X4 | Optimized for anime images; 6 RRDB blocks (smaller network) |
|
31 |
+
|
32 |
+
The following models are **discriminators**, which are usually used for fine-tuning.
|
33 |
+
|
34 |
+
| Models | Corresponding model |
|
35 |
+
| ---------------------------------------------------------------------------------------------------------------------------------------- | :------------------------- |
|
36 |
+
| [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 |
|
37 |
+
|
38 |
+
## For Animation Videos
|
39 |
+
|
40 |
+
| Models | Scale | Description |
|
41 |
+
| ---------------------------------------------------------------------------------------------------------------------------------- | :---- | :----------------------------- |
|
42 |
+
| [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 |
|
43 |
+
|
44 |
+
Note: <br>
|
45 |
+
<sup>1</sup> This model can also be used for X1, X2, X3.
|
46 |
+
|
47 |
+
The following models are **discriminators**, which are usually used for fine-tuning.
|
48 |
+
|
49 |
+
TODO
|
RealESRGANv030/docs/ncnn_conversion.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Instructions on converting to NCNN models
|
2 |
+
|
3 |
+
1. Convert to onnx model with `scripts/pytorch2onnx.py`. Remember to modify codes accordingly
|
4 |
+
1. Convert onnx model to ncnn model
|
5 |
+
1. `cd ncnn-master\ncnn\build\tools\onnx`
|
6 |
+
1. `onnx2ncnn.exe realesrgan-x4.onnx realesrgan-x4-raw.param realesrgan-x4-raw.bin`
|
7 |
+
1. Optimize ncnn model
|
8 |
+
1. fp16 mode
|
9 |
+
1. `cd ncnn-master\ncnn\build\tools`
|
10 |
+
1. `ncnnoptimize.exe realesrgan-x4-raw.param realesrgan-x4-raw.bin realesrgan-x4.param realesrgan-x4.bin 1`
|
11 |
+
1. Modify the blob name in `realesrgan-x4.param`: `data` and `output`
|
RealESRGANv030/experiments/pretrained_models/README.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
# Put downloaded pre-trained models here
|
RealESRGANv030/inference_realesrgan.py
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import cv2
|
3 |
+
import glob
|
4 |
+
import os
|
5 |
+
from basicsr.archs.rrdbnet_arch import RRDBNet
|
6 |
+
from basicsr.utils.download_util import load_file_from_url
|
7 |
+
|
8 |
+
from realesrgan import RealESRGANer
|
9 |
+
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
|
10 |
+
|
11 |
+
|
12 |
+
def main():
|
13 |
+
"""Inference demo for Real-ESRGAN.
|
14 |
+
"""
|
15 |
+
parser = argparse.ArgumentParser()
|
16 |
+
parser.add_argument('-i', '--input', type=str, default='inputs', help='Input image or folder')
|
17 |
+
parser.add_argument(
|
18 |
+
'-n',
|
19 |
+
'--model_name',
|
20 |
+
type=str,
|
21 |
+
default='RealESRGAN_x4plus',
|
22 |
+
help=('Model names: RealESRGAN_x4plus | RealESRNet_x4plus | RealESRGAN_x4plus_anime_6B | RealESRGAN_x2plus | '
|
23 |
+
'realesr-animevideov3 | realesr-general-x4v3'))
|
24 |
+
parser.add_argument('-o', '--output', type=str, default='results', help='Output folder')
|
25 |
+
parser.add_argument(
|
26 |
+
'-dn',
|
27 |
+
'--denoise_strength',
|
28 |
+
type=float,
|
29 |
+
default=0.5,
|
30 |
+
help=('Denoise strength. 0 for weak denoise (keep noise), 1 for strong denoise ability. '
|
31 |
+
'Only used for the realesr-general-x4v3 model'))
|
32 |
+
parser.add_argument('-s', '--outscale', type=float, default=4, help='The final upsampling scale of the image')
|
33 |
+
parser.add_argument(
|
34 |
+
'--model_path', type=str, default=None, help='[Option] Model path. Usually, you do not need to specify it')
|
35 |
+
parser.add_argument('--suffix', type=str, default='out', help='Suffix of the restored image')
|
36 |
+
parser.add_argument('-t', '--tile', type=int, default=0, help='Tile size, 0 for no tile during testing')
|
37 |
+
parser.add_argument('--tile_pad', type=int, default=10, help='Tile padding')
|
38 |
+
parser.add_argument('--pre_pad', type=int, default=0, help='Pre padding size at each border')
|
39 |
+
parser.add_argument('--face_enhance', action='store_true', help='Use GFPGAN to enhance face')
|
40 |
+
parser.add_argument(
|
41 |
+
'--fp32', action='store_true', help='Use fp32 precision during inference. Default: fp16 (half precision).')
|
42 |
+
parser.add_argument(
|
43 |
+
'--alpha_upsampler',
|
44 |
+
type=str,
|
45 |
+
default='realesrgan',
|
46 |
+
help='The upsampler for the alpha channels. Options: realesrgan | bicubic')
|
47 |
+
parser.add_argument(
|
48 |
+
'--ext',
|
49 |
+
type=str,
|
50 |
+
default='auto',
|
51 |
+
help='Image extension. Options: auto | jpg | png, auto means using the same extension as inputs')
|
52 |
+
parser.add_argument(
|
53 |
+
'-g', '--gpu-id', type=int, default=None, help='gpu device to use (default=None) can be 0,1,2 for multi-gpu')
|
54 |
+
|
55 |
+
args = parser.parse_args()
|
56 |
+
|
57 |
+
# determine models according to model names
|
58 |
+
args.model_name = args.model_name.split('.')[0]
|
59 |
+
if args.model_name == 'RealESRGAN_x4plus': # x4 RRDBNet model
|
60 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
61 |
+
netscale = 4
|
62 |
+
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth']
|
63 |
+
elif args.model_name == 'RealESRNet_x4plus': # x4 RRDBNet model
|
64 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
65 |
+
netscale = 4
|
66 |
+
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth']
|
67 |
+
elif args.model_name == 'RealESRGAN_x4plus_anime_6B': # x4 RRDBNet model with 6 blocks
|
68 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4)
|
69 |
+
netscale = 4
|
70 |
+
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth']
|
71 |
+
elif args.model_name == 'RealESRGAN_x2plus': # x2 RRDBNet model
|
72 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
|
73 |
+
netscale = 2
|
74 |
+
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth']
|
75 |
+
elif args.model_name == 'realesr-animevideov3': # x4 VGG-style model (XS size)
|
76 |
+
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu')
|
77 |
+
netscale = 4
|
78 |
+
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth']
|
79 |
+
elif args.model_name == 'realesr-general-x4v3': # x4 VGG-style model (S size)
|
80 |
+
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
81 |
+
netscale = 4
|
82 |
+
file_url = [
|
83 |
+
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth',
|
84 |
+
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth'
|
85 |
+
]
|
86 |
+
|
87 |
+
# determine model paths
|
88 |
+
if args.model_path is not None:
|
89 |
+
model_path = args.model_path
|
90 |
+
else:
|
91 |
+
model_path = os.path.join('weights', args.model_name + '.pth')
|
92 |
+
if not os.path.isfile(model_path):
|
93 |
+
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
94 |
+
for url in file_url:
|
95 |
+
# model_path will be updated
|
96 |
+
model_path = load_file_from_url(
|
97 |
+
url=url, model_dir=os.path.join(ROOT_DIR, 'weights'), progress=True, file_name=None)
|
98 |
+
|
99 |
+
# use dni to control the denoise strength
|
100 |
+
dni_weight = None
|
101 |
+
if args.model_name == 'realesr-general-x4v3' and args.denoise_strength != 1:
|
102 |
+
wdn_model_path = model_path.replace('realesr-general-x4v3', 'realesr-general-wdn-x4v3')
|
103 |
+
model_path = [model_path, wdn_model_path]
|
104 |
+
dni_weight = [args.denoise_strength, 1 - args.denoise_strength]
|
105 |
+
|
106 |
+
# restorer
|
107 |
+
upsampler = RealESRGANer(
|
108 |
+
scale=netscale,
|
109 |
+
model_path=model_path,
|
110 |
+
dni_weight=dni_weight,
|
111 |
+
model=model,
|
112 |
+
tile=args.tile,
|
113 |
+
tile_pad=args.tile_pad,
|
114 |
+
pre_pad=args.pre_pad,
|
115 |
+
half=not args.fp32,
|
116 |
+
gpu_id=args.gpu_id)
|
117 |
+
|
118 |
+
if args.face_enhance: # Use GFPGAN for face enhancement
|
119 |
+
from gfpgan import GFPGANer
|
120 |
+
face_enhancer = GFPGANer(
|
121 |
+
model_path='https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth',
|
122 |
+
upscale=args.outscale,
|
123 |
+
arch='clean',
|
124 |
+
channel_multiplier=2,
|
125 |
+
bg_upsampler=upsampler)
|
126 |
+
os.makedirs(args.output, exist_ok=True)
|
127 |
+
|
128 |
+
if os.path.isfile(args.input):
|
129 |
+
paths = [args.input]
|
130 |
+
else:
|
131 |
+
paths = sorted(glob.glob(os.path.join(args.input, '*')))
|
132 |
+
|
133 |
+
for idx, path in enumerate(paths):
|
134 |
+
imgname, extension = os.path.splitext(os.path.basename(path))
|
135 |
+
print('Testing', idx, imgname)
|
136 |
+
|
137 |
+
img = cv2.imread(path, cv2.IMREAD_UNCHANGED)
|
138 |
+
if len(img.shape) == 3 and img.shape[2] == 4:
|
139 |
+
img_mode = 'RGBA'
|
140 |
+
else:
|
141 |
+
img_mode = None
|
142 |
+
|
143 |
+
try:
|
144 |
+
if args.face_enhance:
|
145 |
+
_, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
|
146 |
+
else:
|
147 |
+
output, _ = upsampler.enhance(img, outscale=args.outscale)
|
148 |
+
except RuntimeError as error:
|
149 |
+
print('Error', error)
|
150 |
+
print('If you encounter CUDA out of memory, try to set --tile with a smaller number.')
|
151 |
+
else:
|
152 |
+
if args.ext == 'auto':
|
153 |
+
extension = extension[1:]
|
154 |
+
else:
|
155 |
+
extension = args.ext
|
156 |
+
if img_mode == 'RGBA': # RGBA images should be saved in png format
|
157 |
+
extension = 'png'
|
158 |
+
if args.suffix == '':
|
159 |
+
save_path = os.path.join(args.output, f'{imgname}.{extension}')
|
160 |
+
else:
|
161 |
+
save_path = os.path.join(args.output, f'{imgname}_{args.suffix}.{extension}')
|
162 |
+
cv2.imwrite(save_path, output)
|
163 |
+
|
164 |
+
|
165 |
+
if __name__ == '__main__':
|
166 |
+
main()
|
RealESRGANv030/inference_realesrgan_video.py
ADDED
@@ -0,0 +1,398 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import cv2
|
3 |
+
import glob
|
4 |
+
import mimetypes
|
5 |
+
import numpy as np
|
6 |
+
import os
|
7 |
+
import shutil
|
8 |
+
import subprocess
|
9 |
+
import torch
|
10 |
+
from basicsr.archs.rrdbnet_arch import RRDBNet
|
11 |
+
from basicsr.utils.download_util import load_file_from_url
|
12 |
+
from os import path as osp
|
13 |
+
from tqdm import tqdm
|
14 |
+
|
15 |
+
from realesrgan import RealESRGANer
|
16 |
+
from realesrgan.archs.srvgg_arch import SRVGGNetCompact
|
17 |
+
|
18 |
+
try:
|
19 |
+
import ffmpeg
|
20 |
+
except ImportError:
|
21 |
+
import pip
|
22 |
+
pip.main(['install', '--user', 'ffmpeg-python'])
|
23 |
+
import ffmpeg
|
24 |
+
|
25 |
+
|
26 |
+
def get_video_meta_info(video_path):
|
27 |
+
ret = {}
|
28 |
+
probe = ffmpeg.probe(video_path)
|
29 |
+
video_streams = [stream for stream in probe['streams'] if stream['codec_type'] == 'video']
|
30 |
+
has_audio = any(stream['codec_type'] == 'audio' for stream in probe['streams'])
|
31 |
+
ret['width'] = video_streams[0]['width']
|
32 |
+
ret['height'] = video_streams[0]['height']
|
33 |
+
ret['fps'] = eval(video_streams[0]['avg_frame_rate'])
|
34 |
+
ret['audio'] = ffmpeg.input(video_path).audio if has_audio else None
|
35 |
+
ret['nb_frames'] = int(video_streams[0]['nb_frames'])
|
36 |
+
return ret
|
37 |
+
|
38 |
+
|
39 |
+
def get_sub_video(args, num_process, process_idx):
|
40 |
+
if num_process == 1:
|
41 |
+
return args.input
|
42 |
+
meta = get_video_meta_info(args.input)
|
43 |
+
duration = int(meta['nb_frames'] / meta['fps'])
|
44 |
+
part_time = duration // num_process
|
45 |
+
print(f'duration: {duration}, part_time: {part_time}')
|
46 |
+
os.makedirs(osp.join(args.output, f'{args.video_name}_inp_tmp_videos'), exist_ok=True)
|
47 |
+
out_path = osp.join(args.output, f'{args.video_name}_inp_tmp_videos', f'{process_idx:03d}.mp4')
|
48 |
+
cmd = [
|
49 |
+
args.ffmpeg_bin, f'-i {args.input}', '-ss', f'{part_time * process_idx}',
|
50 |
+
f'-to {part_time * (process_idx + 1)}' if process_idx != num_process - 1 else '', '-async 1', out_path, '-y'
|
51 |
+
]
|
52 |
+
print(' '.join(cmd))
|
53 |
+
subprocess.call(' '.join(cmd), shell=True)
|
54 |
+
return out_path
|
55 |
+
|
56 |
+
|
57 |
+
class Reader:
|
58 |
+
|
59 |
+
def __init__(self, args, total_workers=1, worker_idx=0):
|
60 |
+
self.args = args
|
61 |
+
input_type = mimetypes.guess_type(args.input)[0]
|
62 |
+
self.input_type = 'folder' if input_type is None else input_type
|
63 |
+
self.paths = [] # for image&folder type
|
64 |
+
self.audio = None
|
65 |
+
self.input_fps = None
|
66 |
+
if self.input_type.startswith('video'):
|
67 |
+
video_path = get_sub_video(args, total_workers, worker_idx)
|
68 |
+
self.stream_reader = (
|
69 |
+
ffmpeg.input(video_path).output('pipe:', format='rawvideo', pix_fmt='bgr24',
|
70 |
+
loglevel='error').run_async(
|
71 |
+
pipe_stdin=True, pipe_stdout=True, cmd=args.ffmpeg_bin))
|
72 |
+
meta = get_video_meta_info(video_path)
|
73 |
+
self.width = meta['width']
|
74 |
+
self.height = meta['height']
|
75 |
+
self.input_fps = meta['fps']
|
76 |
+
self.audio = meta['audio']
|
77 |
+
self.nb_frames = meta['nb_frames']
|
78 |
+
|
79 |
+
else:
|
80 |
+
if self.input_type.startswith('image'):
|
81 |
+
self.paths = [args.input]
|
82 |
+
else:
|
83 |
+
paths = sorted(glob.glob(os.path.join(args.input, '*')))
|
84 |
+
tot_frames = len(paths)
|
85 |
+
num_frame_per_worker = tot_frames // total_workers + (1 if tot_frames % total_workers else 0)
|
86 |
+
self.paths = paths[num_frame_per_worker * worker_idx:num_frame_per_worker * (worker_idx + 1)]
|
87 |
+
|
88 |
+
self.nb_frames = len(self.paths)
|
89 |
+
assert self.nb_frames > 0, 'empty folder'
|
90 |
+
from PIL import Image
|
91 |
+
tmp_img = Image.open(self.paths[0])
|
92 |
+
self.width, self.height = tmp_img.size
|
93 |
+
self.idx = 0
|
94 |
+
|
95 |
+
def get_resolution(self):
|
96 |
+
return self.height, self.width
|
97 |
+
|
98 |
+
def get_fps(self):
|
99 |
+
if self.args.fps is not None:
|
100 |
+
return self.args.fps
|
101 |
+
elif self.input_fps is not None:
|
102 |
+
return self.input_fps
|
103 |
+
return 24
|
104 |
+
|
105 |
+
def get_audio(self):
|
106 |
+
return self.audio
|
107 |
+
|
108 |
+
def __len__(self):
|
109 |
+
return self.nb_frames
|
110 |
+
|
111 |
+
def get_frame_from_stream(self):
|
112 |
+
img_bytes = self.stream_reader.stdout.read(self.width * self.height * 3) # 3 bytes for one pixel
|
113 |
+
if not img_bytes:
|
114 |
+
return None
|
115 |
+
img = np.frombuffer(img_bytes, np.uint8).reshape([self.height, self.width, 3])
|
116 |
+
return img
|
117 |
+
|
118 |
+
def get_frame_from_list(self):
|
119 |
+
if self.idx >= self.nb_frames:
|
120 |
+
return None
|
121 |
+
img = cv2.imread(self.paths[self.idx])
|
122 |
+
self.idx += 1
|
123 |
+
return img
|
124 |
+
|
125 |
+
def get_frame(self):
|
126 |
+
if self.input_type.startswith('video'):
|
127 |
+
return self.get_frame_from_stream()
|
128 |
+
else:
|
129 |
+
return self.get_frame_from_list()
|
130 |
+
|
131 |
+
def close(self):
|
132 |
+
if self.input_type.startswith('video'):
|
133 |
+
self.stream_reader.stdin.close()
|
134 |
+
self.stream_reader.wait()
|
135 |
+
|
136 |
+
|
137 |
+
class Writer:
|
138 |
+
|
139 |
+
def __init__(self, args, audio, height, width, video_save_path, fps):
|
140 |
+
out_width, out_height = int(width * args.outscale), int(height * args.outscale)
|
141 |
+
if out_height > 2160:
|
142 |
+
print('You are generating video that is larger than 4K, which will be very slow due to IO speed.',
|
143 |
+
'We highly recommend to decrease the outscale(aka, -s).')
|
144 |
+
|
145 |
+
if audio is not None:
|
146 |
+
self.stream_writer = (
|
147 |
+
ffmpeg.input('pipe:', format='rawvideo', pix_fmt='bgr24', s=f'{out_width}x{out_height}',
|
148 |
+
framerate=fps).output(
|
149 |
+
audio,
|
150 |
+
video_save_path,
|
151 |
+
pix_fmt='yuv420p',
|
152 |
+
vcodec='libx264',
|
153 |
+
loglevel='error',
|
154 |
+
acodec='copy').overwrite_output().run_async(
|
155 |
+
pipe_stdin=True, pipe_stdout=True, cmd=args.ffmpeg_bin))
|
156 |
+
else:
|
157 |
+
self.stream_writer = (
|
158 |
+
ffmpeg.input('pipe:', format='rawvideo', pix_fmt='bgr24', s=f'{out_width}x{out_height}',
|
159 |
+
framerate=fps).output(
|
160 |
+
video_save_path, pix_fmt='yuv420p', vcodec='libx264',
|
161 |
+
loglevel='error').overwrite_output().run_async(
|
162 |
+
pipe_stdin=True, pipe_stdout=True, cmd=args.ffmpeg_bin))
|
163 |
+
|
164 |
+
def write_frame(self, frame):
|
165 |
+
frame = frame.astype(np.uint8).tobytes()
|
166 |
+
self.stream_writer.stdin.write(frame)
|
167 |
+
|
168 |
+
def close(self):
|
169 |
+
self.stream_writer.stdin.close()
|
170 |
+
self.stream_writer.wait()
|
171 |
+
|
172 |
+
|
173 |
+
def inference_video(args, video_save_path, device=None, total_workers=1, worker_idx=0):
|
174 |
+
# ---------------------- determine models according to model names ---------------------- #
|
175 |
+
args.model_name = args.model_name.split('.pth')[0]
|
176 |
+
if args.model_name == 'RealESRGAN_x4plus': # x4 RRDBNet model
|
177 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
178 |
+
netscale = 4
|
179 |
+
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth']
|
180 |
+
elif args.model_name == 'RealESRNet_x4plus': # x4 RRDBNet model
|
181 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
|
182 |
+
netscale = 4
|
183 |
+
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth']
|
184 |
+
elif args.model_name == 'RealESRGAN_x4plus_anime_6B': # x4 RRDBNet model with 6 blocks
|
185 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4)
|
186 |
+
netscale = 4
|
187 |
+
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth']
|
188 |
+
elif args.model_name == 'RealESRGAN_x2plus': # x2 RRDBNet model
|
189 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
|
190 |
+
netscale = 2
|
191 |
+
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth']
|
192 |
+
elif args.model_name == 'realesr-animevideov3': # x4 VGG-style model (XS size)
|
193 |
+
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu')
|
194 |
+
netscale = 4
|
195 |
+
file_url = ['https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth']
|
196 |
+
elif args.model_name == 'realesr-general-x4v3': # x4 VGG-style model (S size)
|
197 |
+
model = SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu')
|
198 |
+
netscale = 4
|
199 |
+
file_url = [
|
200 |
+
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth',
|
201 |
+
'https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth'
|
202 |
+
]
|
203 |
+
|
204 |
+
# ---------------------- determine model paths ---------------------- #
|
205 |
+
model_path = os.path.join('weights', args.model_name + '.pth')
|
206 |
+
if not os.path.isfile(model_path):
|
207 |
+
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
208 |
+
for url in file_url:
|
209 |
+
# model_path will be updated
|
210 |
+
model_path = load_file_from_url(
|
211 |
+
url=url, model_dir=os.path.join(ROOT_DIR, 'weights'), progress=True, file_name=None)
|
212 |
+
|
213 |
+
# use dni to control the denoise strength
|
214 |
+
dni_weight = None
|
215 |
+
if args.model_name == 'realesr-general-x4v3' and args.denoise_strength != 1:
|
216 |
+
wdn_model_path = model_path.replace('realesr-general-x4v3', 'realesr-general-wdn-x4v3')
|
217 |
+
model_path = [model_path, wdn_model_path]
|
218 |
+
dni_weight = [args.denoise_strength, 1 - args.denoise_strength]
|
219 |
+
|
220 |
+
# restorer
|
221 |
+
upsampler = RealESRGANer(
|
222 |
+
scale=netscale,
|
223 |
+
model_path=model_path,
|
224 |
+
dni_weight=dni_weight,
|
225 |
+
model=model,
|
226 |
+
tile=args.tile,
|
227 |
+
tile_pad=args.tile_pad,
|
228 |
+
pre_pad=args.pre_pad,
|
229 |
+
half=not args.fp32,
|
230 |
+
device=device,
|
231 |
+
)
|
232 |
+
|
233 |
+
if 'anime' in args.model_name and args.face_enhance:
|
234 |
+
print('face_enhance is not supported in anime models, we turned this option off for you. '
|
235 |
+
'if you insist on turning it on, please manually comment the relevant lines of code.')
|
236 |
+
args.face_enhance = False
|
237 |
+
|
238 |
+
if args.face_enhance: # Use GFPGAN for face enhancement
|
239 |
+
from gfpgan import GFPGANer
|
240 |
+
face_enhancer = GFPGANer(
|
241 |
+
model_path='https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth',
|
242 |
+
upscale=args.outscale,
|
243 |
+
arch='clean',
|
244 |
+
channel_multiplier=2,
|
245 |
+
bg_upsampler=upsampler) # TODO support custom device
|
246 |
+
else:
|
247 |
+
face_enhancer = None
|
248 |
+
|
249 |
+
reader = Reader(args, total_workers, worker_idx)
|
250 |
+
audio = reader.get_audio()
|
251 |
+
height, width = reader.get_resolution()
|
252 |
+
fps = reader.get_fps()
|
253 |
+
writer = Writer(args, audio, height, width, video_save_path, fps)
|
254 |
+
|
255 |
+
pbar = tqdm(total=len(reader), unit='frame', desc='inference')
|
256 |
+
while True:
|
257 |
+
img = reader.get_frame()
|
258 |
+
if img is None:
|
259 |
+
break
|
260 |
+
|
261 |
+
try:
|
262 |
+
if args.face_enhance:
|
263 |
+
_, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
|
264 |
+
else:
|
265 |
+
output, _ = upsampler.enhance(img, outscale=args.outscale)
|
266 |
+
except RuntimeError as error:
|
267 |
+
print('Error', error)
|
268 |
+
print('If you encounter CUDA out of memory, try to set --tile with a smaller number.')
|
269 |
+
else:
|
270 |
+
writer.write_frame(output)
|
271 |
+
|
272 |
+
torch.cuda.synchronize(device)
|
273 |
+
pbar.update(1)
|
274 |
+
|
275 |
+
reader.close()
|
276 |
+
writer.close()
|
277 |
+
|
278 |
+
|
279 |
+
def run(args):
|
280 |
+
args.video_name = osp.splitext(os.path.basename(args.input))[0]
|
281 |
+
video_save_path = osp.join(args.output, f'{args.video_name}_{args.suffix}.mp4')
|
282 |
+
|
283 |
+
if args.extract_frame_first:
|
284 |
+
tmp_frames_folder = osp.join(args.output, f'{args.video_name}_inp_tmp_frames')
|
285 |
+
os.makedirs(tmp_frames_folder, exist_ok=True)
|
286 |
+
os.system(f'ffmpeg -i {args.input} -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 {tmp_frames_folder}/frame%08d.png')
|
287 |
+
args.input = tmp_frames_folder
|
288 |
+
|
289 |
+
num_gpus = torch.cuda.device_count()
|
290 |
+
num_process = num_gpus * args.num_process_per_gpu
|
291 |
+
if num_process == 1:
|
292 |
+
inference_video(args, video_save_path)
|
293 |
+
return
|
294 |
+
|
295 |
+
ctx = torch.multiprocessing.get_context('spawn')
|
296 |
+
pool = ctx.Pool(num_process)
|
297 |
+
os.makedirs(osp.join(args.output, f'{args.video_name}_out_tmp_videos'), exist_ok=True)
|
298 |
+
pbar = tqdm(total=num_process, unit='sub_video', desc='inference')
|
299 |
+
for i in range(num_process):
|
300 |
+
sub_video_save_path = osp.join(args.output, f'{args.video_name}_out_tmp_videos', f'{i:03d}.mp4')
|
301 |
+
pool.apply_async(
|
302 |
+
inference_video,
|
303 |
+
args=(args, sub_video_save_path, torch.device(i % num_gpus), num_process, i),
|
304 |
+
callback=lambda arg: pbar.update(1))
|
305 |
+
pool.close()
|
306 |
+
pool.join()
|
307 |
+
|
308 |
+
# combine sub videos
|
309 |
+
# prepare vidlist.txt
|
310 |
+
with open(f'{args.output}/{args.video_name}_vidlist.txt', 'w') as f:
|
311 |
+
for i in range(num_process):
|
312 |
+
f.write(f'file \'{args.video_name}_out_tmp_videos/{i:03d}.mp4\'\n')
|
313 |
+
|
314 |
+
cmd = [
|
315 |
+
args.ffmpeg_bin, '-f', 'concat', '-safe', '0', '-i', f'{args.output}/{args.video_name}_vidlist.txt', '-c',
|
316 |
+
'copy', f'{video_save_path}'
|
317 |
+
]
|
318 |
+
print(' '.join(cmd))
|
319 |
+
subprocess.call(cmd)
|
320 |
+
shutil.rmtree(osp.join(args.output, f'{args.video_name}_out_tmp_videos'))
|
321 |
+
if osp.exists(osp.join(args.output, f'{args.video_name}_inp_tmp_videos')):
|
322 |
+
shutil.rmtree(osp.join(args.output, f'{args.video_name}_inp_tmp_videos'))
|
323 |
+
os.remove(f'{args.output}/{args.video_name}_vidlist.txt')
|
324 |
+
|
325 |
+
|
326 |
+
def main():
|
327 |
+
"""Inference demo for Real-ESRGAN.
|
328 |
+
It mainly for restoring anime videos.
|
329 |
+
|
330 |
+
"""
|
331 |
+
parser = argparse.ArgumentParser()
|
332 |
+
parser.add_argument('-i', '--input', type=str, default='inputs', help='Input video, image or folder')
|
333 |
+
parser.add_argument(
|
334 |
+
'-n',
|
335 |
+
'--model_name',
|
336 |
+
type=str,
|
337 |
+
default='realesr-animevideov3',
|
338 |
+
help=('Model names: realesr-animevideov3 | RealESRGAN_x4plus_anime_6B | RealESRGAN_x4plus | RealESRNet_x4plus |'
|
339 |
+
' RealESRGAN_x2plus | realesr-general-x4v3'
|
340 |
+
'Default:realesr-animevideov3'))
|
341 |
+
parser.add_argument('-o', '--output', type=str, default='results', help='Output folder')
|
342 |
+
parser.add_argument(
|
343 |
+
'-dn',
|
344 |
+
'--denoise_strength',
|
345 |
+
type=float,
|
346 |
+
default=0.5,
|
347 |
+
help=('Denoise strength. 0 for weak denoise (keep noise), 1 for strong denoise ability. '
|
348 |
+
'Only used for the realesr-general-x4v3 model'))
|
349 |
+
parser.add_argument('-s', '--outscale', type=float, default=4, help='The final upsampling scale of the image')
|
350 |
+
parser.add_argument('--suffix', type=str, default='out', help='Suffix of the restored video')
|
351 |
+
parser.add_argument('-t', '--tile', type=int, default=0, help='Tile size, 0 for no tile during testing')
|
352 |
+
parser.add_argument('--tile_pad', type=int, default=10, help='Tile padding')
|
353 |
+
parser.add_argument('--pre_pad', type=int, default=0, help='Pre padding size at each border')
|
354 |
+
parser.add_argument('--face_enhance', action='store_true', help='Use GFPGAN to enhance face')
|
355 |
+
parser.add_argument(
|
356 |
+
'--fp32', action='store_true', help='Use fp32 precision during inference. Default: fp16 (half precision).')
|
357 |
+
parser.add_argument('--fps', type=float, default=None, help='FPS of the output video')
|
358 |
+
parser.add_argument('--ffmpeg_bin', type=str, default='ffmpeg', help='The path to ffmpeg')
|
359 |
+
parser.add_argument('--extract_frame_first', action='store_true')
|
360 |
+
parser.add_argument('--num_process_per_gpu', type=int, default=1)
|
361 |
+
|
362 |
+
parser.add_argument(
|
363 |
+
'--alpha_upsampler',
|
364 |
+
type=str,
|
365 |
+
default='realesrgan',
|
366 |
+
help='The upsampler for the alpha channels. Options: realesrgan | bicubic')
|
367 |
+
parser.add_argument(
|
368 |
+
'--ext',
|
369 |
+
type=str,
|
370 |
+
default='auto',
|
371 |
+
help='Image extension. Options: auto | jpg | png, auto means using the same extension as inputs')
|
372 |
+
args = parser.parse_args()
|
373 |
+
|
374 |
+
args.input = args.input.rstrip('/').rstrip('\\')
|
375 |
+
os.makedirs(args.output, exist_ok=True)
|
376 |
+
|
377 |
+
if mimetypes.guess_type(args.input)[0] is not None and mimetypes.guess_type(args.input)[0].startswith('video'):
|
378 |
+
is_video = True
|
379 |
+
else:
|
380 |
+
is_video = False
|
381 |
+
|
382 |
+
if is_video and args.input.endswith('.flv'):
|
383 |
+
mp4_path = args.input.replace('.flv', '.mp4')
|
384 |
+
os.system(f'ffmpeg -i {args.input} -codec copy {mp4_path}')
|
385 |
+
args.input = mp4_path
|
386 |
+
|
387 |
+
if args.extract_frame_first and not is_video:
|
388 |
+
args.extract_frame_first = False
|
389 |
+
|
390 |
+
run(args)
|
391 |
+
|
392 |
+
if args.extract_frame_first:
|
393 |
+
tmp_frames_folder = osp.join(args.output, f'{args.video_name}_inp_tmp_frames')
|
394 |
+
shutil.rmtree(tmp_frames_folder)
|
395 |
+
|
396 |
+
|
397 |
+
if __name__ == '__main__':
|
398 |
+
main()
|
RealESRGANv030/inputs/00003.png
ADDED
RealESRGANv030/inputs/00017_gray.png
ADDED
RealESRGANv030/inputs/0014.jpg
ADDED
RealESRGANv030/inputs/0030.jpg
ADDED
RealESRGANv030/inputs/ADE_val_00000114.jpg
ADDED
RealESRGANv030/inputs/OST_009.png
ADDED
RealESRGANv030/inputs/children-alpha.png
ADDED
RealESRGANv030/inputs/tree_alpha_16bit.png
ADDED
RealESRGANv030/inputs/video/onepiece_demo.mp4
ADDED
Binary file (593 kB). View file
|
|