8000 support GFPGAN clean arch · coder-wuyan/GFPGAN@7f67e12 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f67e12

Browse files
committed
support GFPGAN clean arch
1 parent cc3c881 commit 7f67e12

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

inference_gfpgan_full.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def restoration(gfpgan,
1919
has_aligned=False,
2020
only_center_face=True,
2121
suffix=None,
22-
paste_back=False):
22+
paste_back=False,
23+
device='cuda'):
2324
# read image
2425
img_name = os.path.basename(img_path)
2526
print(f'Processing {img_name} ...')
@@ -43,7 +44,7 @@ def restoration(gfpgan,
4344
# prepare data
4445
cropped_face_t = img2tensor(cropped_face / 255., bgr2rgb=True, float32=True)
4546
normalize(cropped_face_t, (0.5, 0.5, 0.5), (0.5, 0.5, 0.5), inplace=True)
46-
cropped_face_t = cropped_face_t.unsqueeze(0).to('cuda')
47+
cropped_face_t = cropped_face_t.unsqueeze(0).to(device)
4748

4849
try:
4950
with torch.no_grad():
@@ -77,17 +78,18 @@ def restoration(gfpgan,
7778

7879
if __name__ == '__main__':
7980
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
81+
8082
parser = argparse.ArgumentParser()
8183

82-
parser.add_argument('--upscale_factor', type=int, default=1)
84+
parser.add_argument('--upscale_factor', type=int, default=2)
8385
parser.add_argument('--arch', type=str, default='clean')
8486
parser.add_argument('--channel', type=int, default=2)
85-
parser.add_argument('--model_path', type=str, default='experiments/pretrained_models/GFPGANv1.pth')
87+
parser.add_argument('--model_path', type=str, default='experiments/pretrained_models/GFPGANCleanv1-NoCE-C2.pth')
8688
parser.add_argument('--test_path', type=str, default='inputs/whole_imgs')
8789
parser.add_argument('--suffix', type=str, default=None, help='Suffix of the restored faces')
8890
parser.add_argument('--only_center_face', action='store_true')
8991
parser.add_argument('--aligned', action='store_true')
90-
parser.add_argument('--paste_back', action='store_true')
92+
parser.add_argument('--paste_back', action='store_false')
9193
parser.add_argument('--save_root', type=str, default='results')
9294

9395
args = parser.parse_args()
@@ -123,14 +125,17 @@ def restoration(gfpgan,
123125
narrow=1,
124126
sft_half=True)
125127

126-
gfpgan.to(device)
127-
checkpoint = torch.load(args.model_path, map_location=lambda storage, loc: storage)
128-
gfpgan.load_state_dict(checkpoint['params_ema'])
129-
gfpgan.eval()
128+
gfpgan.load_state_dict(torch.load(args.model_path, map_location=lambda storage, loc: storage)['params_ema'])
129+
gfpgan.to(device).eval()
130130

131131
# initialize face helper
132132
face_helper = FaceRestoreHelper(
133-
args.upscale_factor, face_size=512, crop_ratio=(1, 1), det_model='retinaface_resnet50', save_ext='png')
133+
args.upscale_factor,
134+
face_size=512,
135+
crop_ratio=(1, 1),
136+
det_model='retinaface_resnet50',
137+
save_ext='png',
138+
device=device)
134139

135140
img_list = sorted(glob.glob(os.path.join(args.test_path, '*')))
136141
for img_path in img_list:
@@ -142,6 +147,7 @@ def restoration(gfpgan,
142147
has_aligned=args.aligned,
143148
only_center_face=args.only_center_face,
144149
suffix=args.suffix,
145-
paste_back=args.paste_back)
150+
paste_back=args.paste_back,
151+
device=device)
146152

147153
print(f'Results are in the [{args.save_root}] folder.')

0 commit comments

Comments
 (0)
0