o yf@sUddlmZddlZddlZddlZddlmZmZmZm Z m Z m Z e e ZdZdZdaded<Gdd d e jZd d ZdddZdS)) annotationsN)deviceserrorsface_restorationface_restoration_utils modelloadersharedzLhttps://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pthzGFPGANv1.4.pthz'face_restoration.FaceRestoration | Nonegfpgan_face_restorerc@s.eZdZddZddZd ddZd d Zd S) FaceRestorerGFPGANcCsdS)NGFPGANselfr r eC:\Users\Luke\Documents\Stable diffusion\Automatic1111\stable-diffusion-webui\modules\gfpgan_model.pynameszFaceRestorerGFPGAN.namecCstjS)N)r device_gfpganr r r r get_deviceszFaceRestorerGFPGAN.get_devicereturn torch.ModulecCs\tj|jt|jtdgdD]}dtj|vr)tj|| ddj }d|_ |Sq t d)Nz.pth) model_path model_url command_path download_name ext_filterr )deviceexpected_architectureTzNo GFPGAN model found) r load_modelsrrmodel_download_nameospathbasenameload_spandrel_modelrmodelZ different_w ValueError)rrr"r r rload_nets& zFaceRestorerGFPGAN.load_netcsfdd}||S)Ncs jdusJj|dddS)NF)Z return_rgbr)net)cropped_face_tr r r restore_face1sz0FaceRestorerGFPGAN.restore..restore_face)restore_with_helper)rnp_imager'r r rrestore0s  zFaceRestorerGFPGAN.restoreN)rr)__name__ __module__ __qualname__rrr$r*r r r rr s   r cCstrt|Std|S)NzGFPGAN face restorer not set up)r r*loggerwarning)r)r r rgfpgan_fix_faces8s  r0dirnamestrrNonecCsJzt|t|datjtWdSty$tj dddYdSw)N)rzError setting up GFPGANT)exc_info) rpatch_facexlibr r rface_restorersappend Exceptionrreport)r1r r r setup_model?s   r:)r1r2rr3) __future__rloggingrtorchmodulesrrrrrr getLoggerr+r.rrr __annotations__CommonFaceRestorationr r0r:r r r rs   !