mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-06 13:02:15 -07:00
The load time of training data has been reduced significantly.
This commit is contained in:
parent
554217d026
commit
977d8a2d77
1 changed files with 33 additions and 71 deletions
|
@ -84,7 +84,8 @@ class MPSharedList():
|
||||||
data_size = sum([len(x) for x in obj_pickled_ar])
|
data_size = sum([len(x) for x in obj_pickled_ar])
|
||||||
|
|
||||||
sh_b = multiprocessing.RawArray('B', table_size + data_size)
|
sh_b = multiprocessing.RawArray('B', table_size + data_size)
|
||||||
sh_b[0:8] = struct.pack('<Q', obj_count)
|
#sh_b[0:8] = struct.pack('<Q', obj_count)
|
||||||
|
sh_b_view = memoryview(sh_b).cast('B')
|
||||||
|
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
|
@ -97,51 +98,12 @@ class MPSharedList():
|
||||||
offset += len(obj_pickled_ar[i])
|
offset += len(obj_pickled_ar[i])
|
||||||
offsets.append(offset)
|
offsets.append(offset)
|
||||||
|
|
||||||
sh_b[table_offset:table_offset+table_size] = struct.pack( '<'+'Q'*len(offsets), *offsets )
|
sh_b_view[table_offset:table_offset+table_size] = struct.pack( '<'+'Q'*len(offsets), *offsets )
|
||||||
|
|
||||||
ArrayFillerSubprocessor(sh_b, [ (data_offset+offsets[i], obj_pickled_ar[i] ) for i in range(obj_count) ] ).run()
|
for i, obj_pickled in enumerate(obj_pickled_ar):
|
||||||
|
offset = data_offset+offsets[i]
|
||||||
|
sh_b_view[offset:offset+len(obj_pickled)] = obj_pickled_ar[i]
|
||||||
|
|
||||||
return obj_count, table_offset, data_offset, sh_b
|
return obj_count, table_offset, data_offset, sh_b
|
||||||
return 0, 0, 0, None
|
return 0, 0, 0, None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ArrayFillerSubprocessor(Subprocessor):
|
|
||||||
"""
|
|
||||||
Much faster to fill shared memory via subprocesses rather than direct whole bytes fill.
|
|
||||||
"""
|
|
||||||
#override
|
|
||||||
def __init__(self, sh_b, data_list ):
|
|
||||||
self.sh_b = sh_b
|
|
||||||
self.data_list = data_list
|
|
||||||
super().__init__('ArrayFillerSubprocessor', ArrayFillerSubprocessor.Cli, 60, io_loop_sleep_time=0.001)
|
|
||||||
|
|
||||||
#override
|
|
||||||
def process_info_generator(self):
|
|
||||||
for i in range(min(multiprocessing.cpu_count(), 8)):
|
|
||||||
yield 'CPU%d' % (i), {}, {'sh_b':self.sh_b}
|
|
||||||
|
|
||||||
#override
|
|
||||||
def get_data(self, host_dict):
|
|
||||||
if len(self.data_list) > 0:
|
|
||||||
return self.data_list.pop(-1)
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
#override
|
|
||||||
def on_data_return (self, host_dict, data):
|
|
||||||
self.data_list.insert(0, data)
|
|
||||||
|
|
||||||
#override
|
|
||||||
def on_result (self, host_dict, data, result):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Cli(Subprocessor.Cli):
|
|
||||||
#overridable optional
|
|
||||||
def on_initialize(self, client_dict):
|
|
||||||
self.sh_b = client_dict['sh_b']
|
|
||||||
|
|
||||||
def process_data(self, data):
|
|
||||||
offset, b = data
|
|
||||||
self.sh_b[offset:offset+len(b)]=b
|
|
||||||
return 0
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue