From 5e474c346256739e15819fc2acc2f53928dc4118 Mon Sep 17 00:00:00 2001 From: iperov Date: Fri, 22 Feb 2019 11:32:27 +0400 Subject: [PATCH] added sort by one face in images. it trashes all images in which more than 1 face is found --- doc/doc_features.md | 2 +- main.py | 4 ++-- mainscripts/Sorter.py | 22 +++++++++++++++++++--- mainscripts/Util.py | 1 + 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/doc/doc_features.md b/doc/doc_features.md index 347bfb8..06d9133 100644 --- a/doc/doc_features.md +++ b/doc/doc_features.md @@ -1,6 +1,6 @@ ### **Features**: -- works on AMD, NVIDIA, IntelHD graphics and all OpenCL1.2-compatible videocards with at least 512M video memory +- works on AMD, NVIDIA, IntelHD graphics and all OpenCL1.2-compatible videocards with at least 256M video memory. Of course, the more memory available, the better quality you will get. - CPU-only mode [`--cpu-mode`]. 8th gen Intel core CPU able to train H64 model in 2 days. diff --git a/main.py b/main.py index 4735db7..394a0d2 100644 --- a/main.py +++ b/main.py @@ -61,7 +61,7 @@ if __name__ == "__main__": sort_parser = subparsers.add_parser( "sort", help="Sort faces in a directory.") sort_parser.add_argument('--input-dir', required=True, action=fixPathAction, dest="input_dir", help="Input directory. A directory containing the files you wish to process.") - sort_parser.add_argument('--by', required=True, dest="sort_by_method", choices=("blur", "face", "face-dissim", "face-yaw", "face-pitch", "hist", "hist-dissim", "brightness", "hue", "black", "origname", "final", "test"), help="Method of sorting. 'origname' sort by original filename to recover original sequence." ) + sort_parser.add_argument('--by', required=True, dest="sort_by_method", choices=("blur", "face", "face-dissim", "face-yaw", "face-pitch", "hist", "hist-dissim", "brightness", "hue", "black", "origname", "oneface", "final", "test"), help="Method of sorting. 'origname' sort by original filename to recover original sequence." ) sort_parser.set_defaults (func=process_sort) def process_util(arguments): @@ -72,7 +72,7 @@ if __name__ == "__main__": if arguments.add_landmarks_debug_images: Util.add_landmarks_debug_images (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.") diff --git a/mainscripts/Sorter.py b/mainscripts/Sorter.py index 6272c1b..c24fdbd 100644 --- a/mainscripts/Sorter.py +++ b/mainscripts/Sorter.py @@ -671,7 +671,7 @@ def sort_final(input_path): final_img_list += img_list[0:imgs_per_grad] trash_img_list += img_list[imgs_per_grad:] - + return final_img_list, trash_img_list def sort_by_black(input_path): @@ -746,7 +746,22 @@ def sort_by_origname(input_path): print ("Sorting...") img_list = sorted(img_list, key=operator.itemgetter(1)) return img_list + +def sort_by_oneface_in_image(input_path): + print ("Sort by one face in images...") + image_paths = Path_utils.get_image_paths(input_path) + a = [ Path(filepath).stem.split('_') for filepath in image_paths ] + a = np.array ( [ ( int(x[0]), int(x[1]) ) for x in a ] ) + idxs = np.ndarray.flatten ( np.argwhere ( a[:,1] != 0 ) ) + idxs = np.unique ( a[idxs][:,0] ) + idxs = np.ndarray.flatten ( np.argwhere ( np.array([ x[0] in idxs for x in a ]) == True ) ) + + img_list = [ (i,) for j,i in enumerate(image_paths) if j not in idxs ] + trash_img_list = [ (image_paths[x],) for x in idxs ] + + return img_list, trash_img_list + def main (input_path, sort_by_method): input_path = Path(input_path) sort_by_method = sort_by_method.lower() @@ -765,7 +780,8 @@ def main (input_path, sort_by_method): elif sort_by_method == 'brightness': img_list = sort_by_brightness (input_path) elif sort_by_method == 'hue': img_list = sort_by_hue (input_path) elif sort_by_method == 'black': img_list = sort_by_black (input_path) - elif sort_by_method == 'origname': img_list = sort_by_origname (input_path) - elif sort_by_method == 'final': img_list, trash_img_list = sort_final (input_path) + elif sort_by_method == 'origname': img_list = sort_by_origname (input_path) + elif sort_by_method == 'oneface': img_list, trash_img_list = sort_by_oneface_in_image (input_path) + elif sort_by_method == 'final': img_list, trash_img_list = sort_final (input_path) final_process (input_path, img_list, trash_img_list) diff --git a/mainscripts/Util.py b/mainscripts/Util.py index 22e8455..33cc00b 100644 --- a/mainscripts/Util.py +++ b/mainscripts/Util.py @@ -71,3 +71,4 @@ 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] ) +