"vscode:/vscode.git/clone" did not exist on "87d54c4e583207e7b003d6b59f1e7f49167f68f1"
test_data_source.py 1.82 KB
Newer Older
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
1
2
3
4
5
6
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
7
import os
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
8
import unittest
9
import unittest.mock
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
10
11
12

from omegaconf import OmegaConf
from pytorch3d.implicitron.dataset.data_source import ImplicitronDataSource
13
from pytorch3d.implicitron.dataset.json_index_dataset import JsonIndexDataset
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
14
from pytorch3d.implicitron.tools.config import get_default_args
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
15
from tests.common_testing import get_tests_dir
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
16
17
18
19
20
21
22
23
24

DATA_DIR = get_tests_dir() / "implicitron/data"
DEBUG: bool = False


class TestDataSource(unittest.TestCase):
    def setUp(self):
        self.maxDiff = None

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
    def _test_omegaconf_generic_failure(self):
        # OmegaConf possible bug - this is why we need _GenericWorkaround
        from dataclasses import dataclass

        import torch

        @dataclass
        class D(torch.utils.data.Dataset[int]):
            a: int = 3

        OmegaConf.structured(D)

    def _test_omegaconf_ListList(self):
        # Demo that OmegaConf doesn't support nested lists
        from dataclasses import dataclass
        from typing import Sequence

        @dataclass
        class A:
            a: Sequence[Sequence[int]] = ((32,),)

        OmegaConf.structured(A)

    def test_JsonIndexDataset_args(self):
        # test that JsonIndexDataset works with get_default_args
        get_default_args(JsonIndexDataset)

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
52
    def test_one(self):
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
53
54
55
56
57
58
        with unittest.mock.patch.dict(os.environ, {"CO3D_DATASET_ROOT": ""}):
            cfg = get_default_args(ImplicitronDataSource)
            yaml = OmegaConf.to_yaml(cfg, sort_keys=False)
            if DEBUG:
                (DATA_DIR / "data_source.yaml").write_text(yaml)
            self.assertEqual(yaml, (DATA_DIR / "data_source.yaml").read_text())