|
5 | 5 |
|
6 | 6 |
|
7 | 7 | import tensorflow as tf |
| 8 | +import tensorlayer as tl |
8 | 9 | import os |
| 10 | +import subprocess |
9 | 11 | import sys |
10 | 12 | from sys import platform as _platform |
| 13 | +from sys import exit as _exit |
11 | 14 |
|
12 | 15 |
|
13 | | -def exit_tf(sess=None): |
14 | | - """Close tensorboard and nvidia-process if available |
| 16 | +def exit_tf(sess=None, port=6006): |
| 17 | + """Close tensorflow session, tensorboard and nvidia-process if available |
15 | 18 |
|
16 | 19 | Parameters |
17 | 20 | ---------- |
18 | 21 | sess : a session instance of TensorFlow |
19 | 22 | TensorFlow session |
| 23 | + tb_port : an integer |
| 24 | + TensorBoard port you want to close, 6006 is tensorboard default |
20 | 25 | """ |
21 | 26 | text = "[tl] Close tensorboard and nvidia-process if available" |
22 | | - sess.close() |
| 27 | + text2 = "[tl] Close tensorboard and nvidia-process not yet supported by this function (tl.ops.exit_tf) on " |
| 28 | + if sess != None: |
| 29 | + sess.close() |
23 | 30 | # import time |
24 | 31 | # time.sleep(2) |
25 | 32 | if _platform == "linux" or _platform == "linux2": |
26 | 33 | print('linux: %s' % text) |
27 | 34 | os.system('nvidia-smi') |
28 | | - os.system('fuser 6006/tcp -k') # kill tensorboard 6006 |
| 35 | + os.system('fuser '+ port +'/tcp -k') # kill tensorboard 6006 |
29 | 36 | os.system("nvidia-smi | grep python |awk '{print $3}'|xargs kill") # kill all nvidia-smi python process |
| 37 | + _exit() |
30 | 38 | elif _platform == "darwin": |
31 | 39 | print('OS X: %s' % text) |
32 | | - os.system("lsof -i tcp:6006 | grep -v PID | awk '{print $2}' | xargs kill") # kill tensorboard 6006 |
| 40 | + subprocess.Popen("lsof -i tcp:"+ str(port) +" | grep -v PID | awk '{print $2}' | xargs kill", shell=True) # kill tensorboard |
33 | 41 | elif _platform == "win32": |
34 | | - print('Windows: %s' % text) |
| 42 | + print(text2 + "Windows") |
| 43 | + # TODO |
35 | 44 | else: |
36 | | - print(_platform) |
37 | | - exit() |
| 45 | + print(text2 + _platform) |
| 46 | + |
| 47 | +def open_tb(logdir='/tmp/tensorflow', port=6006): |
| 48 | + """Open tensorboard |
| 49 | + |
| 50 | + Parameters |
| 51 | + ---------- |
| 52 | + logdir : a string |
| 53 | + Directory where your tensorboard logs are saved |
| 54 | + port : an integer |
| 55 | + TensorBoard port you want to open, 6006 is tensorboard default |
| 56 | + """ |
| 57 | + |
| 58 | + text = "[tl] Open tensorboard, go to localhost:" + str(port) + " to access" |
| 59 | + text2 = " not yet supported by this function (tl.ops.open_tb)" |
| 60 | + |
| 61 | + if not tl.files.exists_or_mkdir(logdir, verbose=False): |
| 62 | + print("[tl] Log reportory was created at %s" % logdir) |
| 63 | + |
| 64 | + if _platform == "linux" or _platform == "linux2": |
| 65 | + print('linux %s' % text2) |
| 66 | + # TODO |
| 67 | + elif _platform == "darwin": |
| 68 | + print('OS X: %s' % text) |
| 69 | + subprocess.Popen(sys.prefix + " | python -m tensorflow.tensorboard --logdir=" + logdir + " --port=" + str(port), shell=True) # open tensorboard in localhost:6006/ or whatever port you chose |
| 70 | + elif _platform == "win32": |
| 71 | + print('Windows%s' % text2) |
| 72 | + # TODO |
| 73 | + else: |
| 74 | + print(_platform + text2) |
38 | 75 |
|
39 | 76 | def clear_all(printable=True): |
40 | 77 | """Clears all the placeholder variables of keep prob, |
|
0 commit comments