报错记录TensorFlow

运行代码之后,控制台除了输出应该有的结果外,还多了一行:
I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

 

 

就是说您当前的CPU可以支持未编译为二进制的指令AVX2
要想消除该提示,需要在代码中添加两行代码:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'



查阅有得知,这行代码是用于设置TensorFlow的日志级别的。
-----------------------------------------------------------------------------------------------------------------------------------------

2.

TensorFlow中出现with tf.Session as sess: AttributeError: __enter__错误解决方法

其实该类问题对于新手(鄙人就是)而言很常见:AttributeError表示所调用对象属性错误,记住Python是面向对象语言,该错误就是Python异常类的错误。

#创建一个会话运行TensorFlow程序
with tf.Session as sess:
init_op = tf.global_variables_initializer()
#初始化变量
sess.run(init_op)

print(sess.run(w1))
print(sess.run(w2))
这段程序会报错,因为调用的是TensorFlow的Session函数,而不是Session变量,所以必须写成tf.Session(),加上括号之后就不会出现编译错误。

with tf.Session() as sess:
init_op = tf.global_variables_initializer()
#初始化变量
sess.run(init_op)

print(sess.run(w1))
print(sess.run(w2))
诸如此类的错误,一定要深刻记住,要调用某一个功能函数要加括号,毕竟你说调用的函数不是一个变量。

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.For reference, the tensor object was Tensor("ExpandDims:0", shape=(1, 28, 28, 1), dtype=float32) which was passed to the feed with key Tensor("input0:0", dtype=float32).

 

 

将Tensor转为array

 lbb=onehot_labels.eval()

  张量直接转列表

即可,因为参数类型不接受张量,接受列表等

 

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Tensorflow中张量数据类型的转换

字符串转为数字:
tf.string_to_number
(string_tensor, out_type=None, name=None)

转为64位浮点类型–float64:
tf.to_double(x, name=’ToDouble’)


转为32位浮点类型–float32:
tf.to_float(x, name=’ToFloat’)


转为32位整型–int32:
tf.to_int32(x, name=’ToInt32’)


转为64位整型–int64:
tf.to_int64(x, name=’ToInt64’)


将x或者x.values转换为dtype
# tensor a is [1.8, 2.2], dtype=tf.float
# tf.cast(a, tf.int32) ==> [1, 2],dtype=tf.int32
tf.cast(x, dtype, name=None)

  

 

转载于:https://www.cnblogs.com/blogwangwang/p/11566693.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值