sczhou commited on
Commit
d8235e4
1 Parent(s): 44c001e

avoid upscale for large img.

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -115,10 +115,14 @@ def inference(image, background_enhance, face_upsample, upscale, codeformer_fide
115
  print('\timage size:', img.shape)
116
 
117
  upscale = int(upscale) # covert type to int
118
- if upscale > 4:
119
- upscale = 4 # avoid momory exceeded due to too large upscale
120
- if upscale > 2 and max(img.shape[:2])>1000:
121
- upscale = 2 # avoid momory exceeded due to too large img resolution
 
 
 
 
122
 
123
  face_helper = FaceRestoreHelper(
124
  upscale,
@@ -132,7 +136,6 @@ def inference(image, background_enhance, face_upsample, upscale, codeformer_fide
132
  bg_upsampler = upsampler if background_enhance else None
133
  face_upsampler = upsampler if face_upsample else None
134
 
135
-
136
  if has_aligned:
137
  # the input faces are already cropped and aligned
138
  img = cv2.resize(img, (512, 512), interpolation=cv2.INTER_LINEAR)
 
115
  print('\timage size:', img.shape)
116
 
117
  upscale = int(upscale) # covert type to int
118
+ if upscale > 4: # avoid momory exceeded due to too large upscale
119
+ upscale = 4
120
+ if upscale > 2 and max(img.shape[:2])>1000: # avoid momory exceeded due to too large img resolution
121
+ upscale = 2
122
+ if max(img.shape[:2]) > 1500: # avoid momory exceeded due to too large img resolution
123
+ upscale = 1
124
+ background_enhance = False
125
+ face_upsample = False
126
 
127
  face_helper = FaceRestoreHelper(
128
  upscale,
 
136
  bg_upsampler = upsampler if background_enhance else None
137
  face_upsampler = upsampler if face_upsample else None
138
 
 
139
  if has_aligned:
140
  # the input faces are already cropped and aligned
141
  img = cv2.resize(img, (512, 512), interpolation=cv2.INTER_LINEAR)