mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-08-21 14:03:19 -07:00
global refactoring and fixes,
removed support of extracted(aligned) PNG faces. Use old builds to convert from PNG to JPG. fanseg model file in facelib/ is renamed
This commit is contained in:
parent
921b464d5b
commit
61472cdaf7
82 changed files with 3838 additions and 3812 deletions
32
core/joblib/MPClassFuncOnDemand.py
Normal file
32
core/joblib/MPClassFuncOnDemand.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import multiprocessing
|
||||
from core.interact import interact as io
|
||||
|
||||
class MPClassFuncOnDemand():
|
||||
def __init__(self, class_handle, class_func_name, **class_kwargs):
|
||||
self.class_handle = class_handle
|
||||
self.class_func_name = class_func_name
|
||||
self.class_kwargs = class_kwargs
|
||||
|
||||
self.class_func = None
|
||||
|
||||
self.s2c = multiprocessing.Queue()
|
||||
self.c2s = multiprocessing.Queue()
|
||||
self.lock = multiprocessing.Lock()
|
||||
|
||||
io.add_process_messages_callback(self.io_callback)
|
||||
|
||||
def io_callback(self):
|
||||
while not self.c2s.empty():
|
||||
func_args, func_kwargs = self.c2s.get()
|
||||
if self.class_func is None:
|
||||
self.class_func = getattr( self.class_handle(**self.class_kwargs), self.class_func_name)
|
||||
self.s2c.put ( self.class_func (*func_args, **func_kwargs) )
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
with self.lock:
|
||||
self.c2s.put ( (args, kwargs) )
|
||||
return self.s2c.get()
|
||||
|
||||
def __getstate__(self):
|
||||
return {'s2c':self.s2c, 'c2s':self.c2s, 'lock':self.lock}
|
||||
|
25
core/joblib/MPFunc.py
Normal file
25
core/joblib/MPFunc.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
import multiprocessing
|
||||
from core.interact import interact as io
|
||||
|
||||
class MPFunc():
|
||||
def __init__(self, func):
|
||||
self.func = func
|
||||
|
||||
self.s2c = multiprocessing.Queue()
|
||||
self.c2s = multiprocessing.Queue()
|
||||
self.lock = multiprocessing.Lock()
|
||||
|
||||
io.add_process_messages_callback(self.io_callback)
|
||||
|
||||
def io_callback(self):
|
||||
while not self.c2s.empty():
|
||||
func_args, func_kwargs = self.c2s.get()
|
||||
self.s2c.put ( self.func (*func_args, **func_kwargs) )
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
with self.lock:
|
||||
self.c2s.put ( (args, kwargs) )
|
||||
return self.s2c.get()
|
||||
|
||||
def __getstate__(self):
|
||||
return {'s2c':self.s2c, 'c2s':self.c2s, 'lock':self.lock}
|
|
@ -1,49 +0,0 @@
|
|||
import time
|
||||
import multiprocessing
|
||||
|
||||
class SubprocessFunctionCaller(object):
|
||||
class CliFunction(object):
|
||||
def __init__(self, s2c, c2s, lock):
|
||||
self.s2c = s2c
|
||||
self.c2s = c2s
|
||||
self.lock = lock
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
self.lock.acquire()
|
||||
self.c2s.put ( {'args':args, 'kwargs':kwargs} )
|
||||
while True:
|
||||
if not self.s2c.empty():
|
||||
obj = self.s2c.get()
|
||||
self.lock.release()
|
||||
return obj
|
||||
time.sleep(0.005)
|
||||
|
||||
class HostProcessor(object):
|
||||
def __init__(self, s2c, c2s, func):
|
||||
self.s2c = s2c
|
||||
self.c2s = c2s
|
||||
self.func = func
|
||||
|
||||
def process_messages(self):
|
||||
while not self.c2s.empty():
|
||||
obj = self.c2s.get()
|
||||
result = self.func ( *obj['args'], **obj['kwargs'] )
|
||||
self.s2c.put (result)
|
||||
|
||||
def __getstate__(self):
|
||||
#disable pickling this class
|
||||
return dict()
|
||||
|
||||
def __setstate__(self, d):
|
||||
self.__dict__.update(d)
|
||||
|
||||
@staticmethod
|
||||
def make_pair(func):
|
||||
s2c = multiprocessing.Queue()
|
||||
c2s = multiprocessing.Queue()
|
||||
lock = multiprocessing.Lock()
|
||||
|
||||
host_processor = SubprocessFunctionCaller.HostProcessor (s2c, c2s, func)
|
||||
cli_func = SubprocessFunctionCaller.CliFunction (s2c, c2s, lock)
|
||||
|
||||
return host_processor, cli_func
|
|
@ -1,4 +1,5 @@
|
|||
from .SubprocessorBase import Subprocessor
|
||||
from .SubprocessFunctionCaller import SubprocessFunctionCaller
|
||||
from .ThisThreadGenerator import ThisThreadGenerator
|
||||
from .SubprocessGenerator import SubprocessGenerator
|
||||
from .SubprocessGenerator import SubprocessGenerator
|
||||
from .MPFunc import MPFunc
|
||||
from .MPClassFuncOnDemand import MPClassFuncOnDemand
|
Loading…
Add table
Add a link
Reference in a new issue