jhj0517
commited on
Commit
·
8b2f0bf
1
Parent(s):
93091a7
Disable ultralytics_logger
Browse files
modules/live_portrait/live_portrait_inferencer.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import numpy as np
|
|
@@ -9,6 +10,7 @@ import dill
|
|
| 9 |
from ultralytics import YOLO
|
| 10 |
import safetensors.torch
|
| 11 |
import gradio as gr
|
|
|
|
| 12 |
|
| 13 |
from modules.utils.paths import *
|
| 14 |
from modules.utils.image_helper import *
|
|
@@ -396,10 +398,13 @@ class LivePortraitInferencer:
|
|
| 396 |
return pred[0].boxes.xyxy.cpu().numpy()
|
| 397 |
|
| 398 |
def detect_face(self, image_rgb, crop_factor, sort = True):
|
|
|
|
|
|
|
|
|
|
| 399 |
bboxes = self.get_face_bboxes(image_rgb)
|
| 400 |
w, h = get_rgb_size(image_rgb)
|
| 401 |
|
| 402 |
-
print(f"w, h:{w, h}")
|
| 403 |
|
| 404 |
cx = w / 2
|
| 405 |
min_diff = w
|
|
@@ -410,7 +415,7 @@ class LivePortraitInferencer:
|
|
| 410 |
diff = abs(cx - (x1 + bbox_w / 2))
|
| 411 |
if diff < min_diff:
|
| 412 |
best_box = [x1, y1, x2, y2]
|
| 413 |
-
print(f"diff, min_diff, best_box:{diff, min_diff, best_box}")
|
| 414 |
min_diff = diff
|
| 415 |
|
| 416 |
if best_box == None:
|
|
@@ -467,6 +472,7 @@ class LivePortraitInferencer:
|
|
| 467 |
new_x2 -= over_min
|
| 468 |
new_y2 -= over_min
|
| 469 |
|
|
|
|
| 470 |
return [int(new_x1), int(new_y1), int(new_x2), int(new_y2)]
|
| 471 |
|
| 472 |
@staticmethod
|
|
@@ -531,7 +537,7 @@ class LivePortraitInferencer:
|
|
| 531 |
def prepare_source(self, source_image, crop_factor, is_video=False, tracking=False):
|
| 532 |
# source_image_np = (source_image * 255).byte().numpy()
|
| 533 |
# img_rgb = source_image_np[0]
|
| 534 |
-
print("Prepare source...")
|
| 535 |
if len(source_image.shape) <= 3:
|
| 536 |
source_image = source_image[np.newaxis, ...]
|
| 537 |
|
|
|
|
| 1 |
+
import logging
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
import numpy as np
|
|
|
|
| 10 |
from ultralytics import YOLO
|
| 11 |
import safetensors.torch
|
| 12 |
import gradio as gr
|
| 13 |
+
from ultralytics.utils import LOGGER as ultralytics_logger
|
| 14 |
|
| 15 |
from modules.utils.paths import *
|
| 16 |
from modules.utils.image_helper import *
|
|
|
|
| 398 |
return pred[0].boxes.xyxy.cpu().numpy()
|
| 399 |
|
| 400 |
def detect_face(self, image_rgb, crop_factor, sort = True):
|
| 401 |
+
original_logger_level = ultralytics_logger.level
|
| 402 |
+
ultralytics_logger.setLevel(logging.CRITICAL + 1)
|
| 403 |
+
|
| 404 |
bboxes = self.get_face_bboxes(image_rgb)
|
| 405 |
w, h = get_rgb_size(image_rgb)
|
| 406 |
|
| 407 |
+
# print(f"w, h:{w, h}")
|
| 408 |
|
| 409 |
cx = w / 2
|
| 410 |
min_diff = w
|
|
|
|
| 415 |
diff = abs(cx - (x1 + bbox_w / 2))
|
| 416 |
if diff < min_diff:
|
| 417 |
best_box = [x1, y1, x2, y2]
|
| 418 |
+
# print(f"diff, min_diff, best_box:{diff, min_diff, best_box}")
|
| 419 |
min_diff = diff
|
| 420 |
|
| 421 |
if best_box == None:
|
|
|
|
| 472 |
new_x2 -= over_min
|
| 473 |
new_y2 -= over_min
|
| 474 |
|
| 475 |
+
ultralytics_logger.setLevel(original_logger_level)
|
| 476 |
return [int(new_x1), int(new_y1), int(new_x2), int(new_y2)]
|
| 477 |
|
| 478 |
@staticmethod
|
|
|
|
| 537 |
def prepare_source(self, source_image, crop_factor, is_video=False, tracking=False):
|
| 538 |
# source_image_np = (source_image * 255).byte().numpy()
|
| 539 |
# img_rgb = source_image_np[0]
|
| 540 |
+
# print("Prepare source...")
|
| 541 |
if len(source_image.shape) <= 3:
|
| 542 |
source_image = source_image[np.newaxis, ...]
|
| 543 |
|