Charbel Malo commited on
Commit
b6f9811
·
verified ·
1 Parent(s): bfa85f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -121,7 +121,7 @@ else:
121
  print("\n********** Running on CPU **********\n")
122
  PROVIDER = ["CPUExecutionProvider"]
123
 
124
- device = "cuda" if USE_CUDA else "cpu"
125
  EMPTY_CACHE = lambda: torch.cuda.empty_cache() if device == "cuda" else None
126
 
127
  ## ------------------------------ LOAD MODELS ------------------------------
@@ -148,7 +148,7 @@ def load_face_swapper_model(path="./assets/pretrained_models/inswapper_128.onnx"
148
  def load_face_parser_model(path="./assets/pretrained_models/79999_iter.pth"):
149
  global FACE_PARSER
150
  if FACE_PARSER is None:
151
- FACE_PARSER = init_parsing_model(path, device="cuda")
152
 
153
  @spaces.GPU(enable_queue=True)
154
  def load_nsfw_detector_model(path="./assets/pretrained_models/open-nsfw.onnx"):
@@ -215,7 +215,7 @@ def process(
215
  print("\n********** Running on CPU **********\n")
216
  PROVIDER = ["CPUExecutionProvider"]
217
 
218
- device = "cuda" if USE_CUDA else "cpu"
219
  EMPTY_CACHE = lambda: torch.cuda.empty_cache() if device == "cuda" else None
220
 
221
  # Reset models to None to reload them with GPU
@@ -269,7 +269,7 @@ def process(
269
  if face_enhancer_name != "NONE":
270
  if face_enhancer_name not in cv2_interpolations:
271
  yield f"### \n ⌛ Loading {face_enhancer_name} model...", *ui_before()
272
- FACE_ENHANCER = load_face_enhancer_model(name=face_enhancer_name, device=device)
273
  else:
274
  FACE_ENHANCER = None
275
 
@@ -351,7 +351,7 @@ def process(
351
  yield "### \n ⌛ Face-parsing mask...", *ui_before()
352
  masks = []
353
  count = 0
354
- for batch_mask in get_parsed_mask(FACE_PARSER, preds, classes=includes, device=device, batch_size=BATCH_SIZE, softness=int(mask_soft_iterations)):
355
  masks.append(batch_mask)
356
  EMPTY_CACHE()
357
  count += 1
 
121
  print("\n********** Running on CPU **********\n")
122
  PROVIDER = ["CPUExecutionProvider"]
123
 
124
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
125
  EMPTY_CACHE = lambda: torch.cuda.empty_cache() if device == "cuda" else None
126
 
127
  ## ------------------------------ LOAD MODELS ------------------------------
 
148
  def load_face_parser_model(path="./assets/pretrained_models/79999_iter.pth"):
149
  global FACE_PARSER
150
  if FACE_PARSER is None:
151
+ FACE_PARSER = init_parsing_model(path, device=torch.device('cuda' if torch.cuda.is_available() else 'cpu'))
152
 
153
  @spaces.GPU(enable_queue=True)
154
  def load_nsfw_detector_model(path="./assets/pretrained_models/open-nsfw.onnx"):
 
215
  print("\n********** Running on CPU **********\n")
216
  PROVIDER = ["CPUExecutionProvider"]
217
 
218
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
219
  EMPTY_CACHE = lambda: torch.cuda.empty_cache() if device == "cuda" else None
220
 
221
  # Reset models to None to reload them with GPU
 
269
  if face_enhancer_name != "NONE":
270
  if face_enhancer_name not in cv2_interpolations:
271
  yield f"### \n ⌛ Loading {face_enhancer_name} model...", *ui_before()
272
+ FACE_ENHANCER = load_face_enhancer_model(name=face_enhancer_name, device=torch.device('cuda' if torch.cuda.is_available() else 'cpu'))
273
  else:
274
  FACE_ENHANCER = None
275
 
 
351
  yield "### \n ⌛ Face-parsing mask...", *ui_before()
352
  masks = []
353
  count = 0
354
+ for batch_mask in get_parsed_mask(FACE_PARSER, preds, classes=includes, device=torch.device('cuda' if torch.cuda.is_available() else 'cpu'), batch_size=BATCH_SIZE, softness=int(mask_soft_iterations)):
355
  masks.append(batch_mask)
356
  EMPTY_CACHE()
357
  count += 1