From c86596d60434cf343aa2cc4f38b9b6e67b3a4809 Mon Sep 17 00:00:00 2001 From: shaoxinheng Date: Thu, 12 Oct 2023 20:27:21 +0800 Subject: [PATCH 1/3] up --- facelib/detection/retinaface/retinaface.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/facelib/detection/retinaface/retinaface.py b/facelib/detection/retinaface/retinaface.py index dd728bb..e37e5b3 100644 --- a/facelib/detection/retinaface/retinaface.py +++ b/facelib/detection/retinaface/retinaface.py @@ -5,13 +5,15 @@ import torch.nn as nn import torch.nn.functional as F from PIL import Image from torchvision.models._utils import IntermediateLayerGetter as IntermediateLayerGetter - +from comfy import model_management from custom_nodes.facerestore_cf.facelib.detection.align_trans import get_reference_facial_points, warp_and_crop_face from custom_nodes.facerestore_cf.facelib.detection.retinaface.retinaface_net import FPN, SSH, MobileNetV1, make_bbox_head, make_class_head, make_landmark_head from custom_nodes.facerestore_cf.facelib.detection.retinaface.retinaface_utils import (PriorBox, batched_decode, batched_decode_landm, decode, decode_landm, py_cpu_nms) -device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') +# device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') +device = model_management.get_torch_device() + def generate_config(network_name): From 45ebbe5eb018da67c517eb201433f5d1b996eaa1 Mon Sep 17 00:00:00 2001 From: Momilijaz96 Date: Thu, 19 Oct 2023 08:12:23 +0000 Subject: [PATCH 2/3] Make facedetection models load from comfyui models --- __init__.py | 5 +++-- facelib/detection/yolov5face/face_detector.py | 2 +- facelib/utils/misc.py | 7 +++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/__init__.py b/__init__.py index f88b18a..dda039b 100644 --- a/__init__.py +++ b/__init__.py @@ -15,10 +15,11 @@ from custom_nodes.facerestore_cf.basicsr.utils.registry import ARCH_REGISTRY # import codeformer_arch dir_facerestore_models = os.path.join(folder_paths.models_dir, "facerestore_models") -dir_facedetection = os.path.join(folder_paths.models_dir, "facedetection") +dir_facedetection_models = os.path.join(folder_paths.models_dir, "facedetection") os.makedirs(dir_facerestore_models, exist_ok=True) -os.makedirs(dir_facedetection, exist_ok=True) +os.makedirs(dir_facedetection_models, exist_ok=True) folder_paths.folder_names_and_paths["facerestore_models"] = ([dir_facerestore_models], folder_paths.supported_pt_extensions) +folder_paths.folder_names_and_paths["facedetection_models"] = ([dir_facedetection_models], folder_paths.supported_pt_extensions) def img2tensor(imgs, bgr2rgb=True, float32=True): """Numpy array to tensor. diff --git a/facelib/detection/yolov5face/face_detector.py b/facelib/detection/yolov5face/face_detector.py index 693e345..3d54587 100644 --- a/facelib/detection/yolov5face/face_detector.py +++ b/facelib/detection/yolov5face/face_detector.py @@ -17,7 +17,7 @@ from custom_nodes.facerestore_cf.facelib.detection.yolov5face.utils.general impo scale_coords_landmarks, ) -IS_HIGH_VERSION = tuple(map(int, torch.__version__.split('+')[0].split('.'))) >= (1, 9, 0) +IS_HIGH_VERSION = True def isListempty(inList): diff --git a/facelib/utils/misc.py b/facelib/utils/misc.py index 7b0de18..02e8ec0 100644 --- a/facelib/utils/misc.py +++ b/facelib/utils/misc.py @@ -4,6 +4,8 @@ import os.path as osp import torch from torch.hub import download_url_to_file, get_dir from urllib.parse import urlparse +import folder_paths + # from custom_nodes.facerestore_cf.basicsr.utils.download_util import download_file_from_google_drive #import gdown @@ -96,6 +98,11 @@ def load_file_from_url(url, model_dir=None, progress=True, file_name=None): filename = os.path.basename(parts.path) if file_name is not None: filename = file_name + + model_path = folder_paths.get_full_path("facedetection_models", filename) + if model_path: + return model_path + cached_file = os.path.abspath(os.path.join(ROOT_DIR, model_dir, filename)) if not os.path.exists(cached_file): print(f'Downloading: "{url}" to {cached_file}\n') From 827ce1e9dfba14cc63ce9b3b193a5fab09a4e682 Mon Sep 17 00:00:00 2001 From: SameetAsadullah Date: Thu, 19 Oct 2023 09:50:12 +0000 Subject: [PATCH 3/3] Fix torch version checking --- facelib/detection/yolov5face/face_detector.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/facelib/detection/yolov5face/face_detector.py b/facelib/detection/yolov5face/face_detector.py index 3d54587..ff486be 100644 --- a/facelib/detection/yolov5face/face_detector.py +++ b/facelib/detection/yolov5face/face_detector.py @@ -17,7 +17,9 @@ from custom_nodes.facerestore_cf.facelib.detection.yolov5face.utils.general impo scale_coords_landmarks, ) -IS_HIGH_VERSION = True +from torch import torch_version + +IS_HIGH_VERSION = torch_version.__version__ >= "1.9.0" def isListempty(inList):