More progressbars, update example

This commit is contained in:
kijai 2025-01-22 12:38:32 +02:00
parent 1ec0914967
commit d9b467d466
2 changed files with 97 additions and 82 deletions

View File

@ -1,6 +1,6 @@
{ {
"last_node_id": 60, "last_node_id": 60,
"last_link_id": 90, "last_link_id": 91,
"nodes": [ "nodes": [
{ {
"id": 13, "id": 13,
@ -277,7 +277,7 @@
"inputs": [], "inputs": [],
"outputs": [ "outputs": [
{ {
"name": "delight_model", "name": "delight_pipe",
"type": "DELIGHTMODEL", "type": "DELIGHTMODEL",
"links": [ "links": [
30 30
@ -386,7 +386,7 @@
"inputs": [], "inputs": [],
"outputs": [ "outputs": [
{ {
"name": "multiview_model", "name": "multiview_pipe",
"type": "HY3DPAINTMODEL", "type": "HY3DPAINTMODEL",
"links": [ "links": [
40 40
@ -401,60 +401,6 @@
"hunyuan3d-paint-v2-0" "hunyuan3d-paint-v2-0"
] ]
}, },
{
"id": 52,
"type": "ImageResize+",
"pos": [
-668.4475708007812,
-291.98388671875
],
"size": [
315,
218
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 69
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
75,
83
],
"slot_index": 0
},
{
"name": "width",
"type": "INT",
"links": null
},
{
"name": "height",
"type": "INT",
"links": null
}
],
"properties": {
"Node name for S&R": "ImageResize+"
},
"widgets_values": [
512,
512,
"lanczos",
"pad",
"always",
0
]
},
{ {
"id": 60, "id": 60,
"type": "ImageResize+", "type": "ImageResize+",
@ -774,9 +720,7 @@
{ {
"name": "IMAGE", "name": "IMAGE",
"type": "IMAGE", "type": "IMAGE",
"links": [ "links": [],
78
],
"slot_index": 0 "slot_index": 0
}, },
{ {
@ -852,7 +796,7 @@
{ {
"name": "source", "name": "source",
"type": "IMAGE", "type": "IMAGE",
"link": 78 "link": 91
}, },
{ {
"name": "mask", "name": "mask",
@ -948,6 +892,61 @@
75, 75,
null null
] ]
},
{
"id": 52,
"type": "ImageResize+",
"pos": [
-668.4475708007812,
-291.98388671875
],
"size": [
315,
218
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 69
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
75,
83,
91
],
"slot_index": 0
},
{
"name": "width",
"type": "INT",
"links": null
},
{
"name": "height",
"type": "INT",
"links": null
}
],
"properties": {
"Node name for S&R": "ImageResize+"
},
"widgets_values": [
512,
512,
"lanczos",
"pad",
"always",
0
]
} }
], ],
"links": [ "links": [
@ -1071,14 +1070,6 @@
0, 0,
"IMAGE" "IMAGE"
], ],
[
78,
56,
0,
57,
1,
"IMAGE"
],
[ [
79, 79,
56, 56,
@ -1158,6 +1149,14 @@
42, 42,
0, 0,
"IMAGE" "IMAGE"
],
[
91,
52,
0,
57,
1,
"IMAGE"
] ]
], ],
"groups": [ "groups": [
@ -1204,16 +1203,16 @@
"config": {}, "config": {},
"extra": { "extra": {
"ds": { "ds": {
"scale": 0.5054470284993025, "scale": 0.5559917313492327,
"offset": [ "offset": [
1409.3260143727844, 1771.1866402657352,
532.4019697620178 777.3248184126946
] ]
}, },
"node_versions": { "node_versions": {
"comfy-core": "0.3.12", "comfy-core": "0.3.12",
"ComfyUI-Hunyuan3DWrapper": "75ad5e41eb32f771e7a88dd9db50a004c98b3832", "ComfyUI-Hunyuan3DWrapper": "1ec09149678bc9064c22c5f71d05a8526b6063b8",
"ComfyUI_essentials": "60acb955712ae84959873012a8d9bbfc230499b7" "ComfyUI_essentials": "76e9d1e4399bd025ce8b12c290753d58f9f53e93"
}, },
"VHS_latentpreview": true, "VHS_latentpreview": true,
"VHS_latentpreviewrate": 0 "VHS_latentpreviewrate": 0

View File

@ -9,12 +9,24 @@ from .hy3dgen.shapegen import Hunyuan3DDiTFlowMatchingPipeline, FaceReducer, Flo
import folder_paths import folder_paths
import comfy.model_management as mm import comfy.model_management as mm
from comfy.utils import load_torch_file from comfy.utils import load_torch_file, ProgressBar
script_directory = os.path.dirname(os.path.abspath(__file__)) script_directory = os.path.dirname(os.path.abspath(__file__))
from .utils import log, print_memory from .utils import log, print_memory
class ComfyProgressCallback:
def __init__(self, total_steps):
self.pbar = ProgressBar(total_steps)
def __call__(self, pipe, i, t, callback_kwargs):
self.pbar.update(1)
return {
"latents": callback_kwargs["latents"],
"prompt_embeds": callback_kwargs["prompt_embeds"],
"negative_prompt_embeds": callback_kwargs["negative_prompt_embeds"]
}
class Hy3DTorchCompileSettings: class Hy3DTorchCompileSettings:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
@ -92,7 +104,7 @@ class DownloadAndLoadHy3DDelightModel:
} }
RETURN_TYPES = ("DELIGHTMODEL",) RETURN_TYPES = ("DELIGHTMODEL",)
RETURN_NAMES = ("delight_model", ) RETURN_NAMES = ("delight_pipe", )
FUNCTION = "loadmodel" FUNCTION = "loadmodel"
CATEGORY = "Hunyuan3DWrapper" CATEGORY = "Hunyuan3DWrapper"
@ -154,8 +166,6 @@ class Hy3DDelightImage:
image = image.permute(0, 3, 1, 2).to(device) image = image.permute(0, 3, 1, 2).to(device)
#delight_pipe = delight_pipe.to(device)
image = delight_pipe( image = delight_pipe(
prompt="", prompt="",
image=image, image=image,
@ -165,11 +175,10 @@ class Hy3DDelightImage:
num_inference_steps=steps, num_inference_steps=steps,
image_guidance_scale=cfg_image, image_guidance_scale=cfg_image,
guidance_scale=cfg_text, guidance_scale=cfg_text,
output_type="pt" output_type="pt",
).images[0] ).images[0]
#delight_pipe = delight_pipe.to(offload_device)
out_tensor = image.unsqueeze(0).permute(0, 2, 3, 1).cpu().float() out_tensor = image.unsqueeze(0).permute(0, 2, 3, 1).cpu().float()
return (out_tensor, ) return (out_tensor, )
@ -184,7 +193,7 @@ class DownloadAndLoadHy3DPaintModel:
} }
RETURN_TYPES = ("HY3DPAINTMODEL",) RETURN_TYPES = ("HY3DPAINTMODEL",)
RETURN_NAMES = ("multiview_model", ) RETURN_NAMES = ("multiview_pipe", )
FUNCTION = "loadmodel" FUNCTION = "loadmodel"
CATEGORY = "Hunyuan3DWrapper" CATEGORY = "Hunyuan3DWrapper"
@ -287,6 +296,8 @@ class Hy3DRenderMultiView:
#pipeline = pipeline.to(device) #pipeline = pipeline.to(device)
callback = ComfyProgressCallback(total_steps=steps)
multiview_images = pipeline( multiview_images = pipeline(
input_image, input_image,
width=view_size, width=view_size,
@ -299,6 +310,9 @@ class Hy3DRenderMultiView:
position_imgs = position_image, position_imgs = position_image,
num_inference_steps=steps, num_inference_steps=steps,
output_type="pt", output_type="pt",
callback_on_step_end=callback,
callback_on_step_end_tensor_inputs=["latents", "prompt_embeds", "negative_prompt_embeds"]
).images ).images
#pipeline = pipeline.to(offload_device) #pipeline = pipeline.to(offload_device)
@ -373,6 +387,7 @@ class Hy3DBakeFromMultiview:
camera_azims, view_weights, method='graphcut'): camera_azims, view_weights, method='graphcut'):
project_textures, project_weighted_cos_maps = [], [] project_textures, project_weighted_cos_maps = [], []
project_boundary_maps = [] project_boundary_maps = []
pbar = ProgressBar(len(views))
for view, camera_elev, camera_azim, weight in zip( for view, camera_elev, camera_azim, weight in zip(
views, camera_elevs, camera_azims, view_weights): views, camera_elevs, camera_azims, view_weights):
project_texture, project_cos_map, project_boundary_map = self.render.back_project( project_texture, project_cos_map, project_boundary_map = self.render.back_project(
@ -381,6 +396,7 @@ class Hy3DBakeFromMultiview:
project_textures.append(project_texture) project_textures.append(project_texture)
project_weighted_cos_maps.append(project_cos_map) project_weighted_cos_maps.append(project_cos_map)
project_boundary_maps.append(project_boundary_map) project_boundary_maps.append(project_boundary_map)
pbar.update(1)
if method == 'fast': if method == 'fast':
texture, ori_trust_map = self.render.fast_bake_texture( texture, ori_trust_map = self.render.fast_bake_texture(