Spaces:
Sleeping
Sleeping
fix queue jam.
Browse filesFiles changed (4)
16 unmodified lines171819202021222316 unmodified lines scale_coords_landmarks,)
IS_HIGH_VERSION = tuple(map(int, torch.__version__.split('+')[0].split('.'))) >= (1, 9, 0)IS_HIGH_VERSION = tuple(map(int, torch.__version__.split('+')[0].split('.')[:3])) >= (1, 9, 0)
def isListempty(inList):5 unmodified lines67899101112112 unmodified lines125126127128129130131132133165 unmodified lines2993003013023033043053065 unmodified lines
from facelib.detection import init_detection_modelfrom facelib.parsing import init_parsing_modelfrom facelib.utils.misc import img2tensor, imwritefrom facelib.utils.misc import img2tensor, imwrite, is_gray, bgr2gray
def get_largest_face(det_faces, h, w):112 unmodified lines img = img[:, :, 0:3]
self.input_img = img self.is_gray = is_gray(img, threshold=5) if self.is_gray: print('Grayscale input: True')
if min(self.input_img.shape[:2])<512: f = 512.0/min(self.input_img.shape[:2])165 unmodified lines
def add_restored_face(self, face): if self.is_gray: face = bgr2gray(face) # convert img into grayscale self.restored_faces.append(face)
12345678132 unmodified lines141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174import cv2import osimport os.path as ospimport numpy as npfrom PIL import Imageimport torchfrom torch.hub import download_url_to_file, get_dirfrom urllib.parse import urlparse132 unmodified lines continue
return _scandir(dir_path, suffix=suffix, recursive=recursive)
def is_gray(img, threshold=10): img = Image.fromarray(img) if len(img.getbands()) == 1: return True img1 = np.asarray(img.getchannel(channel=0), dtype=np.int16) img2 = np.asarray(img.getchannel(channel=1), dtype=np.int16) img3 = np.asarray(img.getchannel(channel=2), dtype=np.int16) diff1 = (img1 - img2).var() diff2 = (img2 - img3).var() diff3 = (img3 - img1).var() diff_sum = (diff1 + diff2 + diff3) / 3.0 if diff_sum <= threshold: return True else: return False
def rgb2gray(img, out_channel=3): r, g, b = img[:,:,0], img[:,:,1], img[:,:,2] gray = 0.2989 * r + 0.5870 * g + 0.1140 * b if out_channel == 3: gray = gray[:,:,np.newaxis].repeat(3, axis=2) return gray
def bgr2gray(img, out_channel=3): b, g, r = img[:,:,0], img[:,:,1], img[:,:,2] gray = 0.2989 * r + 0.5870 * g + 0.1140 * b if out_channel == 3: gray = gray[:,:,np.newaxis].repeat(3, axis=2) return gray15 unmodified lines1617181920212286 unmodified lines10911011111211311411511 unmodified lines12712812913013113213313413597 unmodified lines23323423523123623723823914 unmodified lines25425525625725825915 unmodified linesfrom basicsr.utils import imwrite, img2tensor, tensor2imgfrom basicsr.utils.download_util import load_file_from_urlfrom facelib.utils.face_restoration_helper import FaceRestoreHelperfrom facelib.utils.misc import is_grayfrom basicsr.archs.rrdbnet_arch import RRDBNetfrom basicsr.utils.realesrgan_utils import RealESRGANer
86 unmodified lines draw_box = False detection_model = "retinaface_resnet50"
upscale = int(upscale) # covert type to int face_helper = FaceRestoreHelper( upscale, face_size=512,11 unmodified lines if has_aligned: # the input faces are already cropped and aligned img = cv2.resize(img, (512, 512), interpolation=cv2.INTER_LINEAR) face_helper.is_gray = is_gray(img, threshold=5) if face_helper.is_gray: print('Grayscale input: True') face_helper.cropped_faces = [img] else: face_helper.read_image(img)97 unmodified lines"""
gr.Interface(demo = gr.Interface( inference, [ gr.inputs.Image(type="filepath", label="Input"), gr.inputs.Checkbox(default=True, label="Background_Enhance"),14 unmodified lines ['05.jpg', True, True, 2, 0.1] ] ).launch()
demo.queue(concurrency_count=4)demo.launch()CodeFormer/facelib/detection/yolov5face/face_detector.py+1-1
CodeFormer/facelib/utils/face_restoration_helper.py+6-1
CodeFormer/facelib/utils/misc.py+33
app.py+9-1