forked from hbb1/2d-gaussian-splatting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.py
52 lines (46 loc) · 2.29 KB
/
view.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
from scene import Scene, GaussianModel
from argparse import ArgumentParser
from arguments import ModelParams, PipelineParams
from gaussian_renderer import render, network_gui
from utils.image_utils import render_net_image
import torch
def view(dataset, pipe, iteration):
gaussians = GaussianModel(dataset.sh_degree)
scene = Scene(dataset, gaussians, load_iteration=iteration, shuffle=False)
bg_color = [1, 1, 1] if dataset.white_background else [0, 0, 0]
background = torch.tensor(bg_color, dtype=torch.float32, device="cuda")
while True:
with torch.no_grad():
if network_gui.conn == None:
network_gui.try_connect(dataset.render_items)
while network_gui.conn != None:
try:
net_image_bytes = None
custom_cam, do_training, keep_alive, scaling_modifer, render_mode = network_gui.receive()
if custom_cam != None:
render_pkg = render(custom_cam, gaussians, pipe, background, scaling_modifer)
net_image = render_net_image(render_pkg, dataset.render_items, render_mode, custom_cam)
net_image_bytes = memoryview((torch.clamp(net_image, min=0, max=1.0) * 255).byte().permute(1, 2, 0).contiguous().cpu().numpy())
metrics_dict = {
"#": gaussians.get_opacity.shape[0]
# Add more metrics as needed
}
network_gui.send(net_image_bytes, dataset.source_path, metrics_dict)
except Exception as e:
raise e
print('Viewer closed')
exit(0)
if __name__ == "__main__":
# Set up command line argument parser
parser = ArgumentParser(description="Exporting script parameters")
lp = ModelParams(parser)
pp = PipelineParams(parser)
parser.add_argument('--ip', type=str, default="127.0.0.1")
parser.add_argument('--port', type=int, default=6009)
parser.add_argument('--iteration', type=int, default=30000)
args = parser.parse_args(sys.argv[1:])
print("View: " + args.model_path)
network_gui.init(args.ip, args.port)
view(lp.extract(args), pp.extract(args), args.iteration)
print("\nViewing complete.")