1、查看device信息
import os
import tensorflow as tf
a = tf.constant([1., 2., 3.], shape=[3], name='a')
b = tf.constant([1., 2., 3.], shape=[3], name='b')
c = a + b
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))
"""
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce 940MX, pci bus id: 0000:02:00.0, compute capability: 5.0
add: (Add): /job:localhost/replica:0/task:0/device:GPU:0
a: (Const): /job:localhost/replica:0/task:0/device:GPU:0
b: (Const): /job:localhost/replica:0/task:0/device:GPU:0
[2. 4. 6.]
"""
2、tensorflow的日志级别
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"]='1'
os.environ["TF_CPP_MIN_LOG_LEVEL"]='2'
os.environ["TF_CPP_MIN_LOG_LEVEL"]='3'
3、tf.compat.as_str 和tf.compat.as_bytes
import tensorflow as tf
a = b'\xe4\xbd\xa0\xe5\xa5\xbd'
data = tf.compat.as_str(a)
print(data)
b = "你好"
bys = tf.compat.as_bytes(b)
print(bys)