File size: 1,539 Bytes
05c6078
 
 
 
 
9c5a0eb
05c6078
 
 
 
 
 
 
 
 
 
9c5a0eb
 
 
4d329d3
 
 
9c5a0eb
 
 
05c6078
 
bcfd69e
 
 
 
 
 
 
 
9c5a0eb
bcfd69e
 
 
 
 
 
 
 
 
 
05c6078
 
 
 
9c5a0eb
05c6078
 
 
 
 
9c5a0eb
05c6078
 
 
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
from __future__ import annotations

from functools import lru_cache
from pathlib import Path

from .config import EXAMPLES_ROOT, IMAGE_EXTS, IMAGE_ROOT, VISLOC_DIR


@lru_cache(maxsize=1)
def list_visloc_images() -> list[Path]:
    if not VISLOC_DIR.exists():
        return []
    files = [p for p in VISLOC_DIR.iterdir() if p.suffix in IMAGE_EXTS]
    return sorted(files)


@lru_cache(maxsize=1)
def list_example_images() -> list[Path]:
    examples_dir = EXAMPLES_ROOT / "visloc"
    files: list[Path] = []
    if examples_dir.exists():
        files = [p for p in examples_dir.rglob("*") if p.is_file() and p.suffix in IMAGE_EXTS]
    return sorted(files)


@lru_cache(maxsize=1)
def list_all_data_inputs() -> list[str]:
    paths: list[Path] = []

    def _add(paths_in: list[Path]):
        for p in paths_in:
            if p not in paths:
                paths.append(p)

    # Prefer structured datasets first
    _add(list_example_images())
    _add(list_visloc_images())

    # Allow arbitrary images anywhere under data/Image/
    if IMAGE_ROOT.exists():
        for p in IMAGE_ROOT.rglob("*"):
            if p.is_file() and p.suffix in IMAGE_EXTS:
                if p not in paths:
                    paths.append(p)

    return [str(p) for p in sorted(paths)]


def clear_caches() -> None:
    list_visloc_images.cache_clear()
    list_example_images.cache_clear()
    list_all_data_inputs.cache_clear()


__all__ = [
    "list_visloc_images",
    "list_example_images",
    "list_all_data_inputs",
    "clear_caches",
]