Spaces:
Running
Running
fix queue jam.
Browse filesFiles changed (4)
16 unmodified lines1718192021222316 unmodified linesscale_coords_landmarks,)IS_HIGH_VERSION = tuple(map(int, torch.__version__.split('+')[0].split('.'))) >= (1, 9, 0)def isListempty(inList):16 unmodified lines1718192021222316 unmodified linesscale_coords_landmarks,)IS_HIGH_VERSION = tuple(map(int, torch.__version__.split('+')[0].split('.')[:3])) >= (1, 9, 0)def isListempty(inList):
5 unmodified lines6789101112112 unmodified lines125126127128129130165 unmodified lines2962972982993003015 unmodified linesfrom facelib.detection import init_detection_modelfrom facelib.parsing import init_parsing_modelfrom facelib.utils.misc import img2tensor, imwritedef get_largest_face(det_faces, h, w):112 unmodified linesimg = img[:, :, 0:3]self.input_img = imgif min(self.input_img.shape[:2])<512:f = 512.0/min(self.input_img.shape[:2])165 unmodified linesdef add_restored_face(self, face):self.restored_faces.append(face)5 unmodified lines6789101112112 unmodified lines125126127128129130131132133165 unmodified lines2993003013023033043053065 unmodified linesfrom facelib.detection import init_detection_modelfrom facelib.parsing import init_parsing_modelfrom facelib.utils.misc import img2tensor, imwrite, is_gray, bgr2graydef get_largest_face(det_faces, h, w):112 unmodified linesimg = img[:, :, 0:3]self.input_img = imgself.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 linesdef add_restored_face(self, face):if self.is_gray:face = bgr2gray(face) # convert img into grayscaleself.restored_faces.append(face)
123456132 unmodified lines139140141import cv2import osimport os.path as ospimport torchfrom torch.hub import download_url_to_file, get_dirfrom urllib.parse import urlparse132 unmodified linescontinuereturn _scandir(dir_path, suffix=suffix, recursive=recursive)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 linescontinuereturn _scandir(dir_path, suffix=suffix, recursive=recursive)def is_gray(img, threshold=10):img = Image.fromarray(img)if len(img.getbands()) == 1:return Trueimg1 = 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.0if diff_sum <= threshold:return Trueelse:return Falsedef rgb2gray(img, out_channel=3):r, g, b = img[:,:,0], img[:,:,1], img[:,:,2]gray = 0.2989 * r + 0.5870 * g + 0.1140 * bif out_channel == 3:gray = gray[:,:,np.newaxis].repeat(3, axis=2)return graydef bgr2gray(img, out_channel=3):b, g, r = img[:,:,0], img[:,:,1], img[:,:,2]gray = 0.2989 * r + 0.5870 * g + 0.1140 * bif out_channel == 3:gray = gray[:,:,np.newaxis].repeat(3, axis=2)return gray
15 unmodified lines16171819202186 unmodified lines10810911011111211311 unmodified lines12512612712812913097 unmodified lines22822923023123223323414 unmodified lines24925025115 unmodified linesfrom basicsr.utils import imwrite, img2tensor, tensor2imgfrom basicsr.utils.download_util import load_file_from_urlfrom facelib.utils.face_restoration_helper import FaceRestoreHelperfrom basicsr.archs.rrdbnet_arch import RRDBNetfrom basicsr.utils.realesrgan_utils import RealESRGANer86 unmodified linesdraw_box = Falsedetection_model = "retinaface_resnet50"face_helper = FaceRestoreHelper(upscale,face_size=512,11 unmodified linesif has_aligned:# the input faces are already cropped and alignedimg = cv2.resize(img, (512, 512), interpolation=cv2.INTER_LINEAR)face_helper.cropped_faces = [img]else:face_helper.read_image(img)97 unmodified lines"""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()15 unmodified lines1617181920212286 unmodified lines10911011111211311411511 unmodified lines12712812913013113213313413597 unmodified lines23323423523623723823914 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 RealESRGANer86 unmodified linesdraw_box = Falsedetection_model = "retinaface_resnet50"upscale = int(upscale) # covert type to intface_helper = FaceRestoreHelper(upscale,face_size=512,11 unmodified linesif has_aligned:# the input faces are already cropped and alignedimg = 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"""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