Spaces:
Configuration error
Configuration error
add some more prov imgs
Browse filesFiles changed (21)
- app.py+10-8
- demo/relighting_gen.py+9-12
- demo/render_hints.py+10-1
- examples/provisional_img/3d-animation-character-minimal-art-toy.pngAdded
- examples/provisional_img/a-decorated-plaster-round-plate-with-blue-fine-silk-ribbon-around-it-0.pngAdded
- examples/provisional_img/a-decorated-plaster-round-plate-with-blue-fine-silk-ribbon-around-it-1.pngAdded
- examples/provisional_img/a-large-colorful-candle-high-quality-product-photo.pngAdded
- examples/provisional_img/an-elephant-sculpted-from-plaster-and-the-elephant-nose-is-decorated-with-the-golden-texture.pngAdded
- examples/provisional_img/girraffe_turtle.jpegAdded
- examples/provisional_img/gorgeous-ornate-fountain-made-of-marble.pngAdded
- examples/provisional_img/leather-glove-0.pngAdded
- examples/provisional_img/machine-dragon-robot-in-platinum-0.pngAdded
- examples/provisional_img/machine-dragon-robot-in-platinum-1.pngAdded
- examples/provisional_img/machine-dragon-robot-in-platinum-2.pngAdded
- examples/provisional_img/pottery.pngAdded
- examples/provisional_img/rusty-copper-toy-frog-with-spatially-varying-materials-some-parts-are-shinning-other-parts-are-rough.pngAdded
- examples/provisional_img/rusty-phoenix.pngAdded
- examples/provisional_img/starcraft-2-marine-machine-gun-0.pngAdded
- examples/provisional_img/steampunk-space-tank-with-delicate-details-0.pngAdded
- examples/provisional_img/steampunk-space-tank-with-delicate-details-1.pngAdded
- examples/provisional_img/stone-griffin.pngAdded
12 unmodified lines1314151617181914 unmodified lines3435363738394040 unmodified lines8182838485868776 unmodified lines16416516616716816917017117217317417517612 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 / Generation14 unmodified linesgr.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 Removal40 unmodified linesenv_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")76 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,12 unmodified lines1314151617181914 unmodified lines3435363738394040 unmodified lines8182838485868776 unmodified lines16416516616716816917017117217317417517617717812 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 & depth-conditioned generation) and more examples, please refer to our [GitHub repository](https://github.com/iamNCJ/DiLightNet)""")with gr.Row():# 1. Reference Image Input / Generation14 unmodified linesgr.Examples(examples=[os.path.join("examples/provisional_img", i) for i in os.listdir("examples/provisional_img")],inputs=[input_image],examples_per_page=8,)# 2. Background Removal40 unmodified linesenv_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")76 unmodified linesseed=int(relighting_seed),cfg=relighting_cfg)relit_img = imageio.v3.imread(res_folder_path + '/relighting00_0.png')if do_env_inpainting:bg = imageio.v3.imread(res_folder_path + f'/bg00.png') / 255.else:bg = np.zeros_like(relit_img)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,
1234567813 unmodified lines222324252627282930318 unmodified lines404142434445468 unmodified lines55565758596061626364656667import imageioimport numpy as npimport spacesimport torchfrom diffusers import UniPCMultistepScheduler, StableDiffusionControlNetPipeline, StableDiffusionInpaintPipeline, ConsistencyDecoderVAEfrom diffusers.utils import get_class_from_dynamic_modulefrom tqdm import tqdm13 unmodified lines"dilightnet/DiLightNet-submissions-300k",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)8 unmodified lines@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.8 unmodified linesimages.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))123456713 unmodified lines21222324252627288 unmodified lines373839404142438 unmodified lines52535455565758596061626364import imageioimport numpy as npimport torchfrom diffusers import UniPCMultistepScheduler, StableDiffusionControlNetPipeline, StableDiffusionInpaintPipelinefrom diffusers.utils import get_class_from_dynamic_modulefrom tqdm import tqdm13 unmodified lines"dilightnet/DiLightNet-submissions-300k",torch_dtype=dtype,)pipe = StableDiffusionControlNetPipeline.from_pretrained("stabilityai/stable-diffusion-2-1",controlnet=controlnet,torch_dtype=dtype).to(device)8 unmodified lines@spaces.GPUdef relighting_gen(masked_ref_img, mask, cond_path, frames, prompt, steps, seed, cfg, num_imgs_per_prompt=1, inpaint=False):mask = mask[..., :1] / 255.for i in tqdm(range(frames)):source_image = masked_ref_img[..., :3] / 255.8 unmodified linesimages.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.Generator(device=device).manual_seed(seed)images = pipe(prompt, num_inference_steps=steps, generator=generator, image=hint, num_images_per_prompt=num_imgs_per_prompt, guidance_scale=cfg, output_type='np',).images # [N, H, W, C]if inpaint:mask_image = (1. - mask)[None]images = inpainting_pipe(prompt=prompt, image=images, mask_image=mask_image, generator=generator, output_type='np', cfg=3.0, strength=1.0).imagesfor idx in range(num_imgs_per_prompt):imageio.imwrite(f'{cond_path}/relighting{i:02d}_{idx}.png', (images[idx] * 255).clip(0, 255).astype(np.uint8))
26 unmodified lines27282930313252 unmodified lines8586878889909113 unmodified lines10510610710810911026 unmodified linesbpy.context.preferences.addons["cycles"].preferences.get_devices()bpy.context.scene.cycles.device = 'GPU'bpy.context.preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'# Enable the alpha channel for GT maskbpy.context.scene.render.film_transparent = True52 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 np13 unmodified linesbpy.context.scene.render.film_transparent = Falsebpy.context.scene.render.image_settings.color_mode = 'RGB'def render_env_bg(output_path):bpy.context.scene.view_layers["ViewLayer"].material_override = Nonebpy.context.scene.render.image_settings.file_format = 'PNG'26 unmodified lines272829303132333452 unmodified lines8788899091929313 unmodified lines10710810911011111211311411511611711811926 unmodified linesbpy.context.preferences.addons["cycles"].preferences.get_devices()bpy.context.scene.cycles.device = 'GPU'bpy.context.preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'bpy.context.scene.render.threads = 8bpy.context.scene.render.threads_mode = 'FIXED'# Enable the alpha channel for GT maskbpy.context.scene.render.film_transparent = True52 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, use_gpu=False):import bpyimport numpy as np13 unmodified linesbpy.context.scene.render.film_transparent = Falsebpy.context.scene.render.image_settings.color_mode = 'RGB'if use_gpu:bpy.context.preferences.addons["cycles"].preferences.get_devices()bpy.context.scene.cycles.device = 'GPU'bpy.context.preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'bpy.context.scene.render.threads = 8bpy.context.scene.render.threads_mode = 'FIXED'def render_env_bg(output_path):bpy.context.scene.view_layers["ViewLayer"].material_override = Nonebpy.context.scene.render.image_settings.file_format = 'PNG'
app.py+10-8
demo/relighting_gen.py+9-12
demo/render_hints.py+10-1
examples/provisional_img/3d-animation-character-minimal-art-toy.pngAdded

Large File Pointer Details
- SHA256: 5e6022b4b5811d8221f8e20b1cfd9eee6e656557da14243151f49dd1351c6ff9
- Pointer size: 131 Bytes
- Size of remote file: 887 kB
examples/provisional_img/a-decorated-plaster-round-plate-with-blue-fine-silk-ribbon-around-it-0.pngAdded

Large File Pointer Details
- SHA256: 2af1b2539e5688c34f5ba662af80989a54af5334da7aed0a751e260b725951d7
- Pointer size: 132 Bytes
- Size of remote file: 3.16 MB
examples/provisional_img/a-decorated-plaster-round-plate-with-blue-fine-silk-ribbon-around-it-1.pngAdded

Large File Pointer Details
- SHA256: a9e0beda5044ff929716b7e9a4aa63d55dc55d39d797ffe97542aa698c798065
- Pointer size: 132 Bytes
- Size of remote file: 3.16 MB
examples/provisional_img/a-large-colorful-candle-high-quality-product-photo.pngAdded

Large File Pointer Details
- SHA256: bbfc77e6bd66a856a6c1d516a2c3ad9f23e824ec9fbc6dfcd7947792e9002674
- Pointer size: 132 Bytes
- Size of remote file: 3.16 MB
examples/provisional_img/an-elephant-sculpted-from-plaster-and-the-elephant-nose-is-decorated-with-the-golden-texture.pngAdded

Large File Pointer Details
- SHA256: d7d75875801c33972e23b47f0dcb4ce86a7b78df3a86f878e8e6899ff8be1364
- Pointer size: 132 Bytes
- Size of remote file: 3.16 MB
examples/provisional_img/girraffe_turtle.jpegAdded

examples/provisional_img/gorgeous-ornate-fountain-made-of-marble.pngAdded

Large File Pointer Details
- SHA256: 0bfc9dc43da7bc0535e550e70b5a78786ec47334f2812661e90ef7173832a9ab
- Pointer size: 131 Bytes
- Size of remote file: 888 kB
examples/provisional_img/leather-glove-0.pngAdded

Large File Pointer Details
- SHA256: b907f2b5ae7e92bfb41ba368b263a68e9e3d43a430950f606b3a8d80eeb65617
- Pointer size: 131 Bytes
- Size of remote file: 523 kB
examples/provisional_img/machine-dragon-robot-in-platinum-0.pngAdded

Large File Pointer Details
- SHA256: 777a48a22d551bc3ce80c3247bf77114d7b596d74124cee3a26eb357eb886908
- Pointer size: 131 Bytes
- Size of remote file: 855 kB
examples/provisional_img/machine-dragon-robot-in-platinum-1.pngAdded

Large File Pointer Details
- SHA256: 52c29bae3251733ccd58ebfabf4452a5de8f24da57826e9ac460edb0c5ee7ae2
- Pointer size: 131 Bytes
- Size of remote file: 799 kB
examples/provisional_img/machine-dragon-robot-in-platinum-2.pngAdded

Large File Pointer Details
- SHA256: 53a19155ec3e3a2c7ccb9816c8e7465fbef39c81b79d6b2e6e9e2cdd8c919174
- Pointer size: 131 Bytes
- Size of remote file: 619 kB
examples/provisional_img/pottery.pngAdded

Large File Pointer Details
- SHA256: d857ff5150610cd4ad605132b882bfeb71bc91857f71a7af00fe37b0a12e3a3e
- Pointer size: 132 Bytes
- Size of remote file: 1.29 MB
examples/provisional_img/rusty-copper-toy-frog-with-spatially-varying-materials-some-parts-are-shinning-other-parts-are-rough.pngAdded

Large File Pointer Details
- SHA256: 8883cd99b164a1710e75ef98c4c2775cef8d17878f6577998241cb577debd636
- Pointer size: 132 Bytes
- Size of remote file: 3.16 MB
examples/provisional_img/rusty-phoenix.pngAdded

Large File Pointer Details
- SHA256: 75cab46ef0fd031242bb4f7d8433282fd94b081abadf2cb5855728825b8fb361
- Pointer size: 132 Bytes
- Size of remote file: 3.16 MB
examples/provisional_img/starcraft-2-marine-machine-gun-0.pngAdded

Large File Pointer Details
- SHA256: cdfb7c769f5bf3c28f37796f3f115f41dd0515d5de9ce0c3f9e09d0c4e98f828
- Pointer size: 131 Bytes
- Size of remote file: 788 kB
examples/provisional_img/steampunk-space-tank-with-delicate-details-0.pngAdded

Large File Pointer Details
- SHA256: 0f09e18378653831d9f316d0641a3eb10eb44c5f3338ad0dd370c5b2a16d138e
- Pointer size: 131 Bytes
- Size of remote file: 880 kB
examples/provisional_img/steampunk-space-tank-with-delicate-details-1.pngAdded

Large File Pointer Details
- SHA256: d17eab2095ffb55ac2fa239c669da3916e7a45783b2891f009485de09972ae98
- Pointer size: 131 Bytes
- Size of remote file: 934 kB
examples/provisional_img/stone-griffin.pngAdded

Large File Pointer Details
- SHA256: da1fb50818a3e2d4373daac145063e231cdbc7980d03c8d43ef5e8b66f20d515
- Pointer size: 131 Bytes
- Size of remote file: 495 kB