Spaces:
No application file
No application file
culture
commited on
Commit
·
099fd55
1
Parent(s):
389a882
Upload tests/test_utils.py
Browse files- tests/test_utils.py +43 -0
tests/test_utils.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
from facexlib.utils.face_restoration_helper import FaceRestoreHelper
|
| 3 |
+
|
| 4 |
+
from gfpgan.archs.gfpganv1_arch import GFPGANv1
|
| 5 |
+
from gfpgan.archs.gfpganv1_clean_arch import GFPGANv1Clean
|
| 6 |
+
from gfpgan.utils import GFPGANer
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_gfpganer():
|
| 10 |
+
# initialize with the clean model
|
| 11 |
+
restorer = GFPGANer(
|
| 12 |
+
model_path='experiments/pretrained_models/GFPGANCleanv1-NoCE-C2.pth',
|
| 13 |
+
upscale=2,
|
| 14 |
+
arch='clean',
|
| 15 |
+
channel_multiplier=2,
|
| 16 |
+
bg_upsampler=None)
|
| 17 |
+
# test attribute
|
| 18 |
+
assert isinstance(restorer.gfpgan, GFPGANv1Clean)
|
| 19 |
+
assert isinstance(restorer.face_helper, FaceRestoreHelper)
|
| 20 |
+
|
| 21 |
+
# initialize with the original model
|
| 22 |
+
restorer = GFPGANer(
|
| 23 |
+
model_path='experiments/pretrained_models/GFPGANv1.pth',
|
| 24 |
+
upscale=2,
|
| 25 |
+
arch='original',
|
| 26 |
+
channel_multiplier=1,
|
| 27 |
+
bg_upsampler=None)
|
| 28 |
+
# test attribute
|
| 29 |
+
assert isinstance(restorer.gfpgan, GFPGANv1)
|
| 30 |
+
assert isinstance(restorer.face_helper, FaceRestoreHelper)
|
| 31 |
+
|
| 32 |
+
# ------------------ test enhance ---------------- #
|
| 33 |
+
img = cv2.imread('tests/data/gt/00000000.png', cv2.IMREAD_COLOR)
|
| 34 |
+
result = restorer.enhance(img, has_aligned=False, paste_back=True)
|
| 35 |
+
assert result[0][0].shape == (512, 512, 3)
|
| 36 |
+
assert result[1][0].shape == (512, 512, 3)
|
| 37 |
+
assert result[2].shape == (1024, 1024, 3)
|
| 38 |
+
|
| 39 |
+
# with has_aligned=True
|
| 40 |
+
result = restorer.enhance(img, has_aligned=True, paste_back=False)
|
| 41 |
+
assert result[0][0].shape == (512, 512, 3)
|
| 42 |
+
assert result[1][0].shape == (512, 512, 3)
|
| 43 |
+
assert result[2] is None
|