Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
automatic1111
GitHub Repository: automatic1111/stable-diffusion-webui
Path: blob/master/test/test_face_restorers.py
3055 views
1
import os
2
from test.conftest import test_files_path, test_outputs_path
3
4
import numpy as np
5
import pytest
6
from PIL import Image
7
8
9
@pytest.mark.usefixtures("initialize")
10
@pytest.mark.parametrize("restorer_name", ["gfpgan", "codeformer"])
11
def test_face_restorers(restorer_name):
12
from modules import shared
13
14
if restorer_name == "gfpgan":
15
from modules import gfpgan_model
16
gfpgan_model.setup_model(shared.cmd_opts.gfpgan_models_path)
17
restorer = gfpgan_model.gfpgan_fix_faces
18
elif restorer_name == "codeformer":
19
from modules import codeformer_model
20
codeformer_model.setup_model(shared.cmd_opts.codeformer_models_path)
21
restorer = codeformer_model.codeformer.restore
22
else:
23
raise NotImplementedError("...")
24
img = Image.open(os.path.join(test_files_path, "two-faces.jpg"))
25
np_img = np.array(img, dtype=np.uint8)
26
fixed_image = restorer(np_img)
27
assert fixed_image.shape == np_img.shape
28
assert not np.allclose(fixed_image, np_img) # should have visibly changed
29
Image.fromarray(fixed_image).save(os.path.join(test_outputs_path, f"{restorer_name}.png"))
30
31