dennistrujillo commited on
Commit
31861e5
·
1 Parent(s): edee4ad

added util.py

Browse files
Files changed (1) hide show
  1. util.py +18 -0
util.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import torch, argparse
3
+
4
+ def str2bool(v):
5
+ if isinstance(v, bool):
6
+ return v
7
+ if v.lower() in ('yes', 'true', 't', 'y', '1'):
8
+ return True
9
+ elif v.lower() in ('no', 'false', 'f', 'n', '0'):
10
+ return False
11
+ else:
12
+ raise argparse.ArgumentTypeError('Boolean value expected.')
13
+
14
+ def str2tuple(s):
15
+ return tuple(s.split('_'))
16
+
17
+ def s2ituple(s):
18
+ return tuple(int(_s) for _s in s.split('_'))