Spaces:
Configuration error
Configuration error
finish demo
Browse filesFiles changed (6)
- app.py+94-40
- demo/mesh_recon.py+45-12
- demo/relighting_gen.py+29-17
- demo/render_hints.py+11-8
- demo/rm_bg.py-1
- requirements.txt+6-5
1234564 unmodified lines1112131415161711 unmodified lines29303132333414 unmodified lines4950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011023 unmodified lines1061071081091101111125 unmodified lines118119120121122123124125126127128129130131132133import gradio as grimport imageioimport numpy as npfrom demo.img_gen import img_genfrom demo.mesh_recon import mesh_reconstruction4 unmodified lineswith gr.Blocks(title="DiLightNet Demo") as demo:gr.Markdown("""# DiLightNet: Fine-grained Lighting Control for Diffusion-based Image Generation## A demo for generating images under point lights using DiLightNet. For full usage, please refer to our [GitHub repository](TBD)""")with gr.Row():# 1. Reference Image Input / Generation11 unmodified lineswith gr.Row():generate_btn = gr.Button(value="Generate")generate_btn.click(fn=img_gen, inputs=[prompt, seed, steps, cfg, down_from_768], outputs=[input_image])# 2. Background Removalwith gr.Column(variant="panel"):14 unmodified lineswith gr.Accordion("Options", open=False):with gr.Group():remove_edges = gr.Checkbox(label="Remove Occlusion Edges", value=False)fov = gr.Number(value=55., label="FOV", interactive=True)mask_threshold = gr.Slider(value=25., label="Mask Threshold", minimum=0., maximum=255., step=1.)depth_estimation_btn = gr.Button(value="Estimate Depth")depth_estimation_btn.click(fn=mesh_reconstruction,inputs=[masked_image, mask, remove_edges, fov, mask_threshold],outputs=[mesh])gr.Markdown("## Step 4. Render Hints")with gr.Row():with gr.Column():hint_image = gr.Image(label="Hint Image")with gr.Column():pl_pos_x = gr.Slider(value=3., label="Point Light X", minimum=-5., maximum=5., step=0.01)pl_pos_y = gr.Slider(value=1., label="Point Light Y", minimum=-5., maximum=5., step=0.01)pl_pos_z = gr.Slider(value=3., label="Point Light Z", minimum=-5., maximum=5., step=0.01)power = gr.Slider(value=1000., label="Point Light Power", minimum=0., maximum=2000., step=1.)render_btn = gr.Button(value="Render Hints")res_folder_path = gr.Textbox("", visible=False)def render_wrapper(mesh, fov, pl_pos_x, pl_pos_y, pl_pos_z, power,progress=gr.Progress(track_tqdm=True)):res_path = render_hint_images_btn_func(mesh, fov, [(pl_pos_x, pl_pos_y, pl_pos_z)], power)hint_files = [res_path + '/hint00' + mat for mat in ["_diffuse.png", "_ggx0.34.png"]]hints = []for hint_file in hint_files:hint = imageio.v3.imread(hint_file)hints.append(hint)hints = np.concatenate(hints, axis=1)return hints, res_pathrender_btn.click(fn=render_wrapper,inputs=[mesh, fov, pl_pos_x, pl_pos_y, pl_pos_z, power],outputs=[hint_image, res_folder_path])gr.Markdown("## Step 5. Lighting Control Generation")with gr.Row():res_image = gr.Image(label="Result Image")with gr.Column():with gr.Group():relighting_prompt = gr.Textbox(value="", label="Lighting-Control Text Prompt", lines=3,placeholder="Input prompt here",interactive=True)reuse_btn = gr.Button(value="Reuse Image Generation Prompt")reuse_btn.click(fn=lambda x: x, inputs=[prompt], outputs=[relighting_prompt])with gr.Accordion("Options", open=False):with gr.Row():relighting_seed = gr.Number(value=3407, label="Seed", interactive=True)3 unmodified linesrelighting_generate_btn = gr.Button(value="Generate")def gen_relighting_image(masked_image, mask, res_folder_path, relighting_prompt, relighting_seed,relighting_steps, relighting_cfg,progress=gr.Progress(track_tqdm=True)):relighting_gen(masked_ref_img=masked_image,5 unmodified linesseed=int(relighting_seed),cfg=relighting_cfg)mask_for_bg = imageio.v3.imread(res_folder_path + '/hint00_diffuse.png')[..., -1:] / 255.res = imageio.v3.imread(res_folder_path + '/relighting00.png') / 255.res = res * mask_for_bg # + bg * (1. - mask_for_bg)res = (res * 255).clip(0, 255).astype(np.uint8)return resrelighting_generate_btn.click(fn=gen_relighting_image,inputs=[masked_image, mask, res_folder_path, relighting_prompt, relighting_seed,relighting_steps, relighting_cfg],outputs=[res_image])123456784 unmodified lines1314151617181911 unmodified lines313233343536373839404114 unmodified lines56575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521533 unmodified lines1571581591601611621635 unmodified lines169170171172173174175176177178179180181182183184185186187import gradio as grimport osimport imageioimport numpy as npfrom einops import rearrangefrom demo.img_gen import img_genfrom demo.mesh_recon import mesh_reconstruction4 unmodified lineswith gr.Blocks(title="DiLightNet Demo") as demo:gr.Markdown("""# DiLightNet: Fine-grained Lighting Control for Diffusion-based Image Generation## A demo for generating images under point/environmantal lighting using DiLightNet. For full usage (video generation & arbitary lighting condition), please refer to our [GitHub repository](https://github.com/iamNCJ/DiLightNet)""")with gr.Row():# 1. Reference Image Input / Generation11 unmodified lineswith gr.Row():generate_btn = gr.Button(value="Generate")generate_btn.click(fn=img_gen, inputs=[prompt, seed, steps, cfg, down_from_768], outputs=[input_image])gr.Examples(examples=[os.path.join("examples/provisional_img", i) for i in os.listdir("examples/provisional_img")],inputs=[input_image],examples_per_page = 20,)# 2. Background Removalwith gr.Column(variant="panel"):14 unmodified lineswith gr.Accordion("Options", open=False):with gr.Group():remove_edges = gr.Checkbox(label="Remove Occlusion Edges", value=False)fov = gr.Number(value=55., label="FOV", interactive=False)mask_threshold = gr.Slider(value=25., label="Mask Threshold", minimum=0., maximum=255., step=1.)depth_estimation_btn = gr.Button(value="Estimate Depth")def mesh_reconstruction_wrapper(image, mask, remove_edges, mask_threshold,progress=gr.Progress(track_tqdm=True)):return mesh_reconstruction(image, mask, remove_edges, None, mask_threshold)depth_estimation_btn.click(fn=mesh_reconstruction_wrapper,inputs=[input_image, mask, remove_edges, mask_threshold],outputs=[mesh, fov],)gr.Markdown("## Step 4. Render Hints")with gr.Row():with gr.Column():hint_image = gr.Image(label="Hint Image", height=512, width=512)with gr.Column():res_folder_path = gr.Textbox("", visible=False)is_env_lighting = gr.Checkbox(label="Use Environmental Lighting", value=True, interactive=False, visible=False)with gr.Tab("Environmental Lighting"):env_map_preview = gr.Image(label="Environment Map Preview", height=256, width=512, interactive=False, show_download_button=False)env_map_path = gr.Text(interactive=False, visible=False, value="examples/env_map/grace.exr")env_rotation = gr.Slider(value=0., label="Environment Rotation", minimum=0., maximum=360., step=0.5)env_examples = gr.Examples(examples=[[os.path.join("examples/env_map_preview", i), os.path.join("examples/env_map", i).replace("png", "exr")] for i in os.listdir("examples/env_map_preview")],inputs=[env_map_preview, env_map_path],examples_per_page = 20,)render_btn_env = gr.Button(value="Render Hints")def render_wrapper_env(mesh, fov, env_map_path, env_rotation, progress=gr.Progress(track_tqdm=True)):env_map_path = os.path.abspath(env_map_path)res_path = render_hint_images_btn_func(mesh, float(fov), [(0, 0, 0)], env_map=env_map_path, env_start_azi=env_rotation / 360.)hint_files = [res_path + '/hint00' + mat for mat in ["_diffuse.png", "_ggx0.05.png", "_ggx0.13.png", "_ggx0.34.png"]]hints = []for hint_file in hint_files:hint = imageio.v3.imread(hint_file)hints.append(hint)hints = rearrange(np.stack(hints), '(n1 n2) h w c -> (n1 h) (n2 w) c', n1=2, n2=2)return hints, res_path, Truerender_btn_env.click(fn=render_wrapper_env,inputs=[mesh, fov, env_map_path, env_rotation],outputs=[hint_image, res_folder_path, is_env_lighting])with gr.Tab("Point Lighting"):pl_pos_x = gr.Slider(value=3., label="Point Light X", minimum=-5., maximum=5., step=0.01)pl_pos_y = gr.Slider(value=1., label="Point Light Y", minimum=-5., maximum=5., step=0.01)pl_pos_z = gr.Slider(value=3., label="Point Light Z", minimum=-5., maximum=5., step=0.01)power = gr.Slider(value=1000., label="Point Light Power", minimum=0., maximum=2000., step=1.)render_btn_pl = gr.Button(value="Render Hints")def render_wrapper_pl(mesh, fov, pl_pos_x, pl_pos_y, pl_pos_z, power,progress=gr.Progress(track_tqdm=True)):res_path = render_hint_images_btn_func(mesh, float(fov), [(pl_pos_x, pl_pos_y, pl_pos_z)], power)hint_files = [res_path + '/hint00' + mat for mat in ["_diffuse.png", "_ggx0.05.png", "_ggx0.13.png", "_ggx0.34.png"]]hints = []for hint_file in hint_files:hint = imageio.v3.imread(hint_file)hints.append(hint)hints = rearrange(np.stack(hints), '(n1 n2) h w c -> (n1 h) (n2 w) c', n1=2, n2=2)return hints, res_path, Falserender_btn_pl.click(fn=render_wrapper_pl,inputs=[mesh, fov, pl_pos_x, pl_pos_y, pl_pos_z, power],outputs=[hint_image, res_folder_path, is_env_lighting])gr.Markdown("## Step 5. Control Lighting!")with gr.Row():res_image = gr.Image(label="Result Image")with gr.Column():with gr.Group():with gr.Row():relighting_prompt = gr.Textbox(value="", label="Appearance Text Prompt", lines=3,placeholder="Input prompt here",interactive=True)with gr.Row():# several example promptsmetallic_prompt_btn = gr.Button(value="Metallic", size="sm")specular_prompt_btn = gr.Button(value="Specular", size="sm")very_specular_prompt_btn = gr.Button(value="Very Specular", size="sm")clear_prompt_btn = gr.Button(value="Clear", size="sm")metallic_prompt_btn.click(fn=lambda x: x + " metallic", inputs=[relighting_prompt], outputs=[relighting_prompt])specular_prompt_btn.click(fn=lambda x: x + " specular", inputs=[relighting_prompt], outputs=[relighting_prompt])very_specular_prompt_btn.click(fn=lambda x: x + " very specular", inputs=[relighting_prompt], outputs=[relighting_prompt])clear_prompt_btn.click(fn=lambda x: "", inputs=[relighting_prompt], outputs=[relighting_prompt])with gr.Row():reuse_btn = gr.Button(value="Reuse Provisional Image Generation Prompt")reuse_btn.click(fn=lambda x: x, inputs=[prompt], outputs=[relighting_prompt])with gr.Accordion("Options", open=False):with gr.Row():relighting_seed = gr.Number(value=3407, label="Seed", interactive=True)3 unmodified linesrelighting_generate_btn = gr.Button(value="Generate")def gen_relighting_image(masked_image, mask, res_folder_path, relighting_prompt, relighting_seed,relighting_steps, relighting_cfg, do_env_inpainting,progress=gr.Progress(track_tqdm=True)):relighting_gen(masked_ref_img=masked_image,5 unmodified linesseed=int(relighting_seed),cfg=relighting_cfg)relit_img = imageio.v3.imread(res_folder_path + '/relighting00.png')if do_env_inpainting:bg = imageio.v3.imread(res_folder_path + f'/bg00.png') / 255.relit_img = relit_img / 255.mask_for_bg = imageio.v3.imread(res_folder_path + '/hint00_diffuse.png')[..., -1:] / 255.relit_img = relit_img * mask_for_bg + bg * (1. - mask_for_bg)relit_img = (relit_img * 255).clip(0, 255).astype(np.uint8)return relit_imgrelighting_generate_btn.click(fn=gen_relighting_image,inputs=[masked_image, mask, res_folder_path, relighting_prompt, relighting_seed,relighting_steps, relighting_cfg, is_env_lighting],outputs=[res_image])
12345678910111213141516171887 unmodified lines10610710810911011111211311411511611711811912 unmodified lines132133134135import tempfileimport numpy as npimport torchimport trimeshimport spacesdevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')# use torch hub# zeroGPU hack from https://huggingface.co/spaces/zero-gpu-explorers/README/discussions/9torch.jit.script = lambda f: fmodel = torch.hub.load("isl-org/ZoeDepth", "ZoeD_NK", pretrained=True).to(device).eval()def get_intrinsics(H, W, fov=55.):87 unmodified linesmasked_image: np.ndarray,mask: np.ndarray,remove_edges: bool = True,fov: float = 55.,mask_threshold: float = 25.,):rgb = masked_image[..., :3].transpose(2, 0, 1) / 255.sample = torch.from_numpy(rgb).to(device).unsqueeze(0).float()with torch.no_grad():depth = model.infer(sample)depth = depth.squeeze().cpu().numpy()pts3d = depth_to_points(depth[None], fov=fov)pts3d = pts3d.reshape(-1, 3)12 unmodified linesmesh_file = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)mesh_file_path = mesh_file.namemesh.export(mesh_file_path)return mesh_file_path12345678910111213141516171819202122232425262728293031323334353687 unmodified lines12412512612712812913013113213313413513613713813914014114214314414514614714814915015115212 unmodified lines165166167168import tempfilefrom typing import Optionalimport numpy as npimport cv2import torchimport trimeshimport spacesfrom dust3r.model import AsymmetricCroCo3DStereofrom dust3r.cloud_opt import global_aligner, GlobalAlignerModefrom dust3r.inference import inferencefrom dust3r.image_pairs import make_pairsdevice = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')model = AsymmetricCroCo3DStereo.from_pretrained("naver/DUSt3R_ViTLarge_BaseDecoder_512_dpt").to(device).eval()import torchvision.transforms as tvfimport PIL.Imageimport numpy as npImgNorm = tvf.Compose([tvf.ToTensor(), tvf.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])def load_single_image(img_array):imgs = []for i in range(2):img = PIL.Image.fromarray(img_array)imgs.append(dict(img=ImgNorm(img)[None], true_shape=np.int32([img.size[::-1]]), idx=i, instance=str(len(imgs))))return imgsdef get_intrinsics(H, W, fov=55.):87 unmodified linesmasked_image: np.ndarray,mask: np.ndarray,remove_edges: bool = True,fov: Optional[float] = None,mask_threshold: float = 25.,):masked_image = cv2.resize(masked_image, (512, 512))mask = cv2.resize(mask, (512, 512))images = load_single_image(masked_image)pairs = make_pairs(images, scene_graph='complete', prefilter=None, symmetrize=True)output = inference(pairs, model, device, batch_size=1)scene = global_aligner(output, device=device, mode=GlobalAlignerMode.PointCloudOptimizer)if fov is not None:# do not optimize focal length if fov is providedfocal = scene.imshapes[0][1] / (2 * np.tan(0.5 * fov * np.pi / 180.))scene.preset_focal([focal, focal])_loss = scene.compute_global_alignment(init='mst', niter=300, schedule='cosine', lr=0.01)if fov is None:# get the focal length from the optimized parametersfocals = scene.get_focals()fov = 2 * (np.arctan((scene.imshapes[0][1] / (focals[0] + focals[1])).detach().cpu().numpy()) * 180 / np.pi)[0]depth = scene.get_depthmaps()[0].detach().cpu().numpy()if device.type == 'cuda':torch.cuda.empty_cache()rgb = masked_image[..., :3].transpose(2, 0, 1) / 255.pts3d = depth_to_points(depth[None], fov=fov)pts3d = pts3d.reshape(-1, 3)12 unmodified linesmesh_file = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)mesh_file_path = mesh_file.namemesh.export(mesh_file_path)return mesh_file_path, fov
1 unmodified line234567810 unmodified lines192021222324252627282930313233343536373839404142434445464748495051525354551 unmodified lineimport numpy as npimport spacesimport torchfrom diffusers import UniPCMultistepScheduler, StableDiffusionControlNetPipelinefrom diffusers.utils import get_class_from_dynamic_modulefrom tqdm import tqdm10 unmodified lines"NeuralTextureControlNetModel")controlnet = NeuralTextureControlNetModel.from_pretrained("dilightnet/DiLightNet",torch_dtype=dtype,)pipe = StableDiffusionControlNetPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", controlnet=controlnet, torch_dtype=dtype).to(device)pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)pipe.set_progress_bar_config(disable=True)@spaces.GPUdef relighting_gen(masked_ref_img, mask, cond_path, frames, prompt, steps, seed, cfg):mask = mask[..., :1] / 255.for i in tqdm(range(frames)):source_image = masked_ref_img[..., :3] / 255.cond_diffuse = imageio.v3.imread(f'{cond_path}/hint{i:02d}_diffuse.png') / 255.if cond_diffuse.shape[-1] == 4:cond_diffuse = cond_diffuse[..., :3] * cond_diffuse[..., 3:]cond_ggx034 = imageio.v3.imread(f'{cond_path}/hint{i:02d}_ggx0.34.png') / 255.if cond_ggx034.shape[-1] == 4:cond_ggx034 = cond_ggx034[..., :3] * cond_ggx034[..., 3:]cond_ggx013 = imageio.v3.imread(f'{cond_path}/hint{i:02d}_ggx0.13.png') / 255.if cond_ggx013.shape[-1] == 4:cond_ggx013 = cond_ggx013[..., :3] * cond_ggx013[..., 3:]cond_ggx005 = imageio.v3.imread(f'{cond_path}/hint{i:02d}_ggx0.05.png') / 255.if cond_ggx005.shape[-1] == 4:cond_ggx005 = cond_ggx005[..., :3] * cond_ggx005[..., 3:]hint = np.concatenate([mask, source_image, cond_diffuse, cond_ggx005, cond_ggx013, cond_ggx034], axis=2).astype(np.float32)[None]hint = torch.from_numpy(hint).to(dtype).permute(0, 3, 1, 2).to(device)generator = torch.manual_seed(seed)image = pipe(prompt, num_inference_steps=steps, generator=generator, image=hint, num_images_per_prompt=1, guidance_scale=cfg, output_type='np',).images[0] # [H, W, C]imageio.imwrite(f'{cond_path}/relighting{i:02d}.png', (image * 255).clip(0, 255).astype(np.uint8))1 unmodified line234567810 unmodified lines192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566671 unmodified lineimport numpy as npimport spacesimport torchfrom diffusers import UniPCMultistepScheduler, StableDiffusionControlNetPipeline, StableDiffusionInpaintPipeline, ConsistencyDecoderVAEfrom diffusers.utils import get_class_from_dynamic_modulefrom tqdm import tqdm10 unmodified lines"NeuralTextureControlNetModel")controlnet = NeuralTextureControlNetModel.from_pretrained("DiLightNet/DiLightNet",torch_dtype=dtype,)vae = ConsistencyDecoderVAE.from_pretrained("openai/consistency-decoder", torch_dtype=dtype)pipe = StableDiffusionControlNetPipeline.from_pretrained("stabilityai/stable-diffusion-2-1",vae=vae,controlnet=controlnet,torch_dtype=dtype).to(device)pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)pipe.set_progress_bar_config(disable=True)inpainting_pipe = StableDiffusionInpaintPipeline.from_pretrained("stabilityai/stable-diffusion-2-inpainting",torch_dtype=dtype).to(device)inpainting_pipe.set_progress_bar_config(disable=True)@spaces.GPUdef relighting_gen(masked_ref_img, mask, cond_path, frames, prompt, steps, seed, cfg, inpaint=False):mask = mask[..., :1] / 255.for i in tqdm(range(frames)):source_image = masked_ref_img[..., :3] / 255.hint_types = ['diffuse', 'ggx0.05', 'ggx0.13', 'ggx0.34']images = [mask, source_image]for hint_type in hint_types:image_path = f'{cond_path}/hint{i:02d}_{hint_type}.png'image = imageio.v3.imread(image_path) / 255.if image.shape[-1] == 4: # Check if the image has an alpha channelimage = image[..., :3] * image[..., 3:] # Premultiply RGB by Alphaimages.append(image)hint = np.concatenate(images, axis=2).astype(np.float32)[None]hint = torch.from_numpy(hint).to(dtype).permute(0, 3, 1, 2).to(device)generator = torch.manual_seed(seed)image = pipe(prompt, num_inference_steps=steps, generator=generator, image=hint, num_images_per_prompt=1, guidance_scale=cfg, output_type='np',).images[0] # [H, W, C]if inpaint:mask_image = (1. - mask)[None]image = inpainting_pipe(prompt=prompt, image=image[None], mask_image=mask_image, generator=generator, output_type='np', cfg=3.0, strength=1.0).images[0]imageio.imwrite(f'{cond_path}/relighting{i:02d}.png', (image * 255).clip(0, 255).astype(np.uint8))
6 unmodified lines7891011121359 unmodified lines737475767778795 unmodified lines8586878889909134 unmodified lines1261271281291301311322 unmodified lines1351361371381391401411421431441451461471481491506 unmodified linesdef render_hint_images(model_path, fov, pls, power=500., geo_smooth=True, output_folder: Optional[str] = None,env_map: Optional[str] = None, resolution=512, use_gpu=False):import bpyimport numpy as np59 unmodified linesoutput_folder = tempfile.mkdtemp()for i in tqdm(range(len(pls)), desc='Rendering Hints'):if env_map:z_angle = i / len(pls) * np.pi * 2.set_env_light(env_map, rotation_euler=[0, 0, z_angle])else:pl_pos = pls[i]5 unmodified linesreturn output_folderdef render_bg_images(fov, pls, output_folder: Optional[str] = None, env_map: Optional[str] = None, resolution=512):import bpyimport numpy as np34 unmodified linesif output_folder is None:output_folder = tempfile.mkdtemp()for i in tqdm(range(len(pls)), desc='Rendering Env Backgrounds'):z_angle = i / len(pls) * np.pi * 2.set_env_light(env_map, rotation_euler=[0, 0, z_angle])with stdout_redirected():2 unmodified linesreturn output_folderdef render_hint_images_wrapper(model_path, fov, pls, power, geo_smooth, output_folder, env_map, resolution, return_dict):output_folder = render_hint_images(model_path, fov, pls, power, geo_smooth, output_folder, env_map, resolution)return_dict['output_folder'] = output_folderdef render_hint_images_btn_func(model_path, fov, pls, power=500., geo_smooth=True, output_folder: Optional[str] = None,env_map: Optional[str] = None, resolution=512):manager = multiprocessing.Manager()return_dict = manager.dict()p = Process(target=render_hint_images_wrapper, args=(model_path, fov, pls, power, geo_smooth, output_folder, env_map, resolution, return_dict))p.start()p.join()return return_dict['output_folder']6 unmodified lines7891011121359 unmodified lines737475767778795 unmodified lines8586878889909134 unmodified lines1261271281291301311322 unmodified lines1351361371381391401411421431441451461471481491501511521536 unmodified linesdef render_hint_images(model_path, fov, pls, power=500., geo_smooth=True, output_folder: Optional[str] = None,env_map: Optional[str] = None, env_start_azi=0., resolution=512, use_gpu=False):import bpyimport numpy as np59 unmodified linesoutput_folder = tempfile.mkdtemp()for i in tqdm(range(len(pls)), desc='Rendering Hints'):if env_map:z_angle = (i / len(pls) + env_start_azi) * np.pi * 2.set_env_light(env_map, rotation_euler=[0, 0, z_angle])else:pl_pos = pls[i]5 unmodified linesreturn output_folderdef render_bg_images(fov, pls, output_folder: Optional[str] = None, env_map: Optional[str] = None, env_start_azi=0., resolution=512):import bpyimport numpy as np34 unmodified linesif output_folder is None:output_folder = tempfile.mkdtemp()for i in tqdm(range(len(pls)), desc='Rendering Env Backgrounds'):z_angle = (i / len(pls) + env_start_azi) * np.pi * 2.set_env_light(env_map, rotation_euler=[0, 0, z_angle])with stdout_redirected():2 unmodified linesreturn output_folderdef render_hint_images_wrapper(model_path, fov, pls, power, geo_smooth, output_folder, env_map, env_start_azi, resolution, return_dict):output_folder = render_hint_images(model_path, fov, pls, power, geo_smooth, output_folder, env_map, env_start_azi, resolution)if env_map is not None:bg_output_folder = render_bg_images(fov, pls, output_folder, env_map, env_start_azi, resolution)return_dict['bg_output_folder'] = bg_output_folderreturn_dict['output_folder'] = output_folderdef render_hint_images_btn_func(model_path, fov, pls, power=500., geo_smooth=True, output_folder: Optional[str] = None,env_map: Optional[str] = None, env_start_azi=0., resolution=512):manager = multiprocessing.Manager()return_dict = manager.dict()p = Process(target=render_hint_images_wrapper, args=(model_path, fov, pls, power, geo_smooth, output_folder, env_map, env_start_azi, resolution, return_dict))p.start()p.join()return return_dict['output_folder']
7 unmodified lines8910111213147 unmodified linesimg = img.resize((512, 512))output = rembg.remove(img)mask = np.array(output)[:, :, 3]print(mask.shape)# use sam for mask refinementif use_sam:7 unmodified lines89101112137 unmodified linesimg = img.resize((512, 512))output = rembg.remove(img)mask = np.array(output)[:, :, 3]# use sam for mask refinementif use_sam:
1234567891011121314151617numpy==1.26.4scipy==1.13.0diffusers==0.27.2transformers==4.39.3accelerate==0.29.3timm==0.6.12 # must use this version, required by MiDaSrembg==2.0.56trimesh==4.3.1opencv-contrib-python==4.9.0.80tqdm==4.66.2bpy==3.6.0bpy-helper==0.0.0gradio==4.27.0einops==0.7.0imageio[ffmpeg]==2.34.0torch==2.0.1torchvision==0.15.2123456789101112131415161718numpy==1.26.4scipy==1.13.0diffusers==0.29.1transformers==4.41.2accelerate==0.29.3rembg==2.0.56trimesh==4.3.1opencv-contrib-python==4.9.0.80tqdm==4.66.2bpy==3.6.0bpy-helper==0.0.1gradio==4.36.1einops==0.7.0imageio[ffmpeg]==2.34.0torch==2.0.1torchvision==0.15.2git+https://github.com/naver/croco/#subdirectory=models/curopegit+https://github.com/iamNCJ/dust3r.git
app.py+94-40
demo/mesh_recon.py+45-12
demo/relighting_gen.py+29-17
demo/render_hints.py+11-8
demo/rm_bg.py-1
requirements.txt+6-5