2018年7月29日 星期日

用 Putty 登入 AWS EC2 instance 的私鑰轉換


當用 AWS EC2 產生 Ubuntu (如 16.04 LTS) 的 instance 時,同時選擇使用新的 key 產生,並下載 .pem 的 key 檔。

首先需要了解 PuTTY本身不支持Amazon EC2生成的私鑰格式(.pem),需要使用 PuTTY 所附的工具 PuTTYgen 進行轉換。



進入 PuTTYgen 之後,選擇 Load,將從 AWS 下載的 .pem 檔載進來。



載入後,輸入 passphrase 兩次加強保護,之後選擇  Save private key,產生 PuTTY適用的 key 檔。



進入 PuTTY 除了一般須入的 host name / ip 以外,選擇 SSH --> Auth,將剛剛轉出來的 .ppk key 檔載入即可。

連結後,login account 為 ubuntu,密碼為剛剛所加強保護的 passphrase。

2018年7月24日 星期二

Windows 的 wget

Linux 上我們常用 wget, 那麼在 windows 上呢?

答案是一樣有東西可用! GNU 的  wget 事實上也有 support Windows (試 Windows 10)

站點
http://gnuwin32.sourceforge.net/packages/wget.htm

選 " Complete package, except sources"

或直接下載連結
https://sourceforge.net/projects/gnuwin32/?source=typ_redirect

安裝好,加完系統路徑,



重開 cmd.exe,就可以用了。



安裝優化 Tensorflow GPU相關功能 (Cuda)

問題: 出現 "Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2" 或其他未優化狀況,此為 tensorflow僅使用一般指令集,而未對目前平台新的指令集做優化。

解決方法:

1. 自己動手做

- Windows
https://software.intel.com/zh-cn/articles/tutorial-for-compiling-tensorflow-on-windows

人生苦短,沒有作。

2. 使用別人編譯好的包

- Linux

進去選相關的包
https://github.com/mind/wheels

在自己的虛擬環境
pip --no-cache-dir install https://github.com/mind/wheels/releases/download/{RELEASE}/{WHEEL}

- Windows

進去下載自己需要的包,到虛擬環境的目錄下
https://github.com/fo40225/tensorflow-windows-wheel


在自己的虛擬環境裡安裝
pip --no-cache-dir install 包的名字(如 tensorflow_gpu-1.9.0-cp36-cp36m-win_amd64.whl)


3. 試試看進 python 直譯器

import tensorflow as tf

- 錯誤排除

如出現 "ImportError: Could not find 'cudart64_92.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 9.2 from this URL: https://developer.nvidia.com/cuda-toolkit"

乖乖去裝一下 https://developer.nvidia.com/cuda-toolkit

- 錯誤排除

ImportError: Could not find 'cudnn64_7.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and this DLL is often found in a different directory from the CUDA DLLs. You may install the necessary DLL by downloading cuDNN 7 from this URL: https://developer.nvidia.com/cudnn

乖乖去裝一下  https://developer.nvidia.com/cudnn

傳回來是一個壓縮檔
解壓縮到 (我在上面已經重裝了 cuda 9.2, 所以這邊也 copy 進 cuda 9.2 喔)
  1. Copy \cuda\bin\cudnn64_7.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\bin.
  2. Copy \cuda\ include\cudnn.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\include.
  3. Copy \cuda\lib\x64\cudnn.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\lib\x64.
參考文章: https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html


然後,就大功告成。


4. 運作看看


# 新建一個 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) 

# 新建session with log_device_placement 並設為 True. 
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) 

# 運行這個 op.
print(sess.run(c))

剛開始卡了一下,但還是跑完。

注意裡面已經開始使用 GPU了,如: 
MatMul: (MatMul): /job:localhost/replica:0/task:0/device:GPU:0 

終於成功了。

2018年7月12日 星期四

Python 3.6 自行安裝方式

Python 3.6 自行安裝方式(Ubuntu 16.04)

當 apt-get 無法安裝,版本太新、或要安裝特定版本時,可以採用以下安裝方式。

首先到 Python.org 的原始碼下載點 (https://www.python.org/ftp/python)
很多版本可供選擇,選擇一個自己要下載的版本,我這邊選擇了 3.6.6,點入將其檔案連結點複製起來。

右鍵選擇複製連結。

$ wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
$ tar xJf Python-3.6.6.tar.xz
$ cd Python.3.6.6
$ ./configure
$ make
$ sudo make install


產生出來的執行檔名稱是 python3.6

Pip 發生無法 SSL 連線

如果遇到,pip 運作的時候,產生 "pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available." 之類的錯誤訊息。

則先安裝
$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-de

再依照上述步驟重新安裝一次即可。