Skip to content

Commit 6bd2bde

Browse files
terratorch.models.backbones.utils
Signed-off-by: João Lucas de Sousa Almeida <[email protected]>
1 parent 233a5c2 commit 6bd2bde

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

terratorch/models/backbones/utils.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from terratorch.datasets import HLSBands
2+
3+
def _are_sublists_of_int(item) -> bool:
4+
5+
if all([isinstance(i, list) for i in item]):
6+
if all([isinstance(i, int) for i in sum(item, [])]):
7+
return True
8+
else:
9+
return False
10+
else:
11+
return False
12+
13+
def _estimate_in_chans(model_bands: list[HLSBands] | list[str] | tuple[int, int] = None) -> int:
14+
15+
# Conditional to deal with the different possible choices for the bands
16+
# Bands as lists of strings or enum
17+
if all([isinstance(b, str) for b in model_bands]):
18+
in_chans = len(model_bands)
19+
# Bands as intervals limited by integers
20+
elif all([isinstance(b, int) for b in model_bands] or _are_sublists_of_int(model_bands)):
21+
22+
if _are_sublists_of_int(model_bands):
23+
in_chans = sum([i[-1] - i[0] for i in model_bands])
24+
else:
25+
in_chans = model_bands[-1] - model_bands[0]
26+
else:
27+
raise Exception(f"Expected bands to be list(str) or [int, int] but received {model_bands}")
28+
29+
return in_chans
30+
31+

0 commit comments

Comments
 (0)