This commit is contained in:
iperov 2021-10-28 09:31:30 +04:00
parent 8fc4447dab
commit 1d4d3cd0e8
3 changed files with 21 additions and 24 deletions

View file

@ -54,10 +54,15 @@ def main():
def run_extract_FaceSynthetics(args): def run_extract_FaceSynthetics(args):
from scripts import dev from scripts import dev
dev.extract_FaceSynthetics(input_dir=args.input_dir)
inputdir_path = Path(args.input_dir)
faceset_path = Path(args.faceset_path)
dev.extract_FaceSynthetics(inputdir_path, faceset_path)
p = dev_subparsers.add_parser('extract_FaceSynthetics') p = dev_subparsers.add_parser('extract_FaceSynthetics')
p.add_argument('--input-dir', default=None, action=fixPathAction, help="FaceSynthetics directory.") p.add_argument('--input-dir', default=None, action=fixPathAction, help="FaceSynthetics directory.")
p.add_argument('--faceset-path', default=None, action=fixPathAction, help="output .dfs path")
p.set_defaults(func=run_extract_FaceSynthetics) p.set_defaults(func=run_extract_FaceSynthetics)
train_parser = subparsers.add_parser( "train", help="Train neural network.") train_parser = subparsers.add_parser( "train", help="Train neural network.")

View file

@ -26,7 +26,7 @@ def split_large_files(delete_original=False):
SplittedFile.split(filepath, part_size=part_size, delete_original=delete_original) SplittedFile.split(filepath, part_size=part_size, delete_original=delete_original)
print('Done') print('Done')
def extract_FaceSynthetics(input_dir): def extract_FaceSynthetics(inputdir_path : Path, faceset_path : Path):
""" """
extract FaceSynthetics dataset https://github.com/microsoft/FaceSynthetics extract FaceSynthetics dataset https://github.com/microsoft/FaceSynthetics
@ -51,19 +51,11 @@ def extract_FaceSynthetics(input_dir):
FACEWEAR = 18 FACEWEAR = 18
IGNORE = 255 IGNORE = 255
""" """
input_path = Path(input_dir) if faceset_path.suffix != '.dfs':
faceset_path = input_path.parent / f'{input_path.name}.dfs' raise ValueError('faceset_path must have .dfs extension.')
# fs = lib_face.Faceset(output_dbpath) filepaths = lib_path.get_files_paths(inputdir_path)
# for ufm in fs.iter_UFaceMark():
# uimg = fs.get_UImage_by_uuid( ufm.get_UImage_uuid() )
# img = uimg.get_image()
# cv2.imshow('', img)
# cv2.waitKey(0)
filepaths = lib_path.get_files_paths(input_path)[:100] #TODO
fs = lib_face.Faceset(faceset_path) fs = lib_face.Faceset(faceset_path)
fs.recreate() fs.recreate()
@ -75,7 +67,7 @@ def extract_FaceSynthetics(input_dir):
if not image_filepath.exists(): if not image_filepath.exists():
print(f'{image_filepath} does not exist, skipping') print(f'{image_filepath} does not exist, skipping')
img = lib_cv.imread(image_filepath) img = lib_cv.imread(image_filepath)
H,W,C = img.shape H,W,C = img.shape
@ -101,14 +93,14 @@ def extract_FaceSynthetics(input_dir):
ufm.set_UImage_uuid(uimg.get_uuid()) ufm.set_UImage_uuid(uimg.get_uuid())
ufm.set_FRect(flmrks.get_FRect()) ufm.set_FRect(flmrks.get_FRect())
ufm.add_FLandmarks2D(flmrks) ufm.add_FLandmarks2D(flmrks)
fs.add_UImage(uimg, format='png') fs.add_UImage(uimg, format='png')
fs.add_UFaceMark(ufm) fs.add_UFaceMark(ufm)
fs.shrink() fs.shrink()
fs.close() fs.close()
import code import code
code.interact(local=dict(globals(), **locals())) code.interact(local=dict(globals(), **locals()))
@ -122,10 +114,10 @@ def extract_FaceSynthetics(input_dir):
# img_seg = img_seg[...,None] # img_seg = img_seg[...,None]
# if img_seg.shape[-1] != 1: # if img_seg.shape[-1] != 1:
# raise Exception(f'{seg_filepath} wrong mask file. Must be 1 channel.') # raise Exception(f'{seg_filepath} wrong mask file. Must be 1 channel.')
# seg_hair = img_seg.copy() # seg_hair = img_seg.copy()
# seg_hair_inds = np.isin(img_seg, [13]) # seg_hair_inds = np.isin(img_seg, [13])
# seg_hair[~seg_hair_inds] = 0 # seg_hair[~seg_hair_inds] = 0
# seg_hair[seg_hair_inds] = 255 # seg_hair[seg_hair_inds] = 255
@ -141,7 +133,7 @@ def extract_FaceSynthetics(input_dir):
# cv2.imshow('', seg_hair) # cv2.imshow('', seg_hair)
# cv2.waitKey(0) # cv2.waitKey(0)
# img_seg_inds = np.isin(img_seg, [1,2,3,4,5,6,9,10,11,14]) # img_seg_inds = np.isin(img_seg, [1,2,3,4,5,6,9,10,11,14])
# img_seg[~img_seg_inds] = 0 # img_seg[~img_seg_inds] = 0
# img_seg[img_seg_inds] = 255 # img_seg[img_seg_inds] = 255
# import numpy as np # import numpy as np

View file

@ -1,5 +1,5 @@
""" """
Job processing in subprocesses. Job lib using subprocesses
""" """
import multiprocessing import multiprocessing