ironjr commited on
Commit
9be67bf
1 Parent(s): 1cf8b36

Upload folder using huggingface_hub

Browse files
gaussian_renderer/.__init__.py.swp ADDED
Binary file (16.4 kB). View file
 
gaussian_renderer/.ipynb_checkpoints/__init__-checkpoint.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Copyright (C) 2023, Inria
3
+ # GRAPHDECO research group, https://team.inria.fr/graphdeco
4
+ # All rights reserved.
5
+ #
6
+ # This software is free for non-commercial, research and evaluation use
7
+ # under the terms of the LICENSE.md file.
8
+ #
9
+ # For inquiries contact george.drettakis@inria.fr
10
+ #
11
+
12
+ import torch
13
+ import math
14
+ from depth_diff_gaussian_rasterization_min import GaussianRasterizationSettings, GaussianRasterizer
15
+ from scene.gaussian_model import GaussianModel
16
+ from utils.sh import eval_sh
17
+
18
+ def render(viewpoint_camera, pc: GaussianModel, opt, bg_color: torch.Tensor, scaling_modifier=1.0, override_color=None, render_only=False):
19
+ """
20
+ Render the scene.
21
+
22
+ Background tensor (bg_color) must be on GPU!
23
+ """
24
+
25
+ # Create zero tensor. We will use it to make pytorch return gradients of the 2D (screen-space) means
26
+ screenspace_points = torch.zeros_like(pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda") + 0
27
+ try:
28
+ screenspace_points.retain_grad()
29
+ except:
30
+ pass
31
+
32
+ # Set up rasterization configuration
33
+ tanfovx = math.tan(viewpoint_camera.FoVx * 0.5)
34
+ tanfovy = math.tan(viewpoint_camera.FoVy * 0.5)
35
+
36
+ raster_settings = GaussianRasterizationSettings(
37
+ image_height=int(viewpoint_camera.image_height),
38
+ image_width=int(viewpoint_camera.image_width),
39
+ tanfovx=tanfovx,
40
+ tanfovy=tanfovy,
41
+ bg=bg_color,
42
+ scale_modifier=scaling_modifier,
43
+ viewmatrix=viewpoint_camera.world_view_transform,
44
+ projmatrix=viewpoint_camera.full_proj_transform,
45
+ sh_degree=pc.active_sh_degree,
46
+ campos=viewpoint_camera.camera_center,
47
+ prefiltered=False,
48
+ debug=opt.debug
49
+ )
50
+
51
+ rasterizer = GaussianRasterizer(raster_settings=raster_settings)
52
+
53
+ means3D = pc.get_xyz
54
+ means2D = screenspace_points
55
+ opacity = pc.get_opacity
56
+
57
+ # If precomputed 3d covariance is provided, use it. If not, then it will be computed from
58
+ # scaling / rotation by the rasterizer.
59
+ scales = None
60
+ rotations = None
61
+ cov3D_precomp = None
62
+ if opt.compute_cov3D_python:
63
+ cov3D_precomp = pc.get_covariance(scaling_modifier)
64
+ else:
65
+ scales = pc.get_scaling
66
+ rotations = pc.get_rotation
67
+
68
+ # If precomputed colors are provided, use them. Otherwise, if it is desired to precompute colors
69
+ # from SHs in Python, do it. If not, then SH -> RGB conversion will be done by rasterizer.
70
+ shs = None
71
+ colors_precomp = None
72
+ if override_color is None:
73
+ if opt.convert_SHs_python:
74
+ shs_view = pc.get_features.transpose(1, 2).view(-1, 3, (pc.max_sh_degree+1)**2)
75
+ dir_pp = (pc.get_xyz - viewpoint_camera.camera_center.repeat(pc.get_features.shape[0], 1))
76
+ dir_pp_normalized = dir_pp/dir_pp.norm(dim=1, keepdim=True)
77
+ sh2rgb = eval_sh(pc.active_sh_degree, shs_view, dir_pp_normalized)
78
+ colors_precomp = torch.clamp_min(sh2rgb + 0.5, 0.0)
79
+ else:
80
+ shs = pc.get_features
81
+ else:
82
+ colors_precomp = override_color
83
+
84
+ # Rasterize visible Gaussians to image, obtain their radii (on screen).
85
+ rendered_image, radii, depth = rasterizer(
86
+ means3D = means3D,
87
+ means2D = means2D,
88
+ shs = shs,
89
+ colors_precomp = colors_precomp,
90
+ opacities = opacity,
91
+ scales = scales,
92
+ rotations = rotations,
93
+ cov3D_precomp = cov3D_precomp)
94
+
95
+ # Those Gaussians that were frustum culled or had a radius of 0 were not visible.
96
+ # They will be excluded from value updates used in the splitting criteria.
97
+ if render_only:
98
+ return {"render": rendered_image, "depth": depth}
99
+ else:
100
+ return {"render": rendered_image,
101
+ "viewspace_points": screenspace_points,
102
+ "visibility_filter" : radii > 0,
103
+ "radii": radii,
104
+ "depth": depth}
gaussian_renderer/__init__.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Copyright (C) 2023, Inria
3
+ # GRAPHDECO research group, https://team.inria.fr/graphdeco
4
+ # All rights reserved.
5
+ #
6
+ # This software is free for non-commercial, research and evaluation use
7
+ # under the terms of the LICENSE.md file.
8
+ #
9
+ # For inquiries contact george.drettakis@inria.fr
10
+ #
11
+
12
+ import torch
13
+ import math
14
+ from depth_diff_gaussian_rasterization_min import GaussianRasterizationSettings, GaussianRasterizer
15
+ from scene.gaussian_model import GaussianModel
16
+ from utils.sh import eval_sh
17
+
18
+ def render(viewpoint_camera, pc: GaussianModel, opt, bg_color: torch.Tensor, scaling_modifier=1.0, override_color=None, render_only=False):
19
+ """
20
+ Render the scene.
21
+
22
+ Background tensor (bg_color) must be on GPU!
23
+ """
24
+
25
+ # Create zero tensor. We will use it to make pytorch return gradients of the 2D (screen-space) means
26
+ screenspace_points = torch.zeros_like(pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda") + 0
27
+ try:
28
+ screenspace_points.retain_grad()
29
+ except:
30
+ pass
31
+
32
+ # Set up rasterization configuration
33
+ tanfovx = math.tan(viewpoint_camera.FoVx * 0.5)
34
+ tanfovy = math.tan(viewpoint_camera.FoVy * 0.5)
35
+
36
+ raster_settings = GaussianRasterizationSettings(
37
+ image_height=int(viewpoint_camera.image_height),
38
+ image_width=int(viewpoint_camera.image_width),
39
+ tanfovx=tanfovx,
40
+ tanfovy=tanfovy,
41
+ bg=bg_color,
42
+ scale_modifier=scaling_modifier,
43
+ viewmatrix=viewpoint_camera.world_view_transform,
44
+ projmatrix=viewpoint_camera.full_proj_transform,
45
+ sh_degree=pc.active_sh_degree,
46
+ campos=viewpoint_camera.camera_center,
47
+ prefiltered=False,
48
+ debug=opt.debug
49
+ )
50
+
51
+ rasterizer = GaussianRasterizer(raster_settings=raster_settings)
52
+
53
+ means3D = pc.get_xyz
54
+ means2D = screenspace_points
55
+ opacity = pc.get_opacity
56
+
57
+ # If precomputed 3d covariance is provided, use it. If not, then it will be computed from
58
+ # scaling / rotation by the rasterizer.
59
+ scales = None
60
+ rotations = None
61
+ cov3D_precomp = None
62
+ if opt.compute_cov3D_python:
63
+ cov3D_precomp = pc.get_covariance(scaling_modifier)
64
+ else:
65
+ scales = pc.get_scaling
66
+ rotations = pc.get_rotation
67
+
68
+ # If precomputed colors are provided, use them. Otherwise, if it is desired to precompute colors
69
+ # from SHs in Python, do it. If not, then SH -> RGB conversion will be done by rasterizer.
70
+ shs = None
71
+ colors_precomp = None
72
+ if override_color is None:
73
+ if opt.convert_SHs_python:
74
+ shs_view = pc.get_features.transpose(1, 2).view(-1, 3, (pc.max_sh_degree+1)**2)
75
+ dir_pp = (pc.get_xyz - viewpoint_camera.camera_center.repeat(pc.get_features.shape[0], 1))
76
+ dir_pp_normalized = dir_pp/dir_pp.norm(dim=1, keepdim=True)
77
+ sh2rgb = eval_sh(pc.active_sh_degree, shs_view, dir_pp_normalized)
78
+ colors_precomp = torch.clamp_min(sh2rgb + 0.5, 0.0)
79
+ else:
80
+ shs = pc.get_features
81
+ else:
82
+ colors_precomp = override_color
83
+
84
+ # Rasterize visible Gaussians to image, obtain their radii (on screen).
85
+ rendered_image, radii, depth = rasterizer(
86
+ means3D = means3D,
87
+ means2D = means2D,
88
+ shs = shs,
89
+ colors_precomp = colors_precomp,
90
+ opacities = opacity,
91
+ scales = scales,
92
+ rotations = rotations,
93
+ cov3D_precomp = cov3D_precomp)
94
+
95
+ # Those Gaussians that were frustum culled or had a radius of 0 were not visible.
96
+ # They will be excluded from value updates used in the splitting criteria.
97
+ if render_only:
98
+ return {"render": rendered_image, "depth": depth}
99
+ else:
100
+ return {"render": rendered_image,
101
+ "viewspace_points": screenspace_points,
102
+ "visibility_filter" : radii > 0,
103
+ "radii": radii,
104
+ "depth": depth}
gaussian_renderer/__pycache__/__init__.cpython-39.pyc ADDED
Binary file (2.2 kB). View file
 
gaussian_renderer/network_gui.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Copyright (C) 2023, Inria
3
+ # GRAPHDECO research group, https://team.inria.fr/graphdeco
4
+ # All rights reserved.
5
+ #
6
+ # This software is free for non-commercial, research and evaluation use
7
+ # under the terms of the LICENSE.md file.
8
+ #
9
+ # For inquiries contact george.drettakis@inria.fr
10
+ #
11
+
12
+ import torch
13
+ import traceback
14
+ import socket
15
+ import json
16
+ from scene.cameras import MiniCam
17
+
18
+ host = "127.0.0.1"
19
+ port = 6009
20
+
21
+ conn = None
22
+ addr = None
23
+
24
+ listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
25
+
26
+ def init(wish_host, wish_port):
27
+ global host, port, listener
28
+ host = wish_host
29
+ port = wish_port
30
+ listener.bind((host, port))
31
+ listener.listen()
32
+ listener.settimeout(0)
33
+
34
+ def try_connect():
35
+ global conn, addr, listener
36
+ try:
37
+ conn, addr = listener.accept()
38
+ print(f"\nConnected by {addr}")
39
+ conn.settimeout(None)
40
+ except Exception as inst:
41
+ pass
42
+
43
+ def read():
44
+ global conn
45
+ messageLength = conn.recv(4)
46
+ messageLength = int.from_bytes(messageLength, 'little')
47
+ message = conn.recv(messageLength)
48
+ return json.loads(message.decode("utf-8"))
49
+
50
+ def send(message_bytes, verify):
51
+ global conn
52
+ if message_bytes != None:
53
+ conn.sendall(message_bytes)
54
+ conn.sendall(len(verify).to_bytes(4, 'little'))
55
+ conn.sendall(bytes(verify, 'ascii'))
56
+
57
+ def receive():
58
+ message = read()
59
+
60
+ width = message["resolution_x"]
61
+ height = message["resolution_y"]
62
+
63
+ if width != 0 and height != 0:
64
+ try:
65
+ do_training = bool(message["train"])
66
+ fovy = message["fov_y"]
67
+ fovx = message["fov_x"]
68
+ znear = message["z_near"]
69
+ zfar = message["z_far"]
70
+ do_shs_python = bool(message["shs_python"])
71
+ do_rot_scale_python = bool(message["rot_scale_python"])
72
+ keep_alive = bool(message["keep_alive"])
73
+ scaling_modifier = message["scaling_modifier"]
74
+ world_view_transform = torch.reshape(torch.tensor(message["view_matrix"]), (4, 4)).cuda()
75
+ world_view_transform[:,1] = -world_view_transform[:,1]
76
+ world_view_transform[:,2] = -world_view_transform[:,2]
77
+ full_proj_transform = torch.reshape(torch.tensor(message["view_projection_matrix"]), (4, 4)).cuda()
78
+ full_proj_transform[:,1] = -full_proj_transform[:,1]
79
+ custom_cam = MiniCam(width, height, fovy, fovx, znear, zfar, world_view_transform, full_proj_transform)
80
+ except Exception as e:
81
+ print("")
82
+ traceback.print_exc()
83
+ raise e
84
+ return custom_cam, do_training, do_shs_python, do_rot_scale_python, keep_alive, scaling_modifier
85
+ else:
86
+ return None, None, None, None, None, None