File size: 2,199 Bytes
41ff959
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pytest
import torch

from src.model.decoder import decoder_gsplat
from src.model.decoder.decoder_gsplat import DecoderGsplat, DecoderGsplatCfg
from src.utils.gaussians import Gaussians3D


def test_decoder_rasterizes_all_views_without_tile_override(monkeypatch) -> None:
    calls = []

    def fake_rasterization(*args, **kwargs):
        calls.append((args, kwargs))
        viewmats = args[5]
        width = args[7]
        height = args[8]
        rendering = torch.zeros(1, viewmats.shape[1], height, width, 3)
        alpha = torch.zeros(1, viewmats.shape[1], height, width, 1)
        return rendering, alpha, {}

    monkeypatch.setattr(decoder_gsplat, "rasterization", fake_rasterization)
    decoder = DecoderGsplat(
        DecoderGsplatCfg(name="gsplat", background_color=[0.0, 0.0, 0.0])
    )
    gaussians = Gaussians3D(
        mean_vectors=torch.zeros(1, 2, 3),
        singular_values=torch.ones(1, 2, 3),
        quaternions=torch.zeros(1, 2, 4),
        colors=torch.zeros(1, 2, 3),
        opacities=torch.ones(1, 2),
    )
    extrinsics = torch.eye(4).reshape(1, 1, 4, 4).repeat(1, 2, 1, 1)
    intrinsics = torch.eye(3).reshape(1, 1, 3, 3).repeat(1, 2, 1, 1)

    output = decoder(gaussians, extrinsics, intrinsics, image_shape=(4, 6))

    assert len(calls) == 1
    args, kwargs = calls[0]
    assert args[5].shape[1] == 2
    assert "tile_size" not in kwargs
    assert kwargs["render_mode"] == "RGB"
    assert output.shape == (1, 2, 3, 4, 6)


def test_decoder_reports_missing_optional_gsplat(monkeypatch) -> None:
    monkeypatch.setattr(decoder_gsplat, "rasterization", None)
    decoder = DecoderGsplat(
        DecoderGsplatCfg(name="gsplat", background_color=[0.0, 0.0, 0.0])
    )
    gaussians = Gaussians3D(
        mean_vectors=torch.zeros(1, 1, 3),
        singular_values=torch.ones(1, 1, 3),
        quaternions=torch.zeros(1, 1, 4),
        colors=torch.zeros(1, 1, 3),
        opacities=torch.ones(1, 1),
    )
    extrinsics = torch.eye(4).reshape(1, 1, 4, 4)
    intrinsics = torch.eye(3).reshape(1, 1, 3, 3)

    with pytest.raises(RuntimeError, match="optional `gsplat`"):
        decoder(gaussians, extrinsics, intrinsics, image_shape=(4, 6))