This commit is contained in:
iperov 2019-04-23 14:07:38 +04:00
parent 565c131b97
commit 8969e80275
3 changed files with 15 additions and 7 deletions

View file

@ -21,7 +21,7 @@ class Model(ModelBase):
def onInitializeOptions(self, is_first_run, ask_override): def onInitializeOptions(self, is_first_run, ask_override):
default_face_type = 'f' default_face_type = 'f'
if is_first_run: if is_first_run:
self.options['face_type'] = io.input_str ("Half or Full face? (h/f, ?:help skip:f) : ", default_face_type, ['h','f'], help_message="Half face has better resolution, but covers less area of cheeks.").lower() self.options['face_type'] = io.input_str ("Half or Full face? (h/f, ?:help skip:f) : ", default_face_type, ['h','f'], help_message="").lower()
else: else:
self.options['face_type'] = self.options.get('face_type', default_face_type) self.options['face_type'] = self.options.get('face_type', default_face_type)
@ -48,12 +48,12 @@ class Model(ModelBase):
SampleGeneratorFace(self.training_data_src_path, debug=self.is_debug(), batch_size=self.batch_size, SampleGeneratorFace(self.training_data_src_path, debug=self.is_debug(), batch_size=self.batch_size,
sample_process_options=SampleProcessor.Options(random_flip=True, motion_blur = [25, 1] ), sample_process_options=SampleProcessor.Options(random_flip=True, motion_blur = [25, 1] ),
output_sample_types=[ [f.WARPED_TRANSFORMED | face_type | f.MODE_BGR_SHUFFLE | f.OPT_APPLY_MOTION_BLUR, self.resolution], output_sample_types=[ [f.WARPED_TRANSFORMED | face_type | f.MODE_BGR_SHUFFLE | f.OPT_APPLY_MOTION_BLUR, self.resolution],
[f.WARPED_TRANSFORMED | face_type | f.MODE_M | f.FACE_MASK_FULL, self.resolution] [f.WARPED_TRANSFORMED | face_type | f.MODE_M | f.FACE_MASK_FULL, self.resolution],
]), ]),
SampleGeneratorFace(self.training_data_dst_path, debug=self.is_debug(), batch_size=self.batch_size, SampleGeneratorFace(self.training_data_dst_path, debug=self.is_debug(), batch_size=self.batch_size,
sample_process_options=SampleProcessor.Options(random_flip=True ), sample_process_options=SampleProcessor.Options(random_flip=True ),
output_sample_types=[ [f.TRANSFORMED | face_type | f.MODE_BGR_SHUFFLE, self.resolution] output_sample_types=[ [f.TRANSFORMED | face_type | f.MODE_BGR_SHUFFLE, self.resolution],
]) ])
]) ])
@ -71,8 +71,8 @@ class Model(ModelBase):
#override #override
def onGetPreview(self, sample): def onGetPreview(self, sample):
test_A = sample[0][0][0:4] #first 4 samples test_A = sample[0][0][0:4] #first 4 samples
test_B = sample[1][0][0:4] #first 4 samples test_B = sample[1][0][0:4] #first 4 samples
mAA = self.fan_seg.extract(test_A) mAA = self.fan_seg.extract(test_A)
mBB = self.fan_seg.extract(test_B) mBB = self.fan_seg.extract(test_B)

View file

@ -10,7 +10,7 @@ from samplelib import SampleType, SampleProcessor, SampleLoader, SampleGenerator
''' '''
arg arg
output_sample_types = [ output_sample_types = [
[SampleProcessor.TypeFlags, size, (optional)random_sub_size] , [SampleProcessor.TypeFlags, size, (optional) {} opts ] ,
... ...
] ]
''' '''

View file

@ -32,6 +32,8 @@ class SampleProcessor(object):
MODE_M = 0x00080000, #mask only MODE_M = 0x00080000, #mask only
MODE_BGR_SHUFFLE = 0x00100000, #BGR shuffle MODE_BGR_SHUFFLE = 0x00100000, #BGR shuffle
OPT_APPLY_MOTION_BLUR = 0x10000000, OPT_APPLY_MOTION_BLUR = 0x10000000,
class Options(object): class Options(object):
@ -79,7 +81,10 @@ class SampleProcessor(object):
for sample_type in output_sample_types: for sample_type in output_sample_types:
f = sample_type[0] f = sample_type[0]
size = 0 if len (sample_type) < 2 else sample_type[1] size = 0 if len (sample_type) < 2 else sample_type[1]
random_sub_size = 0 if len (sample_type) < 3 else min( sample_type[2] , size) opts = {} if len (sample_type) < 3 else sample_type[2]
random_sub_size = opts.get('random_sub_size', 0)
normalize_std_dev = opts.get('normalize_std_dev', False)
if f & SPTF.SOURCE != 0: if f & SPTF.SOURCE != 0:
img_type = 0 img_type = 0
@ -221,6 +226,9 @@ class SampleProcessor(object):
img_bgr = img[...,0:3] img_bgr = img[...,0:3]
img_mask = img[...,3:4] img_mask = img[...,3:4]
if normalize_std_dev:
img_bgr = (img_bgr - img_bgr.mean( (0,1)) ) / img_bgr.std( (0,1) )
if f & SPTF.MODE_BGR != 0: if f & SPTF.MODE_BGR != 0:
img = img_bgr img = img_bgr
elif f & SPTF.MODE_BGR_SHUFFLE != 0: elif f & SPTF.MODE_BGR_SHUFFLE != 0: