61 lines
2.9 KiB
Python
61 lines
2.9 KiB
Python
|
|
#python face_obfuscator.py --config config/vox-256-sem-15segments.yaml --checkpoint stuff/vox-15segments.pth.tar --swap_index 2,3,9,11,15
|
|
def obfuscate(swap_index, source_image, target_image, reconstruction_module, segmentation_module):
|
|
swapped_image = img_as_ubyte(make_video(swap_index, source_image, target_image, reconstruction_module, segmentation_module, None, False, False, True)[0])
|
|
matched = match_histograms(swapped_image, target_image, multichannel=True)
|
|
return matched
|
|
|
|
|
|
def measure_speed():
|
|
checkpoint = "stuff/vox-15segments.pth.tar"
|
|
config = "config/vox-256-sem-15segments.yaml"
|
|
reconstruction_module, segmentation_module = load_checkpoints(config, checkpoint) #TODO hier muss ggf CPU=TRUE gesetzt werden
|
|
source_image = resize(source_image, (256, 256))[..., :3]
|
|
target_image = [resize(target_image, (256, 256))[..., :3]]
|
|
swap_indices = [2, 3, 9, 11, 15]
|
|
output = obfuscate(swap_indices, source_image, target_image, reconstruction_module, segmentation_module)
|
|
|
|
|
|
def obfuscate_face():
|
|
path = r'X:\tempEpicRoflImage_IN.jpg'
|
|
# C:\Users\Bijan\AppData\Local\Temp\tempEpicRoflImage_IN.jpg"
|
|
target_image = imageio.imread(path)
|
|
source_image = imageio.imread(r"faces\\" + str(face_index) + ".jpg")
|
|
source_image = resize(source_image, (256, 256))[..., :3]
|
|
target_video = [target_image]
|
|
target_video = [resize(frame, (256, 256))[..., :3] for frame in target_video]
|
|
predictions = make_video(swap_index, source_image, target_video, reconstruction_module, segmentation_module,
|
|
face_parser, hard, use_source_segmentation, cpu)
|
|
swapped_image = img_as_ubyte(predictions[0])
|
|
matched = match_histograms(swapped_image, target_image, multichannel=True)
|
|
imageio.imwrite(r'X:\tempEpicRoflImage_OUT.jpg', matched)
|
|
# C:\Users\Bijan\AppData\Local\Temp\tempEpicRoflImage_OUT.jpg", matched)
|
|
return json.dumps(True)
|
|
|
|
|
|
def first_run():
|
|
print('Starting test run')
|
|
path = r'X:\tempEpicRoflImage_IN.jpg'
|
|
# C:\Users\Bijan\AppData\Local\Temp\tempEpicRoflImage_IN.jpg
|
|
target_image = imageio.imread(path)
|
|
DeepFace.analyze(img_path=path, actions=['emotion'],
|
|
enforce_detection=False)
|
|
source_image = imageio.imread(r"faces\\" + str(face_index) + ".jpg")
|
|
source_image = resize(source_image, (256, 256))[..., :3]
|
|
target_video = [target_image]
|
|
target_video = [resize(frame, (256, 256))[..., :3] for frame in target_video]
|
|
predictions = make_video(swap_index, source_image, target_video, reconstruction_module, segmentation_module,
|
|
face_parser, hard, use_source_segmentation, cpu)
|
|
swapped_image = img_as_ubyte(predictions[0])
|
|
matched = match_histograms(swapped_image, target_image, multichannel=True)
|
|
imageio.imwrite(path, matched)
|
|
print('Test run succeeded')
|
|
return json.dumps(True)
|
|
|
|
|
|
def main():
|
|
print("TODO")
|
|
|
|
if __name__ == '__main__':
|
|
main()
|