Spaces:
Paused
Paused
CrazyT commited on
Commit ·
d69cecb
1
Parent(s): ffc2c16
cpu won't work (show message)
Browse files- .gitignore +1 -0
- app.py +45 -13
- runLocalDocker.bat +1 -1
- wrapper/open3d/__init__.py +63 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*.pyc
|
app.py
CHANGED
|
@@ -1,22 +1,54 @@
|
|
| 1 |
import torch
|
| 2 |
import sys
|
|
|
|
|
|
|
|
|
|
| 3 |
if torch.cuda.is_available():
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
else:
|
| 12 |
-
|
| 13 |
-
from Dynamic3DGaussians_cpu.visualize import visualize
|
| 14 |
|
| 15 |
import gradio as gr
|
| 16 |
|
| 17 |
-
def basketball(
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
iface = gr.Interface(fn=basketball, inputs=
|
| 22 |
iface.launch(server_name="0.0.0.0")
|
|
|
|
| 1 |
import torch
|
| 2 |
import sys
|
| 3 |
+
import numpy as np
|
| 4 |
+
import tempfile
|
| 5 |
+
|
| 6 |
if torch.cuda.is_available():
|
| 7 |
+
try:
|
| 8 |
+
torch.ones(1, 1).cuda().float()
|
| 9 |
+
sys.path.insert(0,"/home/user/app/wrapper")
|
| 10 |
+
sys.path.append("/home/user/app/Dynamic3DGaussians")
|
| 11 |
+
from Dynamic3DGaussians.visualize import visualize
|
| 12 |
+
import open3d as o3d
|
| 13 |
+
IS_CPU = False
|
| 14 |
+
except Exception as e:
|
| 15 |
+
print(e)
|
| 16 |
+
IS_CPU = True
|
| 17 |
else:
|
| 18 |
+
IS_CPU = True
|
|
|
|
| 19 |
|
| 20 |
import gradio as gr
|
| 21 |
|
| 22 |
+
def basketball(what):
|
| 23 |
+
if IS_CPU:
|
| 24 |
+
return None, None, "Not possible on CPU"
|
| 25 |
+
visualize(what, "pretrained")
|
| 26 |
+
result = "Done"
|
| 27 |
+
pcd = o3d.get_object()
|
| 28 |
+
pcd.normals = o3d.utility.Vector3dVector(
|
| 29 |
+
np.zeros((1, 3))) # invalidate existing normals
|
| 30 |
+
pcd.estimate_normals(
|
| 31 |
+
search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.01, max_nn=30))
|
| 32 |
+
pcd.orient_normals_towards_camera_location(
|
| 33 |
+
camera_location=np.array([0., 0., 1000.]))
|
| 34 |
+
pcd.transform([[1, 0, 0, 0],
|
| 35 |
+
[0, -1, 0, 0],
|
| 36 |
+
[0, 0, -1, 0],
|
| 37 |
+
[0, 0, 0, 1]])
|
| 38 |
+
pcd.transform([[-1, 0, 0, 0],
|
| 39 |
+
[0, 1, 0, 0],
|
| 40 |
+
[0, 0, 1, 0],
|
| 41 |
+
[0, 0, 0, 1]])
|
| 42 |
+
mesh_raw, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
|
| 43 |
+
pcd, width=0, scale=1.1, linear_fit=True)
|
| 44 |
+
temp_name = next(tempfile._get_candidate_names())
|
| 45 |
+
file_path = f"/tmp/{temp_name}.gltf"
|
| 46 |
+
file_path_pcd = f"/tmp/{temp_name}.pcd"
|
| 47 |
+
if not o3d.io.write_triangle_mesh(file_path, mesh_raw):
|
| 48 |
+
result = "ERROR #1"
|
| 49 |
+
if not o3d.io.write_point_cloud(file_path_pcd, pcd):
|
| 50 |
+
result = "ERROR #2"
|
| 51 |
+
return file_path, file_path_pcd, result
|
| 52 |
|
| 53 |
+
iface = gr.Interface(fn=basketball, inputs=gr.Dropdown(["basketball", "boxes", "football", "juggle", "softball", "tennis"], value="basketball"), outputs=[gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model"), gr.File(), gr.Textbox(label="debug output")], allow_flagging="never")
|
| 54 |
iface.launch(server_name="0.0.0.0")
|
runLocalDocker.bat
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
docker run --gpus=all --entrypoint "python" -v
|
| 2 |
pause
|
|
|
|
| 1 |
+
docker run --gpus=all --entrypoint "python" -v .\wrapper:/home/user/app/wrapper -v .\app.py:/home/user/app/app.py -p 7860:7860 --rm -ti registry.hf.space/crazyt-dynamic3dgaussians:latest /usr/local/bin/gradio app.py
|
| 2 |
pause
|
wrapper/open3d/__init__.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from importlib import reload
|
| 2 |
+
import sys
|
| 3 |
+
import numpy as np
|
| 4 |
+
if("wrapper" in sys.path[0]):
|
| 5 |
+
sys.path.remove(sys.path[0])
|
| 6 |
+
import open3d
|
| 7 |
+
reload(open3d)
|
| 8 |
+
from open3d import visualization
|
| 9 |
+
|
| 10 |
+
class ObjectHolder:
|
| 11 |
+
def __init__(self):
|
| 12 |
+
self.obj = None
|
| 13 |
+
|
| 14 |
+
objHolder = ObjectHolder()
|
| 15 |
+
|
| 16 |
+
def get_object():
|
| 17 |
+
global objHolder
|
| 18 |
+
return objHolder.obj
|
| 19 |
+
|
| 20 |
+
class do_nothing_obj_simple:
|
| 21 |
+
def __init__(self):
|
| 22 |
+
self.intrinsic_matrix = np.array([[320, 0, 320], [0, 320, 180], [0, 0, 1]])
|
| 23 |
+
class do_nothing_obj:
|
| 24 |
+
def __init__(self):
|
| 25 |
+
self.intrinsic = do_nothing_obj_simple()
|
| 26 |
+
self.extrinsic = np.array([[1., 0., 0., 0.],
|
| 27 |
+
[0., 1., 0., 0.],
|
| 28 |
+
[0., 0., 1., 0.],
|
| 29 |
+
[0., 0., 0., 1.]])
|
| 30 |
+
|
| 31 |
+
class do_nothing_class_ViewControl:
|
| 32 |
+
def convert_from_pinhole_camera_parameters(self,*args,**kwargs):
|
| 33 |
+
pass
|
| 34 |
+
def convert_to_pinhole_camera_parameters(self,*args,**kwargs):
|
| 35 |
+
return do_nothing_obj()
|
| 36 |
+
class proxy_class_Visualizer:
|
| 37 |
+
def __init__(self):
|
| 38 |
+
global orgVisualizer
|
| 39 |
+
self.geometries = []
|
| 40 |
+
self.delegate = orgVisualizer()
|
| 41 |
+
def get_render_option(self):
|
| 42 |
+
return do_nothing_obj()
|
| 43 |
+
def create_window(self,*args,**kwargs):
|
| 44 |
+
pass
|
| 45 |
+
def destroy_window(self):
|
| 46 |
+
pass
|
| 47 |
+
def update_renderer(self):
|
| 48 |
+
return self.update_renderer()
|
| 49 |
+
def get_view_control(self):
|
| 50 |
+
return do_nothing_class_ViewControl()
|
| 51 |
+
def add_geometry(self,pcd):
|
| 52 |
+
self.geometries.append(pcd)
|
| 53 |
+
return self.delegate.add_geometry(pcd)
|
| 54 |
+
def update_geometry(self,pcd):
|
| 55 |
+
global objHolder
|
| 56 |
+
objHolder.obj = pcd
|
| 57 |
+
return self.delegate.update_geometry(pcd)
|
| 58 |
+
def poll_events(self):
|
| 59 |
+
return self.delegate.poll_events()
|
| 60 |
+
|
| 61 |
+
orgVisualizer = visualization.Visualizer
|
| 62 |
+
visualization.Visualizer = proxy_class_Visualizer
|
| 63 |
+
open3d.get_object = get_object
|