flpelerin commited on
Commit
c6541c4
·
1 Parent(s): 0b696e1

Update 2 files

Browse files

- /util.py
- /wandb.py

Files changed (2) hide show
  1. util.py +12 -0
  2. wandb.py +25 -0
util.py CHANGED
@@ -1,6 +1,18 @@
1
  import json
 
 
2
 
3
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  class Config:
6
  def __init__(self, data):
 
1
  import json
2
+ import math
3
+ import random
4
 
5
 
6
+ def RandomCode():
7
+ code = '';
8
+ chars = '0123456789abcdef'
9
+ count = 8;
10
+
11
+ for i in range(0, count):
12
+ code += chars[math.floor(random.randrange(len(chars)))]
13
+
14
+ return code
15
+
16
 
17
  class Config:
18
  def __init__(self, data):
wandb.py CHANGED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import wandb
2
+
3
+
4
+ from util import Config, RandomCode
5
+
6
+
7
+
8
+ class Wandb:
9
+ def __init__(self, config: Config):
10
+ if config.entity is None or config.project is None or config.api_key is None:
11
+ raise ValueError('Missing required values for either Entity, Project or API Key')
12
+
13
+ if config.name == '':
14
+ config.name = 'run-' + RandomCode()
15
+
16
+ os.environ['WANDB_API_KEY'] = api_key
17
+ wandb.init(project, entity, name)
18
+
19
+
20
+ def __call__(self, args):
21
+ wandb.log(args)
22
+
23
+
24
+ def __del__(self):
25
+ wandb.finish()