File size: 1,980 Bytes
ee8301e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import io
from pathlib import Path

import torch


def save_tensor(tensor, name):
    f = io.BytesIO()
    torch.save(tensor, f, _use_new_zipfile_serialization=True)
    with open(name, "wb") as out_f:
        out_f.write(f.getbuffer())


def process_forward_dump(dump_path: Path, output_path: Path):
    output_path.mkdir(exist_ok=True, parents=True)
    data = torch.load(dump_path)
    arg_names = [
        "bg",
        "means3D",
        "colors_precomp",
        "opacities",
        "scales",
        "rotations",
        "scale_modifier",
        "cov3Ds_precomp",
        "viewmatrix",
        "projmatrix",
        "tanfovx",
        "tanfovy",
        "image_height",
        "image_width",
        "sh",
        "sh_degree",
        "campos",
        "prefiltered",
        "debug",
    ]
    for tensor, name in zip(data, arg_names):
        save_tensor(tensor, str(output_path / name) + ".pt")


def process_backward_dump(dump_path: Path, output_path: Path):
    output_path.mkdir(exist_ok=True, parents=True)
    data = torch.load(dump_path)
    arg_names = [
        "bg",
        "means3D",
        "radii",
        "colors_precomp",
        "scales",
        "rotations",
        "scale_modifier",
        "cov3Ds_precomp",
        "viewmatrix",
        "projmatrix",
        "tanfovx",
        "tanfovy",
        "grad_out_color",
        "grad_depth",
        "grad_out_alpha",
        "sh",
        "sh_degree",
        "campos",
        "geomBuffer",
        "num_rendered",
        "binningBuffer",
        "imgBuffer",
        "alpha",
        "debug"
    ]
    for tensor, name in zip(data, arg_names):
        save_tensor(tensor, str(output_path / name) + ".pt")


if __name__ == '__main__':
    global_path = Path("/home/vy/projects/gaussian-rasterizer/test_data")
    process_forward_dump(global_path / "snapshot_fw.dump", global_path / "forward_tensors")
    process_backward_dump(global_path / "snapshot_bw.dump",  global_path / "backward_tensors")