tensorflow学习笔记

来源:互联网 发布:淘宝宝贝找不到了 编辑:程序博客网 时间:2024/06/08 16:26

tensorflow学习笔记

按照《TensorFlow:实战Google深度学习框架》一书学习的tensorflow,书中使用的是0.9.0版本,而我安装的是1.2.1,出现了一些问题:

  • 1、使用pip安装时出现问题
    • 注意windows系统下安装tensorflow只能使用python3,而我习惯使用python2.7,所以改用了虚拟机Ubuntu系统,并且安装的是仅支持CPU的。如果你使用的whl是googleapis的链接,那么需要VPN才能下载,如果不翻墙,可以使用国内的资源,比如我用的是https://ci.tensorflow.org/view/Nightly/job/nightly-matrix-cpu/TF_BUILD_IS_OPT=OPT,TF_BUILD_IS_PIP=PIP,TF_BUILD_PYTHON_VERSION=PYTHON2,label=cpu-slave/lastSuccessfulBuild/artifact/pip_test/whl/tensorflow-1.2.1-cp27-none-linux_x86_64.whl ,这是个1.2.1版本
  • 2、测试运行时出现很多警告

    • W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn’tcompiled to use SSE4.1 instructions, but these are available on your machineand could speed up CPU computations.

    • W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn’tcompiled to use SSE4.2 instructions, but these are available on your machineand could speed up CPU computations.

    • W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn’tcompiled to use AVX instructions, but these are available on your machine andcould speed up CPU computations.

    • 大概就是这些警告,包裹SSE4.1 SSE4.2 AVX AVX2 FMA等等,这些warings的意思是说:你的机器上有这些指令集可以用,并且用了他们会加快你的CPU运行速度,但是你的TensorFlow在编译的时候并没有用到这些指令集。我的tensorflow在安装的时候采用的pip install指令,这种安装方式会存在这种问题。主要有两种解决方法,一种是修改警告信息的显示级别,使这种信息不再出现,另外一种就是自己重新编译安装tensorflow,在编译的时候使用这些指令集。可以不管,也可以参考http://blog.csdn.net/nicholas_wong/article/details/70215127
  • 3、错误“_init_() got an unexpected keyword argument ‘shape’”

    • 如果按照书上的例子来,因为这本书使用tensorflow是0.9.0版本,而在最新的tensorflow中有很多改动,文章最后会附上这些改动以供参考查看。这里的错误是因为新版tf.zeros_initializer和tf.ones_initializer后面需要加括号,将v = tf.get_variable(“v”,initializer=tf.zeros_initializer(shape=[1]))改为v = tf.get_variable(“v”,initializer=tf.zeros_initializer( )(shape=[1]))就可以了,下面的一样。
  • tf.global_variables_initializer的错误
    • WARNING:tensorflow:: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
      Instructions for updating:
      Use tf.global_variables_initializer instead.
      initialize_all_variables已被弃用,将在2017-03-02之后删除。
      说明更新:使用tf.global_variables_initializer代替。
      就把tf.initialize_all_variables()改为global_variables_initializer()就可以了