Spaces:
Running on Zero
Running on Zero
Deploy DiffusionGS online generation demos
Browse files- diffusionGS/pipline_obj.py +1 -1
- diffusionGS/systems/utils.py +1 -1
- diffusionGS/utils/mesh_utils.py +3 -2
- diffusionGS/utils/saving.py +1 -1
- space_app.py +5 -2
diffusionGS/pipline_obj.py
CHANGED
|
@@ -3,7 +3,6 @@ import warnings
|
|
| 3 |
from typing import Callable, List, Optional, Union, Dict, Any
|
| 4 |
import PIL.Image
|
| 5 |
import trimesh
|
| 6 |
-
import rembg
|
| 7 |
import torch
|
| 8 |
import numpy as np
|
| 9 |
from huggingface_hub import hf_hub_download
|
|
@@ -122,6 +121,7 @@ class DiffusionGSPipeline():
|
|
| 122 |
do_remove = False
|
| 123 |
do_remove = do_remove or force
|
| 124 |
if do_remove:
|
|
|
|
| 125 |
image = rembg.remove(image)
|
| 126 |
|
| 127 |
# calculate the min bbox of the image
|
|
|
|
| 3 |
from typing import Callable, List, Optional, Union, Dict, Any
|
| 4 |
import PIL.Image
|
| 5 |
import trimesh
|
|
|
|
| 6 |
import torch
|
| 7 |
import numpy as np
|
| 8 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 121 |
do_remove = False
|
| 122 |
do_remove = do_remove or force
|
| 123 |
if do_remove:
|
| 124 |
+
import rembg
|
| 125 |
image = rembg.remove(image)
|
| 126 |
|
| 127 |
# calculate the min bbox of the image
|
diffusionGS/systems/utils.py
CHANGED
|
@@ -13,7 +13,6 @@ from torchvision import transforms
|
|
| 13 |
from diffusionGS.utils.structure import Mesh
|
| 14 |
import inspect
|
| 15 |
from PIL import Image, ImageOps
|
| 16 |
-
import rembg
|
| 17 |
import cv2
|
| 18 |
def _warmup_beta(beta_start, beta_end, num_diffusion_timesteps, warmup_frac):
|
| 19 |
betas = beta_end * np.ones(num_diffusion_timesteps, dtype=np.float64)
|
|
@@ -573,6 +572,7 @@ def preprocess(image:Image.Image,session) -> Image.Image:
|
|
| 573 |
rgba = image.copy()
|
| 574 |
else:
|
| 575 |
# https://github.com/pymatting/pymatting/issues/19
|
|
|
|
| 576 |
rgba = rembg.remove(image, alpha_matting=True, session=session)
|
| 577 |
|
| 578 |
alpha = rgba.getchannel('A')
|
|
|
|
| 13 |
from diffusionGS.utils.structure import Mesh
|
| 14 |
import inspect
|
| 15 |
from PIL import Image, ImageOps
|
|
|
|
| 16 |
import cv2
|
| 17 |
def _warmup_beta(beta_start, beta_end, num_diffusion_timesteps, warmup_frac):
|
| 18 |
betas = beta_end * np.ones(num_diffusion_timesteps, dtype=np.float64)
|
|
|
|
| 572 |
rgba = image.copy()
|
| 573 |
else:
|
| 574 |
# https://github.com/pymatting/pymatting/issues/19
|
| 575 |
+
import rembg
|
| 576 |
rgba = rembg.remove(image, alpha_matting=True, session=session)
|
| 577 |
|
| 578 |
alpha = rgba.getchannel('A')
|
diffusionGS/utils/mesh_utils.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import numpy as np
|
| 2 |
-
import pymeshlab as pml
|
| 3 |
|
| 4 |
|
| 5 |
def poisson_mesh_reconstruction(points, normals=None):
|
|
@@ -57,6 +56,7 @@ def decimate_mesh(
|
|
| 57 |
solver.simplify_mesh(target_count=target, preserve_border=False, verbose=False)
|
| 58 |
verts, faces, normals = solver.getMesh()
|
| 59 |
else:
|
|
|
|
| 60 |
m = pml.Mesh(verts, faces)
|
| 61 |
ms = pml.MeshSet()
|
| 62 |
ms.add_mesh(m, "mesh") # will copy!
|
|
@@ -95,6 +95,7 @@ def clean_mesh(
|
|
| 95 |
remesh=True,
|
| 96 |
remesh_size=0.01,
|
| 97 |
):
|
|
|
|
| 98 |
# verts: [N, 3]
|
| 99 |
# faces: [N, 3]
|
| 100 |
|
|
@@ -144,4 +145,4 @@ def clean_mesh(
|
|
| 144 |
f"[INFO] mesh cleaning: {_ori_vert_shape} --> {verts.shape}, {_ori_face_shape} --> {faces.shape}"
|
| 145 |
)
|
| 146 |
|
| 147 |
-
return verts, faces
|
|
|
|
| 1 |
import numpy as np
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
def poisson_mesh_reconstruction(points, normals=None):
|
|
|
|
| 56 |
solver.simplify_mesh(target_count=target, preserve_border=False, verbose=False)
|
| 57 |
verts, faces, normals = solver.getMesh()
|
| 58 |
else:
|
| 59 |
+
import pymeshlab as pml
|
| 60 |
m = pml.Mesh(verts, faces)
|
| 61 |
ms = pml.MeshSet()
|
| 62 |
ms.add_mesh(m, "mesh") # will copy!
|
|
|
|
| 95 |
remesh=True,
|
| 96 |
remesh_size=0.01,
|
| 97 |
):
|
| 98 |
+
import pymeshlab as pml
|
| 99 |
# verts: [N, 3]
|
| 100 |
# faces: [N, 3]
|
| 101 |
|
|
|
|
| 145 |
f"[INFO] mesh cleaning: {_ori_vert_shape} --> {verts.shape}, {_ori_face_shape} --> {faces.shape}"
|
| 146 |
)
|
| 147 |
|
| 148 |
+
return verts, faces
|
diffusionGS/utils/saving.py
CHANGED
|
@@ -17,7 +17,6 @@ from pytorch_lightning.loggers import WandbLogger
|
|
| 17 |
import torchvision
|
| 18 |
from diffusionGS.models.geometry.utils import Mesh
|
| 19 |
from diffusionGS.utils.typing import *
|
| 20 |
-
import open3d as o3d
|
| 21 |
from einops import rearrange
|
| 22 |
from diffusionGS.models.gsrenderer.gs_core import imageseq2video, render_turntable, render_generic
|
| 23 |
from diffusionGS.models.gsrenderer.cam_utils import get_interpolated_poses_many
|
|
@@ -521,6 +520,7 @@ class SaverMixin:
|
|
| 521 |
return save_path
|
| 522 |
|
| 523 |
def save_vertices_as_ply_open3d(self, vertices, normal, filepath):
|
|
|
|
| 524 |
# points = [[v[0], v[1], v[2]] for v in vertices]
|
| 525 |
points = vertices
|
| 526 |
point_cloud = o3d.geometry.PointCloud()
|
|
|
|
| 17 |
import torchvision
|
| 18 |
from diffusionGS.models.geometry.utils import Mesh
|
| 19 |
from diffusionGS.utils.typing import *
|
|
|
|
| 20 |
from einops import rearrange
|
| 21 |
from diffusionGS.models.gsrenderer.gs_core import imageseq2video, render_turntable, render_generic
|
| 22 |
from diffusionGS.models.gsrenderer.cam_utils import get_interpolated_poses_many
|
|
|
|
| 520 |
return save_path
|
| 521 |
|
| 522 |
def save_vertices_as_ply_open3d(self, vertices, normal, filepath):
|
| 523 |
+
import open3d as o3d
|
| 524 |
# points = [[v[0], v[1], v[2]] for v in vertices]
|
| 525 |
points = vertices
|
| 526 |
point_cloud = o3d.geometry.PointCloud()
|
space_app.py
CHANGED
|
@@ -7,6 +7,8 @@ from types import SimpleNamespace
|
|
| 7 |
# Gradio worker thread when ZeroGPU starts the GPU process.
|
| 8 |
os.environ.setdefault("NUMBA_THREADING_LAYER", "workqueue")
|
| 9 |
os.environ.setdefault("NUMBA_NUM_THREADS", "2")
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# ZeroGPU must install its CUDA emulation before torch is imported.
|
| 12 |
import spaces
|
|
@@ -54,7 +56,7 @@ def load_object_pipeline(model_dir):
|
|
| 54 |
return DiffusionGSPipeline("cuda:0", config, system)
|
| 55 |
|
| 56 |
|
| 57 |
-
torch.set_num_threads(
|
| 58 |
model_dir = Path(snapshot_download(
|
| 59 |
MODEL_REPO, revision=MODEL_REVISION,
|
| 60 |
allow_patterns=["obj_ckpt_512.ckpt", "obj_configs.yaml", "camera_template.pt",
|
|
@@ -106,8 +108,9 @@ object_service.generate = generate_object
|
|
| 106 |
object_service.extract_mesh = extract_mesh
|
| 107 |
scene_service.generate = generate_scene
|
| 108 |
demo = build_object_demo(service=object_service)
|
|
|
|
| 109 |
with demo.route("Scene Generation", "/scene"):
|
| 110 |
-
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|
| 113 |
demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("GRADIO_SERVER_PORT", "7860")),
|
|
|
|
| 7 |
# Gradio worker thread when ZeroGPU starts the GPU process.
|
| 8 |
os.environ.setdefault("NUMBA_THREADING_LAYER", "workqueue")
|
| 9 |
os.environ.setdefault("NUMBA_NUM_THREADS", "2")
|
| 10 |
+
for variable in ("OMP_NUM_THREADS", "MKL_NUM_THREADS", "OPENBLAS_NUM_THREADS"):
|
| 11 |
+
os.environ[variable] = "1"
|
| 12 |
|
| 13 |
# ZeroGPU must install its CUDA emulation before torch is imported.
|
| 14 |
import spaces
|
|
|
|
| 56 |
return DiffusionGSPipeline("cuda:0", config, system)
|
| 57 |
|
| 58 |
|
| 59 |
+
torch.set_num_threads(1)
|
| 60 |
model_dir = Path(snapshot_download(
|
| 61 |
MODEL_REPO, revision=MODEL_REVISION,
|
| 62 |
allow_patterns=["obj_ckpt_512.ckpt", "obj_configs.yaml", "camera_template.pt",
|
|
|
|
| 108 |
object_service.extract_mesh = extract_mesh
|
| 109 |
scene_service.generate = generate_scene
|
| 110 |
demo = build_object_demo(service=object_service)
|
| 111 |
+
scene_demo = build_scene_demo(service=scene_service)
|
| 112 |
with demo.route("Scene Generation", "/scene"):
|
| 113 |
+
scene_demo.render()
|
| 114 |
|
| 115 |
if __name__ == "__main__":
|
| 116 |
demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("GRADIO_SERVER_PORT", "7860")),
|