【TensorFlow | 升级】TensorFlow 1.0 发布

前面写了 TensorFlow 在Windows上的安装教程,当时版本还是 0.12 。

NOW

首届 TensorFlow 开发者大会(TensorFlow Dev Summit)已于美国时间昨日召开,YouTube 还进行了直播。更重要的是,TensorFlow 1.0 版本发布。Google Research Blog 也于昨天在 博客 中公布了这一消息。

这里写图片描述


改动

这一版本的改动还是比较大的,很多旧的 API 都已经不再使用。在 博客 中可以看到 1.0 版本更快、更灵活、更稳定(production-ready) 。TensorFlow 1.0 版本保证 Python API 的稳定性,即使以后添加新的特性也不用担心会破坏现有代码。

博客中提到的其他新版本两点(为避免翻译造成的偏差,我就直接引用原文了):

  • Python APIs have been changed to resemble NumPy more closely. For this and other backwards-incompatible changes made to support API stability going forward, please use our handy migration guide and conversion script.
  • Experimental APIs for Java and Go
  • Higher-level API modules tf.layers, tf.metrics, and tf.losses - brought over from tf.contrib.learn after incorporating skflow and TF Slim
  • Experimental release of XLA, a domain-specific compiler for TensorFlow graphs, that targets CPUs and GPUs. XLA is rapidly evolving - expect to see more progress in upcoming releases.
  • Introduction of the TensorFlow Debugger (tfdbg), a command-line interface and API for debugging live TensorFlow programs.
  • New Android demos for object detection and localization, and camera-based image stylization.
  • Installation improvements: Python 3 docker images have been added, and TensorFlow’s pip packages are now PyPI compliant. This means TensorFlow can now be installed with a simple invocation of pip install tensorflow.

升级

升级很简单(在这里感谢一下为简化 TensorFlow 安装过程的工程师们),就是一行语句,这也是安装命令:

对于 GPU 版本:

pip3 install --upgrade tensorflow-gpu

对于 CPU 版本:

pip3 install --upgrade tensorflow

升级过程
右键在新标签页打开图片可查看大图

输入完回车就开始升级过程,会下载并卸载重装一些必要的包,时间长短视网速而定。


更新你的旧代码

有两种方法更新你的代码,一种就是我上面提到的用脚本自动升级,另一种就是手动更改,具体可以参考 这里

使用脚本

由于版本改动较大,TensorFlow 甚至出了一个 tf_upgrade.py 脚本来帮助你更新代码,从 这里 获取这份代码,或者点击 这里 直接下载。

对于更新单个文件,可以使用下面的命令:

python tf_upgrade.py --infile InputFile --outfile OutputFile

其中 InputFileOutputFile 分别为你的旧代码和新代码,根据你的文件名做相应的替换。例如我的旧代码是 test.py,将要生成的新代码是 test_1.0.py,则:

python tf_upgrade.py --infile test.py --outfile test_1.0.py

同时,tf_upgrade.py 会生成一个名为 report.txt 的文件,该文件记录了对旧文件做的所有改动,同时也给出了可能需要你手动更改的建议。

对于文件夹(目录),和单个文件类似,使用

python tf_upgrade.py --intree InputDir --outtree OutputDir

例如,我的 programs 位于 /home/user/cool 目录,新的生成的文件我想放到 /home/user/cool_1.0 里,则

python tf_upgrade.py --intree /home/user/cool --outtree /home/user/cool_1.0

手动更改

除了使用脚本自动更新外,还可以使用手动替换的方式。需要替换的东西有很多,我就不一一列举了,大家可以参考 官网


END

发布了55 篇原创文章 · 获赞 467 · 访问量 108万+

猜你喜欢

转载自blog.csdn.net/u010099080/article/details/55260055