lucky0146 commited on
Commit
37aabe6
·
verified ·
1 Parent(s): 1a1e1ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -27,11 +27,11 @@ def setup_environment():
27
  retinaface_path = "weights/detection_Resnet50_Final.pth"
28
  download_file(retinaface_url, retinaface_path)
29
 
30
- # Define a simplified CodeFormer architecture (instead of downloading codeformer_arch.py)
31
  class CodeFormer(torch.nn.Module):
32
  def __init__(self, dim_embd=512, codebook_size=1024, n_head=8, n_layer=9, connect_list=['32', '64', '128', '256']):
33
  super(CodeFormer, self).__init__()
34
- # This is a simplified placeholder. In practice, you'd need the full architecture.
35
  self.encoder = torch.nn.Sequential(
36
  torch.nn.Conv2d(3, dim_embd, kernel_size=3, stride=1, padding=1),
37
  torch.nn.ReLU(),
@@ -41,7 +41,6 @@ class CodeFormer(torch.nn.Module):
41
  torch.nn.ConvTranspose2d(dim_embd, 3, kernel_size=3, stride=1, padding=1),
42
  torch.nn.Sigmoid()
43
  )
44
- # Note: This is a mock implementation. Full CodeFormer requires the actual codeformer_arch.py.
45
 
46
  def forward(self, x, w=0.5, adain=True):
47
  # Simplified forward pass (placeholder)
@@ -91,8 +90,8 @@ def enhance_image(image, fidelity_weight=0.5):
91
  face_helper = FaceRestoreHelper(upscale_factor=1, face_size=512, crop_ratio=(1, 1), det_model='retinaface_resnet50', save_ext='png', device='cpu')
92
  face_helper.clean_all()
93
  face_helper.read_image(img)
94
- face_helper.get_face_landmarks_5(align=True)
95
- face_helper.align_warp_face()
96
 
97
  # Enhance face with CodeFormer
98
  for cropped_face in face_helper.cropped_faces:
 
27
  retinaface_path = "weights/detection_Resnet50_Final.pth"
28
  download_file(retinaface_url, retinaface_path)
29
 
30
+ # Define a simplified CodeFormer architecture (placeholder)
31
  class CodeFormer(torch.nn.Module):
32
  def __init__(self, dim_embd=512, codebook_size=1024, n_head=8, n_layer=9, connect_list=['32', '64', '128', '256']):
33
  super(CodeFormer, self).__init__()
34
+ # Simplified placeholder (full architecture requires codeformer_arch.py)
35
  self.encoder = torch.nn.Sequential(
36
  torch.nn.Conv2d(3, dim_embd, kernel_size=3, stride=1, padding=1),
37
  torch.nn.ReLU(),
 
41
  torch.nn.ConvTranspose2d(dim_embd, 3, kernel_size=3, stride=1, padding=1),
42
  torch.nn.Sigmoid()
43
  )
 
44
 
45
  def forward(self, x, w=0.5, adain=True):
46
  # Simplified forward pass (placeholder)
 
90
  face_helper = FaceRestoreHelper(upscale_factor=1, face_size=512, crop_ratio=(1, 1), det_model='retinaface_resnet50', save_ext='png', device='cpu')
91
  face_helper.clean_all()
92
  face_helper.read_image(img)
93
+ face_helper.get_face_landmarks_5() # Removed align=True
94
+ face_helper.align_warp_face() # Ensure alignment happens here
95
 
96
  # Enhance face with CodeFormer
97
  for cropped_face in face_helper.cropped_faces: