support model config during inference

This commit is contained in:
Xintao
2021-08-31 19:58:40 +08:00
parent 18a9c386a8
commit c1669c4b0a
2 changed files with 14 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import argparse
import cv2
import glob
import os
from basicsr.archs.rrdbnet_arch import RRDBNet
from realesrgan import RealESRGANer
@@ -18,11 +19,12 @@ def main():
parser.add_argument('--netscale', type=int, default=4, help='Upsample scale factor of the network')
parser.add_argument('--outscale', type=float, default=4, help='The final upsampling scale of the image')
parser.add_argument('--suffix', type=str, default='out', help='Suffix of the restored image')
parser.add_argument('--tile', type=int, default=800, help='Tile size, 0 for no tile during testing')
parser.add_argument('--tile', type=int, default=0, help='Tile size, 0 for no tile during testing')
parser.add_argument('--tile_pad', type=int, default=10, help='Tile padding')
parser.add_argument('--pre_pad', type=int, default=0, help='Pre padding size at each border')
parser.add_argument('--face_enhance', action='store_true', help='Use GFPGAN to enhance face')
parser.add_argument('--half', action='store_true', help='Use half precision during inference')
parser.add_argument('--block', type=int, default=23, help='num_block in RRDB')
parser.add_argument(
'--alpha_upsampler',
type=str,
@@ -35,9 +37,17 @@ def main():
help='Image extension. Options: auto | jpg | png, auto means using the same extension as inputs')
args = parser.parse_args()
if 'RealESRGAN_x4plus_anime_6B.pth' in args.model_path:
args.block = 6
elif 'RealESRGAN_x2plus.pth' in args.model_path:
args.netscale = 2
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=args.block, num_grow_ch=32, scale=args.netscale)
upsampler = RealESRGANer(
scale=args.netscale,
model_path=args.model_path,
model=model,
tile=args.tile,
tile_pad=args.tile_pad,
pre_pad=args.pre_pad,