mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-05 20:42:11 -07:00
dev_misc: code to extract microsoft/FaceSynthetics dataset
This commit is contained in:
parent
f48e852de3
commit
f64b2495d9
1 changed files with 94 additions and 2 deletions
|
@ -13,7 +13,6 @@ from core.joblib import Subprocessor
|
||||||
from core.leras import nn
|
from core.leras import nn
|
||||||
from DFLIMG import *
|
from DFLIMG import *
|
||||||
from facelib import FaceType, LandmarksProcessor
|
from facelib import FaceType, LandmarksProcessor
|
||||||
|
|
||||||
from . import Extractor, Sorter
|
from . import Extractor, Sorter
|
||||||
from .Extractor import ExtractSubprocessor
|
from .Extractor import ExtractSubprocessor
|
||||||
|
|
||||||
|
@ -359,7 +358,7 @@ def extract_umd_csv(input_file_csv,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def dev_test(input_dir):
|
def dev_test1(input_dir):
|
||||||
# LaPa dataset
|
# LaPa dataset
|
||||||
|
|
||||||
image_size = 1024
|
image_size = 1024
|
||||||
|
@ -500,3 +499,96 @@ def dev_segmented_trash(input_dir):
|
||||||
except:
|
except:
|
||||||
io.log_info ('fail to trashing %s' % (src.name) )
|
io.log_info ('fail to trashing %s' % (src.name) )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def dev_test(input_dir):
|
||||||
|
"""
|
||||||
|
extract FaceSynthetics dataset https://github.com/microsoft/FaceSynthetics
|
||||||
|
|
||||||
|
BACKGROUND = 0
|
||||||
|
SKIN = 1
|
||||||
|
NOSE = 2
|
||||||
|
RIGHT_EYE = 3
|
||||||
|
LEFT_EYE = 4
|
||||||
|
RIGHT_BROW = 5
|
||||||
|
LEFT_BROW = 6
|
||||||
|
RIGHT_EAR = 7
|
||||||
|
LEFT_EAR = 8
|
||||||
|
MOUTH_INTERIOR = 9
|
||||||
|
TOP_LIP = 10
|
||||||
|
BOTTOM_LIP = 11
|
||||||
|
NECK = 12
|
||||||
|
HAIR = 13
|
||||||
|
BEARD = 14
|
||||||
|
CLOTHING = 15
|
||||||
|
GLASSES = 16
|
||||||
|
HEADWEAR = 17
|
||||||
|
FACEWEAR = 18
|
||||||
|
IGNORE = 255
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
image_size = 1024
|
||||||
|
face_type = FaceType.WHOLE_FACE
|
||||||
|
|
||||||
|
input_path = Path(input_dir)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
output_path = input_path.parent / f'{input_path.name}_out'
|
||||||
|
if output_path.exists():
|
||||||
|
output_images_paths = pathex.get_image_paths(output_path)
|
||||||
|
if len(output_images_paths) != 0:
|
||||||
|
io.input(f"\n WARNING !!! \n {output_path} contains files! \n They will be deleted. \n Press enter to continue.\n")
|
||||||
|
for filename in output_images_paths:
|
||||||
|
Path(filename).unlink()
|
||||||
|
output_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
data = []
|
||||||
|
|
||||||
|
for filepath in io.progress_bar_generator(pathex.get_paths(input_path), "Processing"):
|
||||||
|
if filepath.suffix == '.txt':
|
||||||
|
|
||||||
|
image_filepath = filepath.parent / f'{filepath.name.split("_")[0]}.png'
|
||||||
|
if not image_filepath.exists():
|
||||||
|
print(f'{image_filepath} does not exist, skipping')
|
||||||
|
|
||||||
|
lmrks = []
|
||||||
|
for lmrk_line in filepath.read_text().split('\n'):
|
||||||
|
if len(lmrk_line) == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
x, y = lmrk_line.split(' ')
|
||||||
|
x, y = float(x), float(y)
|
||||||
|
|
||||||
|
lmrks.append( (x,y) )
|
||||||
|
|
||||||
|
lmrks = np.array(lmrks[:68], np.float32)
|
||||||
|
rect = LandmarksProcessor.get_rect_from_landmarks(lmrks)
|
||||||
|
data += [ ExtractSubprocessor.Data(filepath=image_filepath, rects=[rect], landmarks=[ lmrks ] ) ]
|
||||||
|
|
||||||
|
if len(data) > 0:
|
||||||
|
io.log_info ("Performing 3rd pass...")
|
||||||
|
data = ExtractSubprocessor (data, 'final', image_size, 95, face_type, final_output_path=output_path, device_config=nn.DeviceConfig.CPU()).run()
|
||||||
|
|
||||||
|
for filename in io.progress_bar_generator(pathex.get_image_paths (output_path), "Processing"):
|
||||||
|
filepath = Path(filename)
|
||||||
|
|
||||||
|
dflimg = DFLJPG.load(filepath)
|
||||||
|
|
||||||
|
src_filename = dflimg.get_source_filename()
|
||||||
|
image_to_face_mat = dflimg.get_image_to_face_mat()
|
||||||
|
|
||||||
|
seg_filepath = input_path / ( Path(src_filename).stem + '_seg.png')
|
||||||
|
if not seg_filepath.exists():
|
||||||
|
raise ValueError(f'{seg_filepath} does not exist')
|
||||||
|
|
||||||
|
seg = cv2_imread(seg_filepath)
|
||||||
|
seg_inds = np.isin(seg, [1,2,3,4,5,6,9,10,11])
|
||||||
|
seg[~seg_inds] = 0
|
||||||
|
seg[seg_inds] = 1
|
||||||
|
seg = seg.astype(np.float32)
|
||||||
|
seg = cv2.warpAffine(seg, image_to_face_mat, (image_size, image_size), cv2.INTER_LANCZOS4)
|
||||||
|
dflimg.set_xseg_mask(seg)
|
||||||
|
dflimg.save()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue