• 报错记录TensorFlow


    运行代码之后,控制台除了输出应该有的结果外,还多了一行:
    I T:srcgithub ensorflow ensorflowcoreplatformcpu_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)
    

      

    InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'shuffle_batch': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.

    with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
    

      

  • 相关阅读:
    XMLHttpRequest 跨域问题
    jQuery+AJAX实现纯js分页功能
    PHP验证码
    PHP基础
    UIView易忽略点
    UITableView  优化
    SpringBoard界面层级结构分析
    给App在“设置”中添加选项(类似招行App)
    通过USB线SSH登陆到越狱手机上(命令行模式的),不通过wifi
    在IOS项目中使用Lua
  • 原文地址:https://www.cnblogs.com/blogwangwang/p/11566693.html
Copyright © 2020-2023  润新知