From 5d91470e3ddb4da7d6d6fb44d355593dc37a6a5b Mon Sep 17 00:00:00 2001 From: Brigham Lysenko Date: Sun, 11 Aug 2019 15:32:41 -0600 Subject: [PATCH 1/5] Added conditional type extraction --- mainscripts/Extractor.py | 42 ++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/mainscripts/Extractor.py b/mainscripts/Extractor.py index 8dc005e..f46613e 100644 --- a/mainscripts/Extractor.py +++ b/mainscripts/Extractor.py @@ -242,23 +242,35 @@ class ExtractSubprocessor(Subprocessor): if self.debug_dir is not None: LandmarksProcessor.draw_rect_landmarks (debug_image, rect, image_landmarks, self.image_size, self.face_type, transparent_mask=True) - if src_dflimg is not None and filename_path.suffix == '.jpg': - #if extracting from dflimg and jpg copy it in order not to lose quality - output_file = str(self.final_output_path / filename_path.name) + if filename_path.suffix == '.jpg': + print(filename_path.suffix + 'is a jpeg') + # if extracting from dflimg and jpg copy it in order not to lose quality + output_file = '{}_{}{}'.format(str(self.final_output_path / filename_path.stem), + str(face_idx), '.jpg') if str(filename_path) != str(output_file): - shutil.copy ( str(filename_path), str(output_file) ) + shutil.copy(str(filename_path), str(output_file)) + cv2_imwrite(output_file, face_image, [int(cv2.IMWRITE_JPEG_QUALITY), 85]) + DFLJPG.embed_data(output_file, face_type=FaceType.toString(self.face_type), + landmarks=face_image_landmarks.tolist(), + source_filename=filename_path.name, + source_rect=rect, + source_landmarks=image_landmarks.tolist(), + image_to_face_mat=image_to_face_mat, + pitch_yaw_roll=data.pitch_yaw_roll + ) else: - output_file = '{}_{}{}'.format(str(self.final_output_path / filename_path.stem), str(face_idx), '.png') - cv2_imwrite(output_file, face_image, [int(cv2.IMWRITE_PNG_COMPRESSION), 0] ) - - DFLPNG.embed_data(output_file, face_type=FaceType.toString(self.face_type), - landmarks=face_image_landmarks.tolist(), - source_filename=filename_path.name, - source_rect=rect, - source_landmarks=image_landmarks.tolist(), - image_to_face_mat=image_to_face_mat, - pitch_yaw_roll=data.pitch_yaw_roll - ) + print(filename_path.suffix + 'is a png') + output_file = '{}_{}{}'.format(str(self.final_output_path / filename_path.stem), + str(face_idx), '.png') + cv2_imwrite(output_file, face_image, [int(cv2.IMWRITE_PNG_COMPRESSION), 0]) + DFLPNG.embed_data(output_file, face_type=FaceType.toString(self.face_type), + landmarks=face_image_landmarks.tolist(), + source_filename=filename_path.name, + source_rect=rect, + source_landmarks=image_landmarks.tolist(), + image_to_face_mat=image_to_face_mat, + pitch_yaw_roll=data.pitch_yaw_roll + ) data.final_output_files.append (output_file) face_idx += 1 From e32c7a963fc9b742608f1264b25cbdb163ffd865 Mon Sep 17 00:00:00 2001 From: Brigham Lysenko Date: Sun, 11 Aug 2019 15:35:57 -0600 Subject: [PATCH 2/5] fixed typo --- mainscripts/Extractor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mainscripts/Extractor.py b/mainscripts/Extractor.py index f46613e..da666a2 100644 --- a/mainscripts/Extractor.py +++ b/mainscripts/Extractor.py @@ -243,7 +243,7 @@ class ExtractSubprocessor(Subprocessor): LandmarksProcessor.draw_rect_landmarks (debug_image, rect, image_landmarks, self.image_size, self.face_type, transparent_mask=True) if filename_path.suffix == '.jpg': - print(filename_path.suffix + 'is a jpeg') + # if extracting from dflimg and jpg copy it in order not to lose quality output_file = '{}_{}{}'.format(str(self.final_output_path / filename_path.stem), str(face_idx), '.jpg') @@ -259,7 +259,7 @@ class ExtractSubprocessor(Subprocessor): pitch_yaw_roll=data.pitch_yaw_roll ) else: - print(filename_path.suffix + 'is a png') + output_file = '{}_{}{}'.format(str(self.final_output_path / filename_path.stem), str(face_idx), '.png') cv2_imwrite(output_file, face_image, [int(cv2.IMWRITE_PNG_COMPRESSION), 0]) From 75e50cbc5ba23cf23a4fb2826b078a08d7211535 Mon Sep 17 00:00:00 2001 From: Brigham Lysenko Date: Mon, 12 Aug 2019 15:52:23 -0600 Subject: [PATCH 3/5] fixed png loading --- mainscripts/Extractor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mainscripts/Extractor.py b/mainscripts/Extractor.py index da666a2..13e79b0 100644 --- a/mainscripts/Extractor.py +++ b/mainscripts/Extractor.py @@ -135,7 +135,7 @@ class ExtractSubprocessor(Subprocessor): if filename_path.suffix == '.png': src_dflimg = DFLPNG.load ( str(filename_path) ) if filename_path.suffix == '.jpg': - src_dflimg = DFLPNG.load ( str(filename_path) ) + src_dflimg = DFLJPG.load ( str(filename_path) ) if 'rects' in self.type: if min(w,h) < 128: @@ -249,7 +249,7 @@ class ExtractSubprocessor(Subprocessor): str(face_idx), '.jpg') if str(filename_path) != str(output_file): shutil.copy(str(filename_path), str(output_file)) - cv2_imwrite(output_file, face_image, [int(cv2.IMWRITE_JPEG_QUALITY), 85]) + cv2_imwrite(output_file, face_image, [int(cv2.IMWRITE_JPEG_QUALITY), 95]) DFLJPG.embed_data(output_file, face_type=FaceType.toString(self.face_type), landmarks=face_image_landmarks.tolist(), source_filename=filename_path.name, @@ -262,7 +262,7 @@ class ExtractSubprocessor(Subprocessor): output_file = '{}_{}{}'.format(str(self.final_output_path / filename_path.stem), str(face_idx), '.png') - cv2_imwrite(output_file, face_image, [int(cv2.IMWRITE_PNG_COMPRESSION), 0]) + cv2_imwrite(output_file, face_image, [int(cv2.IMWRITE_PNG_COMPRESSION), 3]) DFLPNG.embed_data(output_file, face_type=FaceType.toString(self.face_type), landmarks=face_image_landmarks.tolist(), source_filename=filename_path.name, From 1fa0a0c7390767c7a36df8aec10a4800e2965196 Mon Sep 17 00:00:00 2001 From: Brigham Lysenko Date: Mon, 12 Aug 2019 16:21:05 -0600 Subject: [PATCH 4/5] Removed flip restrictions --- models/ModelBase.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/models/ModelBase.py b/models/ModelBase.py index 25757b3..ef7836e 100644 --- a/models/ModelBase.py +++ b/models/ModelBase.py @@ -129,10 +129,7 @@ class ModelBase(object): self.options['sort_by_yaw'] = self.options.get('sort_by_yaw', False) if ask_random_flip: - if (self.iter == 0): self.options['random_flip'] = io.input_bool("Flip faces randomly? (y/n ?:help skip:y) : ", True, help_message="Predicted face will look more naturally without this option, but src faceset should cover all face directions as dst faceset.") - else: - self.options['random_flip'] = self.options.get('random_flip', True) if ask_src_scale_mod: if (self.iter == 0): From 7c205f0166849e2b461ed4501dbce23c223466e5 Mon Sep 17 00:00:00 2001 From: Brigham Lysenko Date: Mon, 12 Aug 2019 16:24:32 -0600 Subject: [PATCH 5/5] Gave prompt patience --- models/ModelBase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/ModelBase.py b/models/ModelBase.py index ef7836e..412b9eb 100644 --- a/models/ModelBase.py +++ b/models/ModelBase.py @@ -128,7 +128,7 @@ class ModelBase(object): else: self.options['sort_by_yaw'] = self.options.get('sort_by_yaw', False) - if ask_random_flip: + if ask_override: self.options['random_flip'] = io.input_bool("Flip faces randomly? (y/n ?:help skip:y) : ", True, help_message="Predicted face will look more naturally without this option, but src faceset should cover all face directions as dst faceset.") if ask_src_scale_mod: