sczhou commited on
Commit
ce81a5e
1 Parent(s): 3931f41

add upscale limit for large input.

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +5 -3
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🐼
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
- sdk_version: 3.3
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
+ sdk_version: 3.4
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
app.py CHANGED
@@ -111,9 +111,14 @@ def inference(image, background_enhance, face_upsample, upscale, codeformer_fide
111
  detection_model = "retinaface_resnet50"
112
  print('Inp:', image, background_enhance, face_upsample, upscale, codeformer_fidelity)
113
 
 
 
 
114
  upscale = int(upscale) # covert type to int
115
  if upscale > 4:
116
  upscale = 4 # avoid momory exceeded due to too large upscale
 
 
117
 
118
  face_helper = FaceRestoreHelper(
119
  upscale,
@@ -127,9 +132,6 @@ def inference(image, background_enhance, face_upsample, upscale, codeformer_fide
127
  bg_upsampler = upsampler if background_enhance else None
128
  face_upsampler = upsampler if face_upsample else None
129
 
130
- img = cv2.imread(str(image), cv2.IMREAD_COLOR)
131
-
132
- print('\timage size:', img.shape)
133
 
134
  if has_aligned:
135
  # the input faces are already cropped and aligned
 
111
  detection_model = "retinaface_resnet50"
112
  print('Inp:', image, background_enhance, face_upsample, upscale, codeformer_fidelity)
113
 
114
+ img = cv2.imread(str(image), cv2.IMREAD_COLOR)
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 min(img.shape[:2])>1280:
121
+ upscale = 2 # avoid momory exceeded due to too large img resolution
122
 
123
  face_helper = FaceRestoreHelper(
124
  upscale,
 
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