nihui / realsr-ncnn-vulkan

RealSR super resolution implemented with ncnn library
MIT License
1.11k stars 113 forks source link

Use ESRGAN (old Architecture) weights #12

Open Klanly opened 4 years ago

Klanly commented 4 years ago

I made a google colab script to convert ESRGAN (old Architecture) pth files to .param and .bin:

import shutil
import os
!7z x '/content/drive/My Drive/TFMLz/ESRGAN_oldarch/ncnnconv.7z' -o/content
!apt-get install -y libomp-dev
!pip install onnx-simplifier
!chmod u+x onnx2ncnn
!chmod u+x ncnnoptimize
adst='/content/esr.pth'

'''
asrc='/content/drive/My Drive/TFMLz/ESRGAN_oldarch/models/FatalimiX.pth'
shutil.copyfile(asrc,adst)
'''
'''
!7z e '/content/drive/My Drive/TFMLz/ESRGAN_oldarch/models/falcoon300.7z' -o/content
ren xxx.pth esr.pth
...

!python to_onnx.py
!python -m onnxsim '/content/esr.onnx' '/content/esr_simp.onnx'
!/content/onnx2ncnn /content/esr_simp.onnx /content/x4_o1.param /content/x4_o1.bin
!/content/ncnnoptimize /content/x4_o1.param /content/x4_o1.bin /content/x4_fp32.param /content/x4_fp32.bin 0
!/content/ncnnoptimize /content/x4_o1.param /content/x4_o1.bin /content/x4_fp16.param /content/x4_fp16.bin 1

ncnnconv.zip, rename it to .7z (to_onnx.py .etc from github.com/achie27/super-resolution )

Replace 'models-DF2K/x4.bin' with the generated x4_fp32.bin or x4_fp16.bin then that's it.

There are about +-3 value bias per channel, comparing to it's original pytorch results.

Felixkruemel commented 4 years ago

Could you just share the bin files instead of pointing to the Colab script? Also those file paths for the drive should be not working for other users I think

Klanly commented 4 years ago

Could you just share the bin files instead of pointing to the Colab script? Also those file paths for the drive should be not working for other users I think

This the converted weights& prog I currently use.. https://github.com/Klanly/lunusbuild/releases/download/gcgghq/SR.zip

1x ( cmd: realsr.exe -m c -s 1 ) is "Fatality DeBlur"; 4x ( cmd: realsr.exe -m c ) is "FatalimiX".

Weights form: https://upscale.wiki/wiki/Model_Database

default input = tibr_o.jpg default output = output.png

Felixkruemel commented 4 years ago

@Klanly How can you specify a different model? Something like realrsr.exe -m "DF2K_JPEG" (if the folder is named that way) doesn't seem to work And what does -m c do?

Klanly commented 4 years ago

@Klanly How can you specify a different model? Something like realrsr.exe -m "DF2K_JPEG" (if the folder is named that way) doesn't seem to work And what does -m c do?

https://github.com/Klanly/realsr-ncnn-vulkan/blob/master/src/Readme/Readme.md 'a'=models-DF2K_JPEG, 'b'=models-DF2K, 'c'=models-ESRGAN

So, -m a = -m "DF2K_JPEG" -m b = -m "DF2K"