mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-07 05:22:06 -07:00
fixes
This commit is contained in:
parent
7174dc835a
commit
c1612c5553
4 changed files with 22 additions and 47 deletions
3
main.py
3
main.py
|
@ -6,6 +6,7 @@ import multiprocessing
|
||||||
from utils import Path_utils
|
from utils import Path_utils
|
||||||
from utils import os_utils
|
from utils import os_utils
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from interact import interact as io
|
||||||
|
|
||||||
if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 6):
|
if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 6):
|
||||||
raise Exception("This program requires at least Python 3.6")
|
raise Exception("This program requires at least Python 3.6")
|
||||||
|
@ -134,10 +135,12 @@ if __name__ == "__main__":
|
||||||
Util.restore_faceset_metadata_folder (input_path=arguments.input_dir)
|
Util.restore_faceset_metadata_folder (input_path=arguments.input_dir)
|
||||||
|
|
||||||
if arguments.pack_faceset:
|
if arguments.pack_faceset:
|
||||||
|
io.log_info ("Performing faceset packing...\r\n")
|
||||||
from samplelib import PackedFaceset
|
from samplelib import PackedFaceset
|
||||||
PackedFaceset.pack( Path(arguments.input_dir) )
|
PackedFaceset.pack( Path(arguments.input_dir) )
|
||||||
|
|
||||||
if arguments.unpack_faceset:
|
if arguments.unpack_faceset:
|
||||||
|
io.log_info ("Performing faceset unpacking...\r\n")
|
||||||
from samplelib import PackedFaceset
|
from samplelib import PackedFaceset
|
||||||
PackedFaceset.unpack( Path(arguments.input_dir) )
|
PackedFaceset.unpack( Path(arguments.input_dir) )
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,6 @@ class PackedFaceset():
|
||||||
io.log_info(f"{samples_dat_path} : file already exists !")
|
io.log_info(f"{samples_dat_path} : file already exists !")
|
||||||
io.input_bool("Press enter to continue and overwrite.", False)
|
io.input_bool("Press enter to continue and overwrite.", False)
|
||||||
|
|
||||||
of = open(samples_dat_path, "wb")
|
|
||||||
|
|
||||||
as_person_faceset = False
|
as_person_faceset = False
|
||||||
dir_names = Path_utils.get_all_dir_names(samples_path)
|
dir_names = Path_utils.get_all_dir_names(samples_path)
|
||||||
if len(dir_names) != 0:
|
if len(dir_names) != 0:
|
||||||
|
@ -36,12 +34,11 @@ class PackedFaceset():
|
||||||
else:
|
else:
|
||||||
image_paths = Path_utils.get_image_paths(samples_path)
|
image_paths = Path_utils.get_image_paths(samples_path)
|
||||||
|
|
||||||
|
|
||||||
samples = samplelib.SampleHost.load_face_samples(image_paths)
|
samples = samplelib.SampleHost.load_face_samples(image_paths)
|
||||||
samples_len = len(samples)
|
samples_len = len(samples)
|
||||||
|
|
||||||
samples_configs = []
|
samples_configs = []
|
||||||
for sample in samples:
|
for sample in io.progress_bar_generator (samples, "Processing"):
|
||||||
sample_filepath = Path(sample.filename)
|
sample_filepath = Path(sample.filename)
|
||||||
sample.filename = sample_filepath.name
|
sample.filename = sample_filepath.name
|
||||||
|
|
||||||
|
@ -50,10 +47,14 @@ class PackedFaceset():
|
||||||
samples_configs.append ( sample.get_config() )
|
samples_configs.append ( sample.get_config() )
|
||||||
samples_bytes = pickle.dumps(samples_configs, 4)
|
samples_bytes = pickle.dumps(samples_configs, 4)
|
||||||
|
|
||||||
|
of = open(samples_dat_path, "wb")
|
||||||
of.write ( struct.pack ("Q", PackedFaceset.VERSION ) )
|
of.write ( struct.pack ("Q", PackedFaceset.VERSION ) )
|
||||||
of.write ( struct.pack ("Q", len(samples_bytes) ) )
|
of.write ( struct.pack ("Q", len(samples_bytes) ) )
|
||||||
of.write ( samples_bytes )
|
of.write ( samples_bytes )
|
||||||
|
|
||||||
|
del samples_bytes #just free mem
|
||||||
|
del samples_configs
|
||||||
|
|
||||||
sample_data_table_offset = of.tell()
|
sample_data_table_offset = of.tell()
|
||||||
of.write ( bytes( 8*(samples_len+1) ) ) #sample data offset table
|
of.write ( bytes( 8*(samples_len+1) ) ) #sample data offset table
|
||||||
|
|
||||||
|
@ -67,15 +68,13 @@ class PackedFaceset():
|
||||||
else:
|
else:
|
||||||
sample_path = samples_path / sample.filename
|
sample_path = samples_path / sample.filename
|
||||||
|
|
||||||
|
|
||||||
with open(sample_path, "rb") as f:
|
with open(sample_path, "rb") as f:
|
||||||
b = f.read()
|
b = f.read()
|
||||||
|
|
||||||
offsets.append ( of.tell() - data_start_offset )
|
offsets.append ( of.tell() - data_start_offset )
|
||||||
of.write(b)
|
of.write(b)
|
||||||
except:
|
except:
|
||||||
import code
|
|
||||||
code.interact(local=dict(globals(), **locals()))
|
|
||||||
|
|
||||||
raise Exception(f"error while processing sample {sample_path}")
|
raise Exception(f"error while processing sample {sample_path}")
|
||||||
|
|
||||||
offsets.append ( of.tell() )
|
offsets.append ( of.tell() )
|
||||||
|
@ -86,11 +85,11 @@ class PackedFaceset():
|
||||||
of.seek(0,2)
|
of.seek(0,2)
|
||||||
of.close()
|
of.close()
|
||||||
|
|
||||||
for filename in io.progress_bar_generator(image_paths,"Deleting"):
|
for filename in io.progress_bar_generator(image_paths, "Deleting files"):
|
||||||
Path(filename).unlink()
|
Path(filename).unlink()
|
||||||
|
|
||||||
if as_person_faceset:
|
if as_person_faceset:
|
||||||
for dir_name in dir_names:
|
for dir_name in io.progress_bar_generator(dir_names, "Deleting dirs"):
|
||||||
dir_path = samples_path / dir_name
|
dir_path = samples_path / dir_name
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(dir_path)
|
shutil.rmtree(dir_path)
|
||||||
|
|
|
@ -92,8 +92,7 @@ class SampleHost:
|
||||||
ie_polys,
|
ie_polys,
|
||||||
eyebrows_expand_mod,
|
eyebrows_expand_mod,
|
||||||
source_filename,
|
source_filename,
|
||||||
|
) in result:
|
||||||
) in io.progress_bar_generator(result, "Processing"):
|
|
||||||
sample_list.append( Sample(filename=filename,
|
sample_list.append( Sample(filename=filename,
|
||||||
sample_type=SampleType.FACE,
|
sample_type=SampleType.FACE,
|
||||||
face_type=FaceType.fromString (face_type),
|
face_type=FaceType.fromString (face_type),
|
||||||
|
@ -105,31 +104,6 @@ class SampleHost:
|
||||||
))
|
))
|
||||||
return sample_list
|
return sample_list
|
||||||
|
|
||||||
"""
|
|
||||||
sample_list = []
|
|
||||||
|
|
||||||
for filename in io.progress_bar_generator(image_paths, "Loading"):
|
|
||||||
filename_path = Path(filename)
|
|
||||||
try:
|
|
||||||
dflimg = DFLIMG.load (filename_path)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sample_list.append( Sample(filename=filename,
|
|
||||||
sample_type=SampleType.FACE,
|
|
||||||
face_type=FaceType.fromString (dflimg.get_face_type()),
|
|
||||||
shape=dflimg.get_shape(),
|
|
||||||
landmarks=dflimg.get_landmarks(),
|
|
||||||
ie_polys=dflimg.get_ie_polys(),
|
|
||||||
eyebrows_expand_mod=dflimg.get_eyebrows_expand_mod(),
|
|
||||||
source_filename=dflimg.get_source_filename(),
|
|
||||||
))
|
|
||||||
except:
|
|
||||||
io.log_err ("Unable to load %s , error: %s" % (filename, traceback.format_exc() ) )
|
|
||||||
|
|
||||||
return sample_list
|
|
||||||
"""
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def upgradeToFaceTemporalSortedSamples( samples ):
|
def upgradeToFaceTemporalSortedSamples( samples ):
|
||||||
new_s = [ (s, s.source_filename) for s in samples]
|
new_s = [ (s, s.source_filename) for s in samples]
|
||||||
|
|
|
@ -4,7 +4,6 @@ import time
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue