Add inspyrenet to easy imageRembg

This commit is contained in:
yolain
2024-07-20 21:01:56 +08:00
parent a5a118c98d
commit 1f8b19fe5e
4 changed files with 43 additions and 11 deletions
+1
View File
@@ -56,6 +56,7 @@ Double-click install.bat to install the required dependencies
**v1.2.1**
- Added **inspyrenet** to `easy imageRemBg`
- Added `easy controlnetLoader++`
- Added **PLUS (kolors genernal)** preset to `easy ipadapterApply` and `easy ipadapterApplyADV` (Supported kolors ipadapter)
- Added `easy kolorsLoader` - Code based on [MinusZoneAI](https://github.com/MinusZoneAI/ComfyUI-Kolors-MZ)'s and [kijai](https://github.com/kijai/ComfyUI-KwaiKolorsWrapper)'s repo, thanks for their contribution.
+1
View File
@@ -64,6 +64,7 @@ git clone https://github.com/yolain/ComfyUI-Easy-Use
**v1.2.1**
- `easy imageRemBg` 增加 **inspyrenet** 选项
- 增加 `easy controlnetLoader++`
- `easy ipadapterApply` 和 `easy ipadapterApplyADV` 增加 **PLUS (kolors genernal)** 预置项 (支持kolors IPA,可能会改名)
- 去除 `easy positive` `easy negative` 等prompt节点的自动将中文翻译功能,自动翻译仅在 `easy a1111Loader` 等不支持中文TE的加载器中生效
+30 -11
View File
@@ -674,9 +674,13 @@ class imageRemBg:
return {
"required": {
"images": ("IMAGE",),
"rem_mode": (("RMBG-1.4",),),
"rem_mode": (("RMBG-1.4","Inspyrenet"),),
"image_output": (["Hide", "Preview", "Save", "Hide/Save"], {"default": "Preview"}),
"save_prefix": ("STRING", {"default": "ComfyUI"}),
},
"optional":{
"torchscript_jit": ("BOOLEAN", {"default": False}),
},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
@@ -688,7 +692,9 @@ class imageRemBg:
CATEGORY = "EasyUse/Image"
def remove(self, rem_mode, images, image_output, save_prefix, prompt=None, extra_pnginfo=None):
def remove(self, rem_mode, images, image_output, save_prefix, torchscript_jit=False, prompt=None, extra_pnginfo=None):
new_images = list()
masks = list()
if rem_mode == "RMBG-1.4":
# load model
model_url = REMBG_MODELS[rem_mode]['model_url']
@@ -702,8 +708,6 @@ class imageRemBg:
net.eval()
# prepare input
model_input_size = [1024, 1024]
new_images = list()
masks = list()
for image in images:
orig_im = tensor2pil(image)
w, h = orig_im.size
@@ -721,18 +725,33 @@ class imageRemBg:
new_images = torch.cat(new_images, dim=0)
masks = torch.cat(masks, dim=0)
elif rem_mode == "Inspyrenet":
from tqdm import tqdm
try:
from transparent_background import Remover
except:
install_package("transparent_background")
from transparent_background import Remover
results = easySave(new_images, save_prefix, image_output, prompt, extra_pnginfo)
remover = Remover(jit=torchscript_jit)
if image_output in ("Hide", "Hide/Save"):
return {"ui": {},
"result": (new_images, masks)}
for img in tqdm(images, "Inspyrenet Rembg"):
mid = remover.process(tensor2pil(img), type='rgba')
out = pil2tensor(mid)
new_images.append(out)
mask = out[:, :, :, 3]
masks.append(mask)
new_images = torch.cat(new_images, dim=0)
masks = torch.cat(masks, dim=0)
return {"ui": {"images": results},
results = easySave(new_images, save_prefix, image_output, prompt, extra_pnginfo)
if image_output in ("Hide", "Hide/Save"):
return {"ui": {},
"result": (new_images, masks)}
else:
return (None, None)
return {"ui": {"images": results},
"result": (new_images, masks)}
# 图像选择器
class imageChooser(PreviewImage):
+11
View File
@@ -442,6 +442,17 @@ function widgetLogic(node, widget) {
}
updateNodeHeight(node)
}
if(widget.name == 'rem_mode'){
switch (widget.value){
case 'Inspyrenet':
toggleWidget(node, findWidgetByName(node, 'torchscript_jit'), true)
break
default:
toggleWidget(node, findWidgetByName(node, 'torchscript_jit'), false)
break
}
}
}
function widgetLogic2(node, widget) {