LogicGoInfotechSpaces commited on
Commit
600df15
·
1 Parent(s): 14cc518

Make facer and fpie dependencies optional for face alignment

Browse files
Files changed (1) hide show
  1. runners/simple_runner.py +18 -2
runners/simple_runner.py CHANGED
@@ -17,7 +17,18 @@ from runners.inference_runners import FSEInferenceRunner
17
 
18
 
19
  def extract_mask(image_path, save_dir_path, trash=0.995):
20
- from models.farl.farl import Masker
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  save_dir_path = Path(save_dir_path)
23
  image_path = Path(image_path)
@@ -104,11 +115,16 @@ def unalign(edited_image, unalign_dict, orig_img_pth, unaligned_path):
104
  PIL.Image.fromarray(unaligned.astype('uint8'), 'RGB').save("edited.png")
105
  PIL.Image.fromarray(np.uint8(np.clip(np.rint((1 - mask) * 255), 0, 255)), 'RGB').save("mask.jpg")
106
 
107
- subprocess.run(
 
108
  ["fpie", "-s", orig_img_pth, "-m", "mask.jpg", "-t", "edited.png", "-o", unaligned_path, "-n",
109
  "5000", "-b", "taichi-gpu", "-g", "src"],
110
  check=True
111
  )
 
 
 
 
112
 
113
 
114
  class SimpleRunner:
 
17
 
18
 
19
  def extract_mask(image_path, save_dir_path, trash=0.995):
20
+ try:
21
+ from models.farl.farl import Masker
22
+ except ImportError:
23
+ print("Warning: facer module not available, skipping background mask extraction")
24
+ # Return a dummy mask path
25
+ save_dir_path = Path(save_dir_path)
26
+ image_path = Path(image_path)
27
+ mask_path = save_dir_path / (image_path.stem + "_mask.jpg")
28
+ # Create a simple white mask (no masking)
29
+ mask = Image.new("1", (1024, 1024), 1)
30
+ mask.save(mask_path)
31
+ return mask_path
32
 
33
  save_dir_path = Path(save_dir_path)
34
  image_path = Path(image_path)
 
115
  PIL.Image.fromarray(unaligned.astype('uint8'), 'RGB').save("edited.png")
116
  PIL.Image.fromarray(np.uint8(np.clip(np.rint((1 - mask) * 255), 0, 255)), 'RGB').save("mask.jpg")
117
 
118
+ try:
119
+ subprocess.run(
120
  ["fpie", "-s", orig_img_pth, "-m", "mask.jpg", "-t", "edited.png", "-o", unaligned_path, "-n",
121
  "5000", "-b", "taichi-gpu", "-g", "src"],
122
  check=True
123
  )
124
+ except FileNotFoundError:
125
+ print("Warning: fpie command not available, skipping unalign step")
126
+ # Just copy the edited image as the final result
127
+ PIL.Image.open("edited.png").save(unaligned_path)
128
 
129
 
130
  class SimpleRunner: