Tensorflow总结

1、查看device信息

import os

import tensorflow as tf

# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

a = tf.constant([1., 2., 3.], shape=[3], name='a')
b = tf.constant([1., 2., 3.], shape=[3], name='b')
c = a + b

# # 通过log_device_placement参数来输出运行每一个运算的设备。
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' # 只显示 warning 和 Error 
os.environ["TF_CPP_MIN_LOG_LEVEL"]='3' # 只显示 Error  

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)  # 将bytes 转为 str
print(data) # 你好

b = "你好"
bys = tf.compat.as_bytes(b)  # 将str 转为 bytes
print(bys) # b'\xe4\xbd\xa0\xe5\xa5\xbd'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值