diff --git a/README.MD b/README.MD index 3d55f42..3580e1e 100644 --- a/README.MD +++ b/README.MD @@ -667,8 +667,9 @@ Remove background. compared to the similar background removal nodes, this node h This node combines the Alpha Matte node of Spacepxl's [ComfyUI-Image-Filters](https://github.com/spacepxl/ComfyUI-Image-Filters) and the functionality of ZHO-ZHO-ZHO's [ComfyUI-BRIA_AI-RMBG](https://github.com/ZHO-ZHO-ZHO/ComfyUI-BRIA_AI-RMBG). -*Download the [BRIA Background Removal v1.4](https://huggingface.co/briaai/RMBG-1.4) model file (model. pth) to the /ComfyUI/models/RMBG-1.4 folder. -This model was developed by BRIA AI and can be used as an open-source model for non-commercial purposes. +*Download the [BRIA Background Removal v1.4](https://huggingface.co/briaai/RMBG-1.4) model file (model. pth) to the /ComfyUI/models/RMBG-1.4 folder. This model was developed by BRIA AI and can be used as an open-source model for non-commercial purposes. +**After downloading the model, recommended to add a line 'rmbg: models/RMBG-1.4' in ComfyUI/extra_model_paths.yaml. (This step is not mandatory) + ![image](image/rembg_ultra_example.png) Node options: diff --git a/README_CN.MD b/README_CN.MD index 7412834..634a42a 100644 --- a/README_CN.MD +++ b/README_CN.MD @@ -653,8 +653,11 @@ ### RemBgUltra 去除背景。与类似的背景移除节点相比,这个节点具有超高的边缘细节。 本节点结合了spacepxl的[ComfyUI-Image-Filters](https://github.com/spacepxl/ComfyUI-Image-Filters)的Alpha Matte节点,以及ZHO-ZHO-ZHO的[ComfyUI-BRIA_AI-RMBG](https://github.com/ZHO-ZHO-ZHO/ComfyUI-BRIA_AI-RMBG)的功能。 -*将[BRIA Background Removal v1.4](https://huggingface.co/briaai/RMBG-1.4)模型文件(model.pth)下载至/ComfyUI/models/RMBG-1.4文件夹。 -该模型由 BRIA AI 开发,可作为非商业用途的开源模型。 + +*将[BRIA Background Removal v1.4](https://huggingface.co/briaai/RMBG-1.4)模型文件(model.pth)下载至/ComfyUI/models/RMBG-1.4文件夹。该模型由 BRIA AI 开发,可作为非商业用途的开源模型。 + +**下载模型后,建议在ComfyUI/extra_model_paths.yaml中添加一行'rmbg: models/RMBG-1.4'。(此步骤非必须) + ![image](image/rembg_ultra_example.png) diff --git a/py/image_scale_by_aspect_ratio.py b/py/image_scale_by_aspect_ratio.py index 8401c18..155dea7 100644 --- a/py/image_scale_by_aspect_ratio.py +++ b/py/image_scale_by_aspect_ratio.py @@ -11,7 +11,7 @@ class ImageScaleByAspectRatio: @classmethod def INPUT_TYPES(self): - ratio_list = ['custom', '1:1', '3:2', '4:3', '16:9', '2:3', '3:4', '9:16'] + ratio_list = ['original', 'custom', '1:1', '3:2', '4:3', '16:9', '2:3', '3:4', '9:16'] fit_mode = ['letterbox', 'crop', 'fill'] method_mode = ['lanczos', 'bicubic', 'hamming', 'bilinear', 'box', 'nearest'] multiple_list = ['8', '16', 'None'] @@ -75,7 +75,9 @@ class ImageScaleByAspectRatio: log(f"Error: {NODE_NAME} skipped, because the image or mask at least one must be input.", message_type='error') return (None, None,) - if aspect_ratio == 'custom': + if aspect_ratio == 'original': + ratio = orig_width / orig_height + elif aspect_ratio == 'custom': ratio = proportional_width / proportional_height else: s = aspect_ratio.split(":") diff --git a/py/imagefunc.py b/py/imagefunc.py index 6224dd7..cfdf48b 100644 --- a/py/imagefunc.py +++ b/py/imagefunc.py @@ -683,10 +683,18 @@ def load_RMBG_model(): current_directory = os.path.dirname(os.path.abspath(__file__)) device = "cuda" if torch.cuda.is_available() else "cpu" net = BriaRMBG() + _path = os.path.join("RMBG-1.4", "model.pth") - model_path = os.path.join(folder_paths.models_dir, _path) + model_path = "" + try: + model_path = os.path.join(os.path.normpath(folder_paths.folder_names_and_paths['rmbg'][0][0]), "model.pth") + except: + pass + if not os.path.exists(model_path): + model_path = os.path.join(folder_paths.models_dir, _path) if not os.path.exists(model_path): model_path = os.path.join(os.path.dirname(current_directory), _path) + net.load_state_dict(torch.load(model_path, map_location=device)) net.to(device) net.eval()