ghost icon indicating copy to clipboard operation
ghost copied to clipboard

get the most core swap face code,for guys to use

Open xiaohaipeng opened this issue 5 months ago • 0 comments

def swap_face(source,target,netArc,G,half=True): target_norm = normalize_and_torch(np.array(target)) target_embeds = netArc(F.interpolate(target_norm, scale_factor=0.5, mode='bilinear', align_corners=True))

source_curr = normalize_and_torch(source)
source_embed = netArc(F.interpolate(source_curr, scale_factor=0.5, mode='bilinear', align_corners=True))

resized_image = cv2.resize(target,(256,256))
resized_frs = np.array([resized_image])
target_batch_rs = transform_target_to_torch(resized_frs, half=half)

if half:
        source_embed = source_embed.half()

Y_st = faceshifter_batch(source_embed, target_batch_rs, G)
return Y_st[0]

xiaohaipeng avatar May 23 '25 08:05 xiaohaipeng