forked from Hukasx0/character-factory
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
30 changed files
with
1,650 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
models/ | ||
app/models/ | ||
# folder | ||
.vscode | ||
|
||
# file type | ||
*.svg | ||
*.pyc | ||
*.pth | ||
*.t7 | ||
*.caffemodel | ||
*.mat | ||
*.npy | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Frequently Asked Questions | ||
|
||
### 1. How to reproduce your results in the [PIRM18-SR Challenge](https://www.pirm2018.org/PIRM-SR.html) (with low perceptual index)? | ||
|
||
First, the released ESRGAN model in the GitHub (`RRDB_ESRGAN_x4.pth`) is **different** from the model we submitted in the competition. | ||
We found that the lower perceptual index does not always guarantee a better visual quality. | ||
The aims for the competition and our ESRGAN work will be a bit different. | ||
We think the aim for the competition is the lower perceptual index and the aim for our ESRGAN work is the better visual quality. | ||
> More analyses can be found in Sec 4.1 and Sec 5 in [PIRM18-SR Chanllenge report](https://arxiv.org/pdf/1809.07517.pdf). | ||
> It points out that PI (perceptual index) is well correlated with the human-opinion-scores on a coarse scale, but it is not always well-correlated with these scores on a finer scale. This highlights the urgent need for better perceptual quality metrics.) | ||
Therefore, in the PIRM18-SR Challenge competition, we used several tricks for the best perceptual index (see Section 4.5 in the [paper](https://arxiv.org/abs/1809.00219)). | ||
|
||
Here, we provid the models and codes used in the competition, which is able to produce the results on the `PIRM test dataset` (we use MATLAB 2016b/2017a): | ||
|
||
| Group | Perceptual index | RMSE | | ||
| ------------- |:-------------:| -----:| | ||
| SuperSR | 1.978 | 15.30 | | ||
|
||
> 1. Download the model and codes from [GoogleDrive](https://drive.google.com/file/d/1l0gBRMqhVLpL_-7R7aN-q-3hnv5ADFSM/view?usp=sharing) | ||
> 2. Put LR input images in the `LR` folder | ||
> 3. Run `python test.py` | ||
> 4. Run `main_reverse_filter.m` in MATLAB as a post processing | ||
> 5. The results on my computer are: Perceptual index: **1.9777** and RMSE: **15.304** | ||
|
||
### 2. How do you get the perceptual index in your ESRGAN paper? | ||
In our paper, we provide the perceptual index in two places. | ||
|
||
1). In the Fig. 2, the perceptual index on PIRM self validation dataset is obtained with the **model we submitted in the competition**. | ||
Since the pupose of this figure is to show the perception-distortion plane. And we also use the post-precessing here same as in the competition. | ||
|
||
2). In the Fig.7, the perceptual indexs are provided as references and they are tested on the data generated by the released ESRGAN model `RRDB_ESRGAN_x4.pth` in the GiuHub. | ||
Also, there is **no** post-processing when testing the ESRGAN model for better visual quality. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import functools | ||
import torch | ||
import torch.nn as nn | ||
import torch.nn.functional as F | ||
|
||
|
||
def make_layer(block, n_layers): | ||
layers = [] | ||
for _ in range(n_layers): | ||
layers.append(block()) | ||
return nn.Sequential(*layers) | ||
|
||
|
||
class ResidualDenseBlock_5C(nn.Module): | ||
def __init__(self, nf=64, gc=32, bias=True): | ||
super(ResidualDenseBlock_5C, self).__init__() | ||
# gc: growth channel, i.e. intermediate channels | ||
self.conv1 = nn.Conv2d(nf, gc, 3, 1, 1, bias=bias) | ||
self.conv2 = nn.Conv2d(nf + gc, gc, 3, 1, 1, bias=bias) | ||
self.conv3 = nn.Conv2d(nf + 2 * gc, gc, 3, 1, 1, bias=bias) | ||
self.conv4 = nn.Conv2d(nf + 3 * gc, gc, 3, 1, 1, bias=bias) | ||
self.conv5 = nn.Conv2d(nf + 4 * gc, nf, 3, 1, 1, bias=bias) | ||
self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True) | ||
|
||
# initialization | ||
# mutil.initialize_weights([self.conv1, self.conv2, self.conv3, self.conv4, self.conv5], 0.1) | ||
|
||
def forward(self, x): | ||
x1 = self.lrelu(self.conv1(x)) | ||
x2 = self.lrelu(self.conv2(torch.cat((x, x1), 1))) | ||
x3 = self.lrelu(self.conv3(torch.cat((x, x1, x2), 1))) | ||
x4 = self.lrelu(self.conv4(torch.cat((x, x1, x2, x3), 1))) | ||
x5 = self.conv5(torch.cat((x, x1, x2, x3, x4), 1)) | ||
return x5 * 0.2 + x | ||
|
||
|
||
class RRDB(nn.Module): | ||
'''Residual in Residual Dense Block''' | ||
|
||
def __init__(self, nf, gc=32): | ||
super(RRDB, self).__init__() | ||
self.RDB1 = ResidualDenseBlock_5C(nf, gc) | ||
self.RDB2 = ResidualDenseBlock_5C(nf, gc) | ||
self.RDB3 = ResidualDenseBlock_5C(nf, gc) | ||
|
||
def forward(self, x): | ||
out = self.RDB1(x) | ||
out = self.RDB2(out) | ||
out = self.RDB3(out) | ||
return out * 0.2 + x | ||
|
||
|
||
class RRDBNet(nn.Module): | ||
def __init__(self, in_nc, out_nc, nf, nb, gc=32): | ||
super(RRDBNet, self).__init__() | ||
RRDB_block_f = functools.partial(RRDB, nf=nf, gc=gc) | ||
|
||
self.conv_first = nn.Conv2d(in_nc, nf, 3, 1, 1, bias=True) | ||
self.RRDB_trunk = make_layer(RRDB_block_f, nb) | ||
self.trunk_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) | ||
#### upsampling | ||
self.upconv1 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) | ||
self.upconv2 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) | ||
self.HRconv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) | ||
self.conv_last = nn.Conv2d(nf, out_nc, 3, 1, 1, bias=True) | ||
|
||
self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True) | ||
|
||
def forward(self, x): | ||
fea = self.conv_first(x) | ||
trunk = self.trunk_conv(self.RRDB_trunk(fea)) | ||
fea = fea + trunk | ||
|
||
fea = self.lrelu(self.upconv1(F.interpolate(fea, scale_factor=2, mode='nearest'))) | ||
fea = self.lrelu(self.upconv2(F.interpolate(fea, scale_factor=2, mode='nearest'))) | ||
out = self.conv_last(self.lrelu(self.HRconv(fea))) | ||
|
||
return out |
Oops, something went wrong.