【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

發佈了54 篇原創文章 · 獲贊 454 · 訪問量 106萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章