mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-07 13:32:09 -07:00
fix
This commit is contained in:
parent
21b25038ac
commit
ea33541177
2 changed files with 92 additions and 100 deletions
|
@ -1,5 +1,6 @@
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import operator
|
import operator
|
||||||
|
import pickle
|
||||||
import traceback
|
import traceback
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -62,22 +63,18 @@ class SampleHost:
|
||||||
if result is None:
|
if result is None:
|
||||||
result = SampleHost.load_face_samples( Path_utils.get_image_paths(samples_path) )
|
result = SampleHost.load_face_samples( Path_utils.get_image_paths(samples_path) )
|
||||||
|
|
||||||
samples[sample_type] = mp_utils.ListHost()
|
|
||||||
|
|
||||||
if sample_type == SampleType.FACE_TEMPORAL_SORTED:
|
if sample_type == SampleType.FACE_TEMPORAL_SORTED:
|
||||||
result = SampleHost.upgradeToFaceTemporalSortedSamples(result)
|
result = SampleHost.upgradeToFaceTemporalSortedSamples(result)
|
||||||
|
|
||||||
|
result_dumped = pickle.dumps(result)
|
||||||
|
del result
|
||||||
|
result = pickle.loads(result_dumped)
|
||||||
|
samples[sample_type] = mp_utils.ListHost(result)
|
||||||
|
|
||||||
list_host = samples[sample_type]
|
list_host = samples[sample_type]
|
||||||
|
|
||||||
clis = [ list_host.create_cli() for _ in range(number_of_clis) ]
|
clis = [ list_host.create_cli() for _ in range(number_of_clis) ]
|
||||||
|
|
||||||
if result is not None:
|
|
||||||
while True:
|
|
||||||
if len(result) == 0:
|
|
||||||
break
|
|
||||||
items = result[0:10000]
|
|
||||||
del result[0:10000]
|
|
||||||
clis[0].extend(items)
|
|
||||||
return clis
|
return clis
|
||||||
|
|
||||||
return samples[sample_type]
|
return samples[sample_type]
|
||||||
|
|
|
@ -1,25 +1,22 @@
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import traceback
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
class Index2DHost():
|
class Index2DHost():
|
||||||
"""
|
"""
|
||||||
Provides random shuffled 2D indexes for multiprocesses
|
Provides random shuffled 2D indexes for multiprocesses
|
||||||
"""
|
"""
|
||||||
def __init__(self, indexes2D, max_number_of_clis=128):
|
def __init__(self, indexes2D):
|
||||||
self.sq = multiprocessing.Queue()
|
self.sq = multiprocessing.Queue()
|
||||||
self.cqs = [ multiprocessing.Queue() for _ in range(max_number_of_clis) ]
|
self.cqs = []
|
||||||
self.n_clis = 0
|
self.clis = []
|
||||||
self.max_number_of_clis = max_number_of_clis
|
self.thread = threading.Thread(target=self.host_thread, args=(indexes2D,) )
|
||||||
|
self.thread.daemon = True
|
||||||
|
self.thread.start()
|
||||||
|
|
||||||
self.p = multiprocessing.Process(target=self.host_proc, args=(indexes2D, self.sq, self.cqs) )
|
def host_thread(self, indexes2D):
|
||||||
self.p.daemon = True
|
|
||||||
self.p.start()
|
|
||||||
|
|
||||||
def host_proc(self, indexes2D, sq, cqs):
|
|
||||||
indexes_counts_len = len(indexes2D)
|
indexes_counts_len = len(indexes2D)
|
||||||
|
|
||||||
idxs = [*range(indexes_counts_len)]
|
idxs = [*range(indexes_counts_len)]
|
||||||
|
@ -30,6 +27,8 @@ class Index2DHost():
|
||||||
idxs_2D[i] = indexes2D[i]
|
idxs_2D[i] = indexes2D[i]
|
||||||
shuffle_idxs_2D[i] = []
|
shuffle_idxs_2D[i] = []
|
||||||
|
|
||||||
|
sq = self.sq
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
while not sq.empty():
|
while not sq.empty():
|
||||||
obj = sq.get()
|
obj = sq.get()
|
||||||
|
@ -44,7 +43,7 @@ class Index2DHost():
|
||||||
shuffle_idxs = idxs.copy()
|
shuffle_idxs = idxs.copy()
|
||||||
np.random.shuffle(shuffle_idxs)
|
np.random.shuffle(shuffle_idxs)
|
||||||
result.append(shuffle_idxs.pop())
|
result.append(shuffle_idxs.pop())
|
||||||
cqs[cq_id].put (result)
|
self.cqs[cq_id].put (result)
|
||||||
elif cmd == 1: #get_2D
|
elif cmd == 1: #get_2D
|
||||||
targ_idxs,count = obj[2], obj[3]
|
targ_idxs,count = obj[2], obj[3]
|
||||||
result = []
|
result = []
|
||||||
|
@ -58,7 +57,7 @@ class Index2DHost():
|
||||||
np.random.shuffle(ar)
|
np.random.shuffle(ar)
|
||||||
sub_idxs.append(ar.pop())
|
sub_idxs.append(ar.pop())
|
||||||
result.append (sub_idxs)
|
result.append (sub_idxs)
|
||||||
cqs[cq_id].put (result)
|
self.cqs[cq_id].put (result)
|
||||||
|
|
||||||
time.sleep(0.005)
|
time.sleep(0.005)
|
||||||
|
|
||||||
|
@ -100,19 +99,18 @@ class IndexHost():
|
||||||
"""
|
"""
|
||||||
Provides random shuffled indexes for multiprocesses
|
Provides random shuffled indexes for multiprocesses
|
||||||
"""
|
"""
|
||||||
def __init__(self, indexes_count, max_number_of_clis=128):
|
def __init__(self, indexes_count):
|
||||||
self.sq = multiprocessing.Queue()
|
self.sq = multiprocessing.Queue()
|
||||||
self.cqs = [ multiprocessing.Queue() for _ in range(max_number_of_clis) ]
|
self.cqs = []
|
||||||
self.n_clis = 0
|
self.clis = []
|
||||||
self.max_number_of_clis = max_number_of_clis
|
self.thread = threading.Thread(target=self.host_thread, args=(indexes_count,) )
|
||||||
|
self.thread.daemon = True
|
||||||
|
self.thread.start()
|
||||||
|
|
||||||
self.p = multiprocessing.Process(target=self.host_proc, args=(indexes_count, self.sq, self.cqs) )
|
def host_thread(self, indexes_count):
|
||||||
self.p.daemon = True
|
|
||||||
self.p.start()
|
|
||||||
|
|
||||||
def host_proc(self, indexes_count, sq, cqs):
|
|
||||||
idxs = [*range(indexes_count)]
|
idxs = [*range(indexes_count)]
|
||||||
shuffle_idxs = []
|
shuffle_idxs = []
|
||||||
|
sq = self.sq
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
while not sq.empty():
|
while not sq.empty():
|
||||||
|
@ -125,18 +123,15 @@ class IndexHost():
|
||||||
shuffle_idxs = idxs.copy()
|
shuffle_idxs = idxs.copy()
|
||||||
np.random.shuffle(shuffle_idxs)
|
np.random.shuffle(shuffle_idxs)
|
||||||
result.append(shuffle_idxs.pop())
|
result.append(shuffle_idxs.pop())
|
||||||
cqs[cq_id].put (result)
|
self.cqs[cq_id].put (result)
|
||||||
|
|
||||||
time.sleep(0.005)
|
time.sleep(0.005)
|
||||||
|
|
||||||
def create_cli(self):
|
def create_cli(self):
|
||||||
if self.n_clis == self.max_number_of_clis:
|
cq = multiprocessing.Queue()
|
||||||
raise Exception("")
|
self.cqs.append ( cq )
|
||||||
|
cq_id = len(self.cqs)-1
|
||||||
cq_id = self.n_clis
|
return IndexHost.Cli(self.sq, cq, cq_id)
|
||||||
self.n_clis += 1
|
|
||||||
|
|
||||||
return IndexHost.Cli(self.sq, self.cqs[cq_id], cq_id)
|
|
||||||
|
|
||||||
# disable pickling
|
# disable pickling
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
|
@ -159,50 +154,50 @@ class IndexHost():
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
|
|
||||||
class ListHost():
|
class ListHost():
|
||||||
def __init__(self, list_=None, max_number_of_clis=128):
|
def __init__(self, list_):
|
||||||
self.sq = multiprocessing.Queue()
|
self.sq = multiprocessing.Queue()
|
||||||
self.cqs = [ multiprocessing.Queue() for _ in range(max_number_of_clis) ]
|
self.cqs = []
|
||||||
self.n_clis = 0
|
self.clis = []
|
||||||
self.max_number_of_clis = max_number_of_clis
|
self.m_list = list_
|
||||||
|
self.thread = threading.Thread(target=self.host_thread)
|
||||||
self.p = multiprocessing.Process(target=self.host_proc, args=(self.sq, self.cqs) )
|
self.thread.daemon = True
|
||||||
self.p.daemon = True
|
self.thread.start()
|
||||||
self.p.start()
|
|
||||||
|
|
||||||
def host_proc(self, sq, cqs):
|
|
||||||
m_list = list()
|
|
||||||
|
|
||||||
|
def host_thread(self):
|
||||||
|
sq = self.sq
|
||||||
while True:
|
while True:
|
||||||
while not sq.empty():
|
while not sq.empty():
|
||||||
obj = sq.get()
|
obj = sq.get()
|
||||||
cq_id, cmd = obj[0], obj[1]
|
cq_id, cmd = obj[0], obj[1]
|
||||||
|
|
||||||
if cmd == 0:
|
if cmd == 0:
|
||||||
cqs[cq_id].put ( len(m_list) )
|
self.cqs[cq_id].put ( len(self.m_list) )
|
||||||
elif cmd == 1:
|
elif cmd == 1:
|
||||||
idx = obj[2]
|
idx = obj[2]
|
||||||
item = m_list[idx ]
|
item = self.m_list[idx ]
|
||||||
cqs[cq_id].put ( item )
|
self.cqs[cq_id].put ( item )
|
||||||
elif cmd == 2:
|
elif cmd == 2:
|
||||||
result = []
|
result = []
|
||||||
for item in obj[2]:
|
for item in obj[2]:
|
||||||
result.append ( m_list[item] )
|
result.append ( self.m_list[item] )
|
||||||
cqs[cq_id].put ( result )
|
self.cqs[cq_id].put ( result )
|
||||||
elif cmd == 3:
|
elif cmd == 3:
|
||||||
m_list.insert(obj[2], obj[3])
|
self.m_list.insert(obj[2], obj[3])
|
||||||
elif cmd == 4:
|
elif cmd == 4:
|
||||||
m_list.append(obj[2])
|
self.m_list.append(obj[2])
|
||||||
elif cmd == 5:
|
elif cmd == 5:
|
||||||
m_list.extend(obj[2])
|
self.m_list.extend(obj[2])
|
||||||
|
|
||||||
time.sleep(0.005)
|
time.sleep(0.005)
|
||||||
|
|
||||||
def create_cli(self):
|
def create_cli(self):
|
||||||
if self.n_clis == self.max_number_of_clis:
|
cq = multiprocessing.Queue()
|
||||||
raise Exception("")
|
self.cqs.append ( cq )
|
||||||
|
cq_id = len(self.cqs)-1
|
||||||
|
return ListHost.Cli(self.sq, cq, cq_id)
|
||||||
|
|
||||||
cq_id = self.n_clis
|
def get_list(self):
|
||||||
self.n_clis += 1
|
return self.list_
|
||||||
|
|
||||||
return ListHost.Cli(self.sq, self.cqs[cq_id], cq_id)
|
|
||||||
|
|
||||||
# disable pickling
|
# disable pickling
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue