feature: better upscaling
- use face enhancement in a smarter way that doesn't blur high-res images - use a different upscale model for composition images **Upscaling** RealESRGAN is great but it blurs parts of images it doesn't understand 4xUltrasharp is a finetune of RealESRGan that isn't as good but doesn't have this blurry patch problem. This makes it more suitable to use as part of the composition/upscale process. We still use realesrgan for any last-step upscales since it does look better. had to write a state dict translator to use the ultrasharp model **Face Enhancement** We no longer enhance faces that are larger than 512 pixels. They should already have enough details and the face enhancer doesn't produce faces at high enough resolution to look good at that size.pull/427/head
parent
6ebd12abb1
commit
32b5175e0e
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
Binary file not shown.
After Width: | Height: | Size: 826 KiB |
@ -0,0 +1,21 @@
|
||||
import pytest
|
||||
from lightning_fabric import seed_everything
|
||||
from PIL import Image
|
||||
|
||||
from imaginairy.enhancers.face_restoration_codeformer import enhance_faces
|
||||
from imaginairy.utils import get_device
|
||||
from tests import TESTS_FOLDER
|
||||
from tests.utils import assert_image_similar_to_expectation
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
get_device() == "cpu", reason="TypeError: Got unsupported ScalarType BFloat16"
|
||||
)
|
||||
def test_fix_faces(filename_base_for_orig_outputs, filename_base_for_outputs):
|
||||
distorted_img = Image.open(f"{TESTS_FOLDER}/data/distorted_face.png")
|
||||
seed_everything(1)
|
||||
img = enhance_faces(distorted_img)
|
||||
|
||||
distorted_img.save(f"{filename_base_for_orig_outputs}__orig.jpg")
|
||||
img_path = f"{filename_base_for_outputs}.png"
|
||||
assert_image_similar_to_expectation(img, img_path=img_path, threshold=2800)
|
@ -0,0 +1,13 @@
|
||||
from PIL import Image
|
||||
|
||||
from imaginairy.enhancers.upscale_realesrgan import upscale_image
|
||||
from tests import TESTS_FOLDER
|
||||
from tests.utils import assert_image_similar_to_expectation
|
||||
|
||||
|
||||
def test_upscale_textured_image(filename_base_for_outputs):
|
||||
img = Image.open(f"{TESTS_FOLDER}/data/sand_upscale_difficult.jpg")
|
||||
upscaled_image = upscale_image(img, ultrasharp=True)
|
||||
assert_image_similar_to_expectation(
|
||||
upscaled_image, f"{filename_base_for_outputs}.jpg", threshold=25000
|
||||
)
|
Loading…
Reference in New Issue