Skip to content

Commit

Permalink
Fix anonymize_image with multiple faces (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
FHellmann authored Mar 13, 2024
2 parents 31f1220 + 588beaa commit e7a0ab2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,17 @@ def anonymize_image(model_file: str, input_file: str, output_file: str, img_size
"""
img = cv2.imread(input_file)
if img is not None:
img = FaceCrop(align)(img)[0]
img = ZeroPaddingResize(img_size)(img)
img = FacialLandmarks478()(img)
img = Pix2PixTransformer(model_file, img_size, device)(img)
img = torch.squeeze(img)
img = (img + 1) / 2
pil_img = transforms.ToPILImage()(img)
os.makedirs(os.path.dirname(output_file), exist_ok=True)
pil_img.save(output_file)
faces = FaceCrop(align)(img)
for idx, f in enumerate(faces):
img = f
img = ZeroPaddingResize(img_size)(img)
img = FacialLandmarks478()(img)
img = Pix2PixTransformer(model_file, img_size, device)(img)
img = torch.squeeze(img)
img = (img + 1) / 2
pil_img = transforms.ToPILImage()(img)
os.makedirs(os.path.dirname(output_file), exist_ok=True)
pil_img.save(os.path.join(os.path.dirname(output_file), f'{idx}_{os.path.basename(output_file)}'))


def anonymize_directory(model_file: str, input_directory: str, output_directory: str,
Expand Down

0 comments on commit e7a0ab2

Please sign in to comment.