Skip to content

Commit

Permalink
修改模型放大倍数识别方式并添加扩展模型的相关说明
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
TransparentLC committed Mar 14, 2023
1 parent 2bb85f6 commit aa5479e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
16 changes: 15 additions & 1 deletion README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Quick Start:
* The artifacts in GitHub Actions are built based on the latest commits. They don't contain Real-ESRGAN-ncnn-vulkan's executable file and models either.
* Use Python 3.10 or above if you want to run Real-ESRGAN GUI from source. Don't forget to install the dependcies by `pip install -r requirements.txt` and extract Real-ESRGAN-ncnn-vulkan to the repository before running `python main.py`.
* It may be possible to run Real-ESRGAN GUI in other Linux distributions, but I have not tested it.
* You can also download more [additional models](#addition-models) and place the `bin` and `param` files in the `models` directory.

</details>

Expand All @@ -59,6 +60,11 @@ sh Build-macOS-arm64.sh

> ⚠️ Since I don't have any device running macOS, I may not be able to handle macOS-related issues.
### Related projects

* Use Real-ESRGAN on Android: [tumuyan/RealSR-NCNN-Android](https://github.com/tumuyan/RealSR-NCNN-Android)
* Upscale video with Real-ESRGAN and Vapoursynth: [HolyWu/vs-realesrgan](https://github.com/HolyWu/vs-realesrgan)

## Features

In addition to the features supported by Real-ESRGAN-ncnn-vulkan, Real-ESRGAN GUI also supports these additional features:
Expand Down Expand Up @@ -114,7 +120,7 @@ I recommend `realesrgan-x4plus` for real-life photos and `realesrgan-x4plus-anim

For different upscale ratio versions of the same model, it is recommended to choose the version that is equal to or greater than the ratio at which you want to enlarge the image. For example, if a model has x2 and x4 version and you want to upscale an image by 3x, you should choose the x4 version.

Models with `animevideo` in the filename are designed for anime videos. These models are small and have a faster processing speed (about 1.5-3x compare to `realesrgan-x4plus-anime`). However, I recommend [VapourSynth](https://www.vapoursynth.com/) and its [Real-ESRGAN plugin](https://github.com/HolyWu/vs-realesrgan) if you want to upscale an video. Real-ESRGAN GUI will not consider adding video processing related features.
Models with `animevideo` in the filename are designed for anime videos. These models are small and have a faster processing speed (about 1.5-3x compare to `realesrgan-x4plus-anime`). However, Real-ESRGAN GUI will not consider adding video processing related features.

### The usage of tile size

Expand Down Expand Up @@ -159,6 +165,14 @@ If this option is not turned on, lossless compression is used when the output is

The configuration will be saved automatically when exiting the program.

### Additional models

You can download additional models from [Upscale Wiki](https://upscale.wiki/wiki/Model_Database) and use them in Real-ESRGAN GUI. These model may produce better (or worse) results than the official model for some images.

These model uses PyTorch's `pth` format, but Real-ESRGAN GUI (Real-ESRGAN-ncnn-vulkan) needs NCNN's `bin` and `param` format. You can follow this [guide](https://note.youdao.com/ynoteshare/?id=2b001cd4175ab46d2ce11ecb5a6d84ff) (written by RealSR-NCNN-Android's author in Chinese) to make a conversion with [cupscale](https://github.com/n00mkrad/cupscale)'s `pth2ncnn` utility. The model's filename must contain its upscale factor like `x4` or `4x`.

You can download some converted additional models from [here](https://github.com/TransparentLC/realesrgan-gui/releases/tag/additional-models).

## Open-source libraries used

* [Pillow](https://github.com/python-pillow/Pillow)
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@

<summary>其它的运行方式和说明</summary>

* Release 中的 `realesrgan-gui-windows.7z``realesrgan-gui-ubuntu.tar.xz` 不包含 Real-ESRGAN-ncnn-vulkan 的主程序和模型,请自行在[这里](https://github.com/xinntao/Real-ESRGAN/releases)下载后解压到 GUI 的主程序所在的目录。
* Actions 中上传的是根据最新提交的代码打包的版本(相当于 Nightly),同样不包含 Real-ESRGAN-ncnn-vulkan 的主程序和模型
* Release 中的 `realesrgan-gui-windows.7z``realesrgan-gui-ubuntu.tar.xz` 不包含 Real-ESRGAN-ncnn-vulkan 的主程序和官方模型,请自行在[这里](https://github.com/xinntao/Real-ESRGAN/releases)下载后解压到 GUI 的主程序所在的目录。
* Actions 中上传的是根据最新提交的代码打包的版本(相当于 Nightly),同样不包含 Real-ESRGAN-ncnn-vulkan 的主程序和官方模型
* 如果需要从源代码运行,请使用 Python 3.10 或以上版本,执行 `pip install -r requirements.txt` 安装依赖,将 Real-ESRGAN-ncnn-vulkan 解压到项目目录,然后执行 `main.py`
* 在其它的 Linux 发行版中可能也可以运行本项目,不过我没有进行测试。
* 你也可以自己下载更多的[扩展模型](#扩展模型),将模型的文件名相同的 `bin``param` 文件放在 `models` 目录,主程序在启动后会自动识别到这些模型。

</details>

Expand All @@ -59,6 +60,11 @@ sh Build-macOS-arm64.sh

> ⚠️ 由于我没有运行 macOS 的设备,因此可能无法处理和 macOS 相关的使用问题。
### 相关项目

* 在 Android 上使用 Real-ESRGAN:[tumuyan/RealSR-NCNN-Android](https://github.com/tumuyan/RealSR-NCNN-Android)
* 通过 Vapoursynth 对视频使用 Real-ESRGAN:[HolyWu/vs-realesrgan](https://github.com/HolyWu/vs-realesrgan)

## 功能介绍

在原版支持的功能的基础上,增加了以下功能:
Expand Down Expand Up @@ -113,7 +119,7 @@ sh Build-macOS-arm64.sh

对于同一系列模型的不同倍率版本,建议选择等于或大于想要将图片放大的倍率的版本。例如在想要将图片放大到 3x 但是只有 x2 和 x4 模型的情况下,应该选择 x4 的模型。

带有 `animevideo` 的几个模型是针对二次元视频使用的,特点是模型文件较小以及处理速度较快(我自己的测试是 `realesrgan-x4plus-anime` 的 1.5x 到 3x 不等)。不过这个 GUI 并不会考虑加入视频处理功能,如果需要放大视频的话可以考虑使用 [VapourSynth 的相关插件](https://github.com/HolyWu/vs-realesrgan),并且确定你的显卡不会跑到冒烟……
带有 `animevideo` 的几个模型是针对二次元视频使用的,特点是模型文件较小以及处理速度较快(我自己的测试是 `realesrgan-x4plus-anime` 的 1.5x 到 3x 不等)。不过这个 GUI 并不会考虑加入视频处理功能

### 拆分大小的作用

Expand Down Expand Up @@ -158,6 +164,14 @@ GIF 只支持最多 256 种 RGB 颜色的调色板并设定其中一种颜色为

如果因为配置文件的问题导致程序不能运行的话,可以先尝试将配置文件删除。

### 扩展模型

除了 Real-ESRGAN 的官方模型,你也可以从 [Upscale Wiki](https://upscale.wiki/wiki/Model_Database) 下载更多的扩展模型,对于某些图片可能会有比官方模型更好的效果,请根据实际情况自由尝试。

这些模型使用的是 PyTorch 的 `pth` 格式,而不是 NCNN 的 `bin``param` 格式,因此需要进行转换,具体的操作方法可以参见 RealSR-NCNN-Android 的原作者提供的[教程](https://note.youdao.com/ynoteshare/?id=2b001cd4175ab46d2ce11ecb5a6d84ff)。为了识别模型的放大倍数,请确保模型的文件名中有类似 `x4``4x` 的字样。

可以在[这里](https://github.com/TransparentLC/realesrgan-gui/releases/tag/additional-models)下载一些转换好的模型。

## 借物表

* [Pillow](https://github.com/python-pillow/Pillow)
Expand Down
12 changes: 7 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import configparser
import notifypy
import os
import re
import sys
import time
import threading
Expand Down Expand Up @@ -41,10 +42,8 @@ def __init__(self, parent: tk.Tk):
self.modelFactors: dict[str, int] = {}
for m in self.models:
self.modelFactors[m] = 4
for i in range(2, 5):
if f'x{i}' in m:
self.modelFactors[m] = i
break
if s := re.search(r'(\d+)x|x(\d+)', m):
self.modelFactors[m] = int(s.group(1) or s.group(2))

self.downsample = (
('Lanczos', Image.Resampling.LANCZOS),
Expand Down Expand Up @@ -143,7 +142,10 @@ def setupWidgets(self):
self.frameModel.grid(row=0, column=1, sticky=tk.NSEW)
ttk.Label(self.frameModel, text=i18n.getTranslatedString('UsedModel')).pack(padx=10, pady=5, fill=tk.X)
self.comboModel = ttk.Combobox(self.frameModel, state='readonly', values=self.models, textvariable=self.varstrModel)
self.comboModel.current(self.models.index(self.varstrModel.get()))
if self.varstrModel.get() in self.models:
self.comboModel.current(self.models.index(self.varstrModel.get()))
else:
self.varstrModel.set(self.models[0])
self.comboModel.pack(padx=10, pady=5, fill=tk.X)
self.comboModel.bind('<<ComboboxSelected>>', lambda e: e.widget.select_clear())
self.frameResize = ttk.Frame(self.frameBasicConfigBottom)
Expand Down

0 comments on commit aa5479e

Please sign in to comment.