ohayonguy commited on
Commit
38e388c
1 Parent(s): 8b15c69

trying to fix daemonic processes error

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -43,6 +43,18 @@ face_helper_dummy = FaceRestoreHelper(
43
  os.makedirs('output', exist_ok=True)
44
 
45
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  def enhance_face(img, face_helper, has_aligned, only_center_face=False, paste_back=True, scale=2):
47
  face_helper.clean_all()
48
 
@@ -63,10 +75,9 @@ def enhance_face(img, face_helper, has_aligned, only_center_face=False, paste_ba
63
  cropped_face_t = cropped_face_t.unsqueeze(0).to(device)
64
 
65
  try:
66
- restored_face = img
67
- # dummy_x = torch.zeros_like(cropped_face_t)
68
- # output = pmrf.generate_reconstructions(dummy_x, cropped_face_t, None, 25, device)
69
- # restored_face = tensor2img(output.squeeze(0), rgb2bgr=True, min_max=(0, 1))
70
  except RuntimeError as error:
71
  print(f'\tFailed inference for PMRF: {error}.')
72
  restored_face = cropped_face
 
43
  os.makedirs('output', exist_ok=True)
44
 
45
 
46
+ def generate_reconstructions(pmrf_model, x, y, non_noisy_z0, num_flow_steps, device):
47
+ source_dist_samples = pmrf_model.create_source_distribution_samples(x, y, non_noisy_z0)
48
+ dt = (1.0 / num_flow_steps) * (1.0 - pmrf_model.hparams.eps)
49
+ x_t_next = source_dist_samples.clone()
50
+ t_one = torch.ones(x.shape[0], device=device)
51
+ for i in range(num_flow_steps):
52
+ num_t = (i / num_flow_steps) * (1.0 - pmrf_model.hparams.eps) + pmrf_model.hparams.eps
53
+ v_t_next = pmrf_model(x_t=x_t_next, t=t_one * num_t, y=y).to(x_t_next.dtype)
54
+ x_t_next = x_t_next.clone() + v_t_next * dt
55
+
56
+ return x_t_next.clip(0, 1).to(torch.float32)
57
+
58
  def enhance_face(img, face_helper, has_aligned, only_center_face=False, paste_back=True, scale=2):
59
  face_helper.clean_all()
60
 
 
75
  cropped_face_t = cropped_face_t.unsqueeze(0).to(device)
76
 
77
  try:
78
+ dummy_x = torch.zeros_like(cropped_face_t)
79
+ output = generate_reconstructions(pmrf, dummy_x, cropped_face_t, None, 25, device)
80
+ restored_face = tensor2img(output.squeeze(0), rgb2bgr=True, min_max=(0, 1))
 
81
  except RuntimeError as error:
82
  print(f'\tFailed inference for PMRF: {error}.')
83
  restored_face = cropped_face