DeepFaceLab/core/pathex.py
Colombo 76ca79216e Upgraded to TF version 1.13.2
Removed the wait at first launch for most graphics cards.

Increased speed of training by 10-20%, but you have to retrain all models from scratch.

SAEHD:

added option 'use float16'
	Experimental option. Reduces the model size by half.
	Increases the speed of training.
	Decreases the accuracy of the model.
	The model may collapse or not train.
	Model may not learn the mask in large resolutions.

true_face_training option is replaced by
"True face power". 0.0000 .. 1.0
Experimental option. Discriminates the result face to be more like the src face. Higher value - stronger discrimination.
Comparison - https://i.imgur.com/czScS9q.png
2020-01-25 21:58:19 +04:00

106 lines
3 KiB
Python

from pathlib import Path
from os import scandir
image_extensions = [".jpg", ".jpeg", ".png", ".tif", ".tiff"]
def write_bytes_safe(p, bytes_data):
"""
writes to .tmp first and then rename to target filename
"""
p_tmp = p.parent / (p.name + '.tmp')
p_tmp.write_bytes(bytes_data)
if p.exists():
p.unlink()
p_tmp.rename (p)
def scantree(path):
"""Recursively yield DirEntry objects for given directory."""
for entry in scandir(path):
if entry.is_dir(follow_symlinks=False):
yield from scantree(entry.path) # see below for Python 2.x
else:
yield entry
def get_image_paths(dir_path, image_extensions=image_extensions, subdirs=False):
dir_path = Path (dir_path)
result = []
if dir_path.exists():
if subdirs:
gen = scantree(str(dir_path))
else:
gen = scandir(str(dir_path))
for x in list(gen):
if any([x.name.lower().endswith(ext) for ext in image_extensions]):
result.append(x.path)
return sorted(result)
def get_image_unique_filestem_paths(dir_path, verbose_print_func=None):
result = get_image_paths(dir_path)
result_dup = set()
for f in result[:]:
f_stem = Path(f).stem
if f_stem in result_dup:
result.remove(f)
if verbose_print_func is not None:
verbose_print_func ("Duplicate filenames are not allowed, skipping: %s" % Path(f).name )
continue
result_dup.add(f_stem)
return sorted(result)
def get_file_paths(dir_path):
dir_path = Path (dir_path)
if dir_path.exists():
return [ Path(x) for x in sorted([ x.path for x in list(scandir(str(dir_path))) if x.is_file() ]) ]
else:
return []
def get_all_dir_names (dir_path):
dir_path = Path (dir_path)
if dir_path.exists():
return sorted([ x.name for x in list(scandir(str(dir_path))) if x.is_dir() ])
else:
return []
def get_all_dir_names_startswith (dir_path, startswith):
dir_path = Path (dir_path)
startswith = startswith.lower()
result = []
if dir_path.exists():
for x in list(scandir(str(dir_path))):
if x.name.lower().startswith(startswith):
result.append ( x.name[len(startswith):] )
return sorted(result)
def get_first_file_by_stem (dir_path, stem, exts=None):
dir_path = Path (dir_path)
stem = stem.lower()
if dir_path.exists():
for x in sorted(list(scandir(str(dir_path))), key=lambda x: x.name):
if not x.is_file():
continue
xp = Path(x.path)
if xp.stem.lower() == stem and (exts is None or xp.suffix.lower() in exts):
return xp
return None
def move_all_files (src_dir_path, dst_dir_path):
paths = get_file_paths(src_dir_path)
for p in paths:
p = Path(p)
p.rename ( Path(dst_dir_path) / p.name )
def delete_all_files (dir_path):
paths = get_file_paths(dir_path)
for p in paths:
p = Path(p)
p.unlink()