forked from Britefury/self-ensemble-visual-domain-adapt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdline_helpers.py
54 lines (46 loc) · 1.8 KB
/
cmdline_helpers.py
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
import os
def intens_aug_options(intens_scale_range, intens_offset_range):
intens_scale_range_lower = intens_scale_range_upper = None
if intens_scale_range != '':
if ':' not in intens_scale_range:
print('Invalid intens_scale_range format; should be float:float')
return
l, _, h = intens_scale_range.partition(':')
try:
intens_scale_range_lower = float(l)
intens_scale_range_upper = float(h)
except ValueError:
print('Invalid intens_scale_range format; should be float:float')
return
intens_offset_range_lower = intens_offset_range_upper = None
if intens_offset_range != '':
if ':' not in intens_offset_range:
print('Invalid intens_offset_range format; should be float:float')
return
l, _, h = intens_offset_range.partition(':')
try:
intens_offset_range_lower = float(l)
intens_offset_range_upper = float(h)
except ValueError:
print('Invalid intens_offset_range format; should be float:float')
return
return intens_scale_range_lower, intens_scale_range_upper, intens_offset_range_lower, intens_offset_range_upper
def colon_separated_range(x):
lower = upper = None
if x != '':
if ':' not in x:
print('Invalid range format; should be float:float')
return
l, _, h = x.partition(':')
try:
lower = float(l)
upper = float(h)
except ValueError:
print('Invalid range format; should be float:float')
return
return lower, upper
def ensure_containing_dir_exists(path):
dir_name = os.path.dirname(path)
if dir_name != '' and not os.path.exists(dir_name):
os.makedirs(dir_name)
return path