fixed error "Failed to get convolution algorithm" on some systems

fixed error "dll load failed" on some systems
Expanded eyebrows line of face masks. It does not affect mask of FAN-x converter mode.
This commit is contained in:
iperov
2019-08-11 11:17:22 +04:00
parent 582c974851
commit b72d5a3f9a
15 changed files with 367 additions and 222 deletions

View File

@@ -13,7 +13,18 @@ class SampleGeneratorBase(object):
self.samples_path = Path(samples_path)
self.debug = debug
self.batch_size = 1 if self.debug else batch_size
self.last_generation = None
self.active = True
def set_active(self, is_active):
self.active = is_active
def generate_next(self):
if not self.active and self.last_generation is not None:
return self.last_generation
self.last_generation = next(self)
return self.last_generation
#overridable
def __iter__(self):
#implement your own iterator

View File

@@ -8,7 +8,7 @@ from samplelib import SampleType, SampleProcessor, SampleLoader, SampleGenerator
'''
output_sample_types = [
[SampleProcessor.TypeFlags, size, (optional)random_sub_size] ,
[SampleProcessor.TypeFlags, size, (optional) {} opts ] ,
...
]
'''
@@ -46,9 +46,9 @@ class SampleGeneratorFaceTemporal(SampleGeneratorBase):
raise ValueError('No training data provided.')
mult_max = 1
l = samples_len - (self.temporal_image_count-1)*mult_max + 1
l = samples_len - ( (self.temporal_image_count)*mult_max - (mult_max-1) )
samples_idxs = [ *range(l) ] [generator_id::self.generators_count]
samples_idxs = [ *range(l+1) ] [generator_id::self.generators_count]
if len(samples_idxs) - self.temporal_image_count < 0:
raise ValueError('Not enough samples to fit temporal line.')
@@ -67,7 +67,7 @@ class SampleGeneratorFaceTemporal(SampleGeneratorBase):
idx = shuffle_idxs.pop()
temporal_samples = []
mult = np.random.randint(mult_max)
mult = np.random.randint(mult_max)+1
for i in range( self.temporal_image_count ):
sample = samples[ idx+i*mult ]
try:

View File

@@ -43,7 +43,8 @@ class SampleGeneratorImageTemporal(SampleGeneratorBase):
raise ValueError('No training data provided.')
mult_max = 4
samples_sub_len = samples_len - (self.temporal_image_count-1)*mult_max
samples_sub_len = samples_len - ( (self.temporal_image_count)*mult_max - (mult_max-1) )
if samples_sub_len <= 0:
raise ValueError('Not enough samples to fit temporal line.')
@@ -61,7 +62,7 @@ class SampleGeneratorImageTemporal(SampleGeneratorBase):
idx = shuffle_idxs.pop()
temporal_samples = []
mult = np.random.randint(mult_max)
mult = np.random.randint(mult_max)+1
for i in range( self.temporal_image_count ):
sample = samples[ idx+i*mult ]
try:

View File

@@ -61,6 +61,7 @@ class SampleProcessor(object):
FACE_TYPE_FULL = 11
FACE_TYPE_HEAD = 12 #currently unused
FACE_TYPE_AVATAR = 13 #currently unused
FACE_TYPE_FULL_NO_ALIGN = 14
FACE_TYPE_END = 20
MODE_BEGIN = 40
@@ -103,7 +104,7 @@ class SampleProcessor(object):
SPTF_FACETYPE_TO_FACETYPE = { SPTF.FACE_TYPE_HALF : FaceType.HALF,
SPTF.FACE_TYPE_FULL : FaceType.FULL,
SPTF.FACE_TYPE_HEAD : FaceType.HEAD,
SPTF.FACE_TYPE_AVATAR : FaceType.AVATAR }
SPTF.FACE_TYPE_FULL_NO_ALIGN : FaceType.FULL_NO_ALIGN }
outputs = []
for opts in output_sample_types:
@@ -157,6 +158,20 @@ class SampleProcessor(object):
if mode_type == SPTF.NONE:
raise ValueError ('expected MODE_ type')
def do_transform(img, mask):
warp = (img_type==SPTF.IMG_WARPED or img_type==SPTF.IMG_WARPED_TRANSFORMED)
transform = (img_type==SPTF.IMG_WARPED_TRANSFORMED or img_type==SPTF.IMG_TRANSFORMED)
flip = img_type != SPTF.IMG_WARPED
img = imagelib.warp_by_params (params, img, warp, transform, flip, True)
if mask is not None:
mask = imagelib.warp_by_params (params, mask, warp, transform, flip, False)
if len(mask.shape) == 2:
mask = mask[...,np.newaxis]
img = np.concatenate( (img, mask ), -1 )
return img
img = cached_images.get(img_type, None)
if img is None:
@@ -181,15 +196,12 @@ class SampleProcessor(object):
if cur_sample.ie_polys is not None:
cur_sample.ie_polys.overlay_mask(mask)
warp = (img_type==SPTF.IMG_WARPED or img_type==SPTF.IMG_WARPED_TRANSFORMED)
transform = (img_type==SPTF.IMG_WARPED_TRANSFORMED or img_type==SPTF.IMG_TRANSFORMED)
flip = img_type != SPTF.IMG_WARPED
img = imagelib.warp_by_params (params, img, warp, transform, flip, True)
if mask is not None:
mask = imagelib.warp_by_params (params, mask, warp, transform, flip, False)[...,np.newaxis]
img = np.concatenate( (img, mask ), -1 )
if sample.face_type == FaceType.MARK_ONLY:
if mask is not None:
img = np.concatenate( (img, mask), -1 )
else:
img = do_transform (img, mask)
cached_images[img_type] = img
@@ -197,7 +209,17 @@ class SampleProcessor(object):
ft = SPTF_FACETYPE_TO_FACETYPE[target_face_type]
if ft > sample.face_type:
raise Exception ('sample %s type %s does not match model requirement %s. Consider extract necessary type of faces.' % (sample.filename, sample.face_type, ft) )
img = cv2.warpAffine( img, LandmarksProcessor.get_transform_mat (sample.landmarks, resolution, ft), (resolution,resolution), flags=cv2.INTER_CUBIC )
if sample.face_type == FaceType.MARK_ONLY:
img = cv2.warpAffine( img, LandmarksProcessor.get_transform_mat (sample.landmarks, sample.shape[0], ft), (sample.shape[0],sample.shape[0]), flags=cv2.INTER_CUBIC )
mask = img[...,3:4] if img.shape[2] > 3 else None
img = img[...,0:3]
img = do_transform (img, mask)
img = cv2.resize( img, (resolution,resolution), cv2.INTER_CUBIC )
else:
img = cv2.warpAffine( img, LandmarksProcessor.get_transform_mat (sample.landmarks, resolution, ft), (resolution,resolution), flags=cv2.INTER_CUBIC )
else:
img = cv2.resize( img, (resolution,resolution), cv2.INTER_CUBIC )