手把手的深度學習實務
預先下載
Anaconda3-4.3.1 安裝 (Windows 10, tensorflow)
- 安裝 anaconda3-4.3.1
- 使用管理者權限開啟 anaconda prompt
- (以下都在 anaconda prompt 下)
- 輸入 conda create -n tensorflow python=3.5
- 輸入 activate tensorflow
- (二擇一)輸入 pip install tensorflow (無 CUDA 支援的 GPU)
- (二擇一)輸入 pip install tensorflow-gpu (有 CUDA 支援的 GPU)
- 在 python 內利用此程式測試:
import tensorflow as tf
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print (sess.run(c))
- 輸入 conda install numpy scipy mingw libpython
- 輸入 pip install keras
- 在 python 內測試 keras:
Anaconda2-4.3.1 安裝 (Windows 10, theano)
- 安裝 anaconda2-4.3.1
- 使用管理者權限開啟 anaconda prompt
- 在 anaconda prompt 下,輸入 conda install numpy scipy mingw libpython theano
- (設定 configuration,設定內容請參考 windows_setup.pdf)
- 設定 Theano configuration (路徑C:\Users\[USER NAME]\.theanorc.txt)
- 輸入 pip install keras
- 設定 Keras configuration (路徑C:\Users\[USER NAME]\.keras\keras.json),第一次安裝要先在 python 底下輸入 import keras,才會自動產生。
- (添加 Windows 環境變數)
- PYTHONPATH:C:\Anaconda2\Lib\site-packages\theano
- PATH:C:\Anaconda2\MinGW\bin;C:\Anaconda2\MinGW\x86_64-w64-mingw32\lib
- 請試跑 CNN 測試程式
GPU 安裝 (需要 NVIDIA 顯示卡)
在 Windows 10 安裝 CUDA8.0 & cuDNN5.1 可以參考下列網址
- 安裝 CUDA&Theano
- 安裝 cuDNN
在 ubuntu 上安裝可以參考下列影片
沒有 GPU 的折衷方案 (Windows 10, OpenBLAS CPU 加速)
需要的 libraries
- pip(3) install scipy
- pip(3) install numpy
- pip(3) install mingw
- pip(3) install libpython
- pip(3) install pillow (存圖用)
- pip(3) install h5py (儲存 model)
- pip(3) install future
- pip(3) install matplotlib
Python2 vs. Python3
- Python3 需將 print function ,添加上左右括號
- Python3 需將 unpickle function 改為
def unpickle(file):
import pickle
fo = open(file, 'rb')
dict = pickle.load(fo, encoding='latin1')
fo.close()
return dict
參考資料
Slides