File size: 1,291 Bytes
1d21e88
 
 
 
 
 
 
 
 
f65c627
1d21e88
 
 
 
 
f65c627
1d21e88
 
 
 
 
f65c627
1d21e88
 
 
 
 
 
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
"""Validated server-side switches for controlled learned-engine experiments."""
from dataclasses import dataclass
import os


@dataclass(frozen=True)
class LearnedSettings:
    matcher: str = 'loftr'
    max_size: int = 800
    patches: str = 'auto'
    adaptive_mask: bool = False

    @classmethod
    def from_env(cls):
        matcher = os.environ.get('IRIS_MATCHER', 'loftr')
        patches = os.environ.get('IRIS_PATCH_VALIDATION', 'auto')
        adaptive = os.environ.get('IRIS_ADAPTIVE_MASK', 'false').lower()
        try:
            size = int(os.environ.get('IRIS_MATCH_MAX_SIZE', '800' if matcher=='loftr' else '1600'))
        except ValueError as exc:
            raise RuntimeError('IRIS_MATCH_MAX_SIZE must be an integer.') from exc
        if matcher not in {'loftr', 'lightglue'} or patches not in {'auto', 'single', 'multiscale', 'geometry'}:
            raise RuntimeError('Invalid learned matcher or patch-validation configuration.')
        if adaptive not in {'true', 'false'}:
            raise RuntimeError('IRIS_ADAPTIVE_MASK must be true or false.')
        if not 400 <= size <= (1200 if matcher=='loftr' else 2200):
            raise RuntimeError('IRIS_MATCH_MAX_SIZE exceeds the supported range.')
        return cls(matcher, size, patches, adaptive=='true')