Skip to content

Commit

Permalink
BiRefNetUltraV2 node add process bar
Browse files Browse the repository at this point in the history
  • Loading branch information
chflame163 committed Sep 5, 2024
1 parent 308d705 commit 4c70935
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions py/birefnet_ultra_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import sys
import torch
from torchvision import transforms
import tqdm
from .imagefunc import *
from comfy.utils import ProgressBar
sys.path.append(os.path.join(os.path.dirname(__file__), 'BiRefNet'))
from .BiRefNet.models.birefnet import BiRefNet

Expand Down Expand Up @@ -95,7 +97,8 @@ def birefnet_ultra_v2(self, image, birefnet_model, detail_method, detail_erode,
birefnet_model.to(device)
birefnet_model.eval()


comfy_pbar = ProgressBar(len(image))
tqdm_pbar = tqdm(total=len(image), desc="Processing BiRefNet")
for i in image:
i = torch.unsqueeze(i, 0)
orig_image = tensor2pil(i).convert('RGB')
Expand All @@ -114,7 +117,7 @@ def birefnet_ultra_v2(self, image, birefnet_model, detail_method, detail_erode,
pred = preds[0].squeeze()
pred_pil = transforms.ToPILImage()(pred)
_mask = pred_pil.resize(inference_image_size)
print(f"_mask type is = {type(_mask)}, mode = {_mask.mode}, size={_mask.size}")

resize_sampler = Image.BILINEAR
_mask = _mask.resize(orig_image.size, resize_sampler)
brightness_image = ImageEnhance.Brightness(_mask)
Expand All @@ -140,6 +143,9 @@ def birefnet_ultra_v2(self, image, birefnet_model, detail_method, detail_erode,
ret_images.append(pil2tensor(ret_image))
ret_masks.append(image2mask(_mask))

comfy_pbar.update(1)
tqdm_pbar.update(1)

log(f"{self.NODE_NAME} Processed {len(ret_masks)} image(s).", message_type='finish')
return (torch.cat(ret_images, dim=0), torch.cat(ret_masks, dim=0),)

Expand Down

0 comments on commit 4c70935

Please sign in to comment.