diff --git a/doc/manual_ru.pdf b/doc/manual_ru.pdf index 51438e4..8063098 100644 Binary files a/doc/manual_ru.pdf and b/doc/manual_ru.pdf differ diff --git a/doc/manual_ru_source.docx b/doc/manual_ru_source.docx index b32bafc..82d6273 100644 Binary files a/doc/manual_ru_source.docx and b/doc/manual_ru_source.docx differ diff --git a/main.py b/main.py index 873e32e..5a3d72f 100644 --- a/main.py +++ b/main.py @@ -65,10 +65,14 @@ if __name__ == "__main__": if arguments.add_landmarks_debug_images: Util.add_landmarks_debug_images (input_path=arguments.input_dir) + if arguments.recover_original_aligned_filename: + Util.recover_original_aligned_filename (input_path=arguments.input_dir) + util_parser = subparsers.add_parser( "util", help="Utilities.") util_parser.add_argument('--input-dir', required=True, action=fixPathAction, dest="input_dir", help="Input directory. A directory containing the files you wish to process.") util_parser.add_argument('--convert-png-to-jpg', action="store_true", dest="convert_png_to_jpg", default=False, help="Convert DeepFaceLAB PNG files to JPEG.") util_parser.add_argument('--add-landmarks-debug-images', action="store_true", dest="add_landmarks_debug_images", default=False, help="Add landmarks debug image for aligned faces.") + util_parser.add_argument('--recover-original-aligned-filename', action="store_true", dest="recover_original_aligned_filename", default=False, help="Recover original aligned filename.") util_parser.set_defaults (func=process_util) def process_train(arguments): @@ -204,7 +208,7 @@ if __name__ == "__main__": """ outnull_file = open(os.devnull, 'w') os.dup2 ( outnull_file.fileno(), sys.stderr.fileno() ) - sys.stderr = outnull_file + sys.stderr = outnull_file ''' diff --git a/mainscripts/Util.py b/mainscripts/Util.py index ae9b1e2..18b631c 100644 --- a/mainscripts/Util.py +++ b/mainscripts/Util.py @@ -15,7 +15,7 @@ def convert_png_to_jpg_file (filepath): dflpng = DFLPNG.load (str(filepath) ) if dflpng is None: - print ("%s is not a dfl image file" % (filepath.name) ) + io.log_err ("%s is not a dfl image file" % (filepath.name) ) return dfl_dict = dflpng.getDFLDictData() @@ -36,14 +36,14 @@ def convert_png_to_jpg_file (filepath): def convert_png_to_jpg_folder (input_path): input_path = Path(input_path) - print ("Converting PNG to JPG...\r\n") + io.log_info ("Converting PNG to JPG...\r\n") for filepath in io.progress_bar_generator( Path_utils.get_image_paths(input_path), "Converting"): filepath = Path(filepath) convert_png_to_jpg_file(filepath) def add_landmarks_debug_images(input_path): - print ("Adding landmarks debug images...") + io.log_info ("Adding landmarks debug images...") for filepath in io.progress_bar_generator( Path_utils.get_image_paths(input_path), "Processing"): filepath = Path(filepath) @@ -58,7 +58,7 @@ def add_landmarks_debug_images(input_path): dflimg = None if dflimg is None: - print ("%s is not a dfl image file" % (filepath.name) ) + io.log_err ("%s is not a dfl image file" % (filepath.name) ) continue if img is not None: @@ -68,3 +68,61 @@ def add_landmarks_debug_images(input_path): output_file = '{}{}'.format( str(Path(str(input_path)) / filepath.stem), '_debug.jpg') cv2_imwrite(output_file, img, [int(cv2.IMWRITE_JPEG_QUALITY), 50] ) +def recover_original_aligned_filename(input_path): + io.log_info ("Recovering original aligned filename...") + + files = [] + for filepath in io.progress_bar_generator( Path_utils.get_image_paths(input_path), "Processing"): + filepath = Path(filepath) + + if filepath.suffix == '.png': + dflimg = DFLPNG.load( str(filepath) ) + elif filepath.suffix == '.jpg': + dflimg = DFLJPG.load ( str(filepath) ) + else: + dflimg = None + + if dflimg is None: + io.log_err ("%s is not a dfl image file" % (filepath.name) ) + continue + + files += [ [filepath, None, dflimg.get_source_filename(), False] ] + + files_len = len(files) + for i in io.progress_bar_generator( range(files_len), "Sorting" ): + fp, _, sf, converted = files[i] + + if converted: + continue + + sf_stem = Path(sf).stem + + files[i][1] = fp.parent / ( sf_stem + '_0' + fp.suffix ) + files[i][3] = True + c = 1 + + for j in range(i+1, files_len): + fp_j, _, sf_j, converted_j = files[j] + if converted_j: + continue + + if sf_j == sf: + files[j][1] = fp_j.parent / ( sf_stem + ('_%d' % (c)) + fp_j.suffix ) + files[j][3] = True + c += 1 + + for file in io.progress_bar_generator( files, "Renaming", leave=False ): + fs, _, _, _ = file + dst = fs.parent / ( fs.stem + '_tmp' + fs.suffix ) + try: + fs.rename (dst) + except: + io.log_err ('fail to rename %s' % (fs.name) ) + + for file in io.progress_bar_generator( files, "Renaming" ): + fs, fd, _, _ = file + fs = fs.parent / ( fs.stem + '_tmp' + fs.suffix ) + try: + fs.rename (fd) + except: + io.log_err ('fail to rename %s' % (fs.name) ) \ No newline at end of file diff --git a/nnlib/device.py b/nnlib/device.py index 683c759..0fac79d 100644 --- a/nnlib/device.py +++ b/nnlib/device.py @@ -3,7 +3,9 @@ import json import numpy as np from .pynvml import * -tf_min_req_cap = 37 #min req compute capability for tensorflow-gpu==1.11.0 + + +tf_min_req_cap = int(os.environ.get("force_tf_min_req_cap", 37)) #min req compute capability for tensorflow-gpu==1.11.0 class device: backend = None