ImageScaleByAspectRatio node add 'original' ratio mode

This commit is contained in:
chflame163
2024-02-20 14:21:55 +08:00
parent fc93c846a4
commit bc387a18dd
4 changed files with 21 additions and 7 deletions
+3 -2
View File
@@ -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:
+5 -2
View File
@@ -653,8 +653,11 @@
### <a id="table1">RemBgUltra</a>
去除背景。与类似的背景移除节点相比,这个节点具有超高的边缘细节。
本节点结合了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)
+4 -2
View File
@@ -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(":")
+9 -1
View File
@@ -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()