1. 程式人生 > >吳恩達deeplearning課程作業環境

吳恩達deeplearning課程作業環境

Deep learning課程安裝

Course 4 prerequisites:
- 2017/2/14 keras /pydot / graphviz
- 2017/2/20 pandas for week 3
- 2017/2/23 opencv for week 4

conda安裝

unbuntu 16
pyhton 3.6版本 miniconda

sudo apt-get update

bash Miniconda3-latest-Linux-x86_64.sh
# 安裝位置 /home/ubuser/miniconda3

重啟Terminal

基礎庫

建立virtualenv環境deeplearn,並且安裝相應的包。(好像漏掉了conda create -n tensorflow python=2.7 # or python=3.3, etc.

)

conda config --prepend channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ #使用國內源,清華或者豆瓣

mkdir DeepLearning
cd DeepLearning/

conda install -n deeplearn numpy
conda install -n deeplearn jupyter
conda install -n deeplearn matplotlib
conda install -n deeplearn h5py

# 為了支援PIL,PIL官方只支援python 2.xconda install -n deeplearn pillow 
#sklearn conda install -n deeplearn scikit-learn conda install -n deeplearn pandas #cv2 conda install -n deeplearn opencv

pip 國內源使用方法

永久修改
linux下,修改 ~/.pip/pip.conf
windows下,直接在user目錄中建立一個pip目錄,如:C:\Users\xx\pip,新建檔案pip.ini,

安裝TensorFlow

Take the following steps to install TensorFlow in an Anaconda environment:

  1. Follow the instructions on the Anaconda download site to download and install Anaconda.

  2. Create a conda environment named tensorflow to run a version of Python by invoking the following command:

    $ conda create -n tensorflow python=2.7 # or python=3.3, etc.

  3. Activate the conda environment by issuing the following command:

    $ **source activate tensorflow
    (tensorflow)$  # Your prompt should change
  4. Issue a command of the following format to install TensorFlow inside your conda environment:

    (tensorflow)$ pip install --ignore-installed --upgrade tfBinaryURL

    where tfBinaryURL is the URL of the TensorFlow Python package. For example, the following command installs the CPU-only version of TensorFlow for Python 3.4:

    (tensorflow)$ pip install --ignore-installed --upgrade\
     https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.4.0-cp34-cp34m-linux_x86_64.whl

從清華頁面獲得安裝引數(在虛機內,簡單期間使用CPU版。GPU的依賴見官方安裝說明)

pip install \
  -i https://pypi.tuna.tsinghua.edu.cn/simple/ \
  https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/cpu/tensorflow-1.4.1-cp36-cp36m-linux_x86_64.whl

正式使用安裝命令(在相應的venv下執行)

 pip install --ignore-installed --upgrade\
     -i https://pypi.tuna.tsinghua.edu.cn/simple/ \
     https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/cpu/tensorflow-1.4.1-cp36-cp36m-linux_x86_64.whl

TensorFlow其他資料

1) 如果出現警告 “RuntimeWarning: compiletime version 3.5 of module ‘tensorflow.python.framework.fast_tensor_util’ does not match runtime version 3.6”, 可以嘗試從https://github.com/lakshayg/tensorflow-build安裝。這個警告截至到2017/12/18沒有官方解決方案。可以不管這個警告繼續執行。迴避的方式是把python改成3.5或者自己重編譯。

2) 未經測試的安裝方式

 $ pip install tensorflow      # Python 2.7; 僅支援CPU
 $ pip3 install tensorflow     # Python 3.n; 僅支援CPU
 $ pip install tensorflow-gpu  # Python 2.7; 支援CPU
 $ pip3 install tensorflow-gpu # Python 3.n; 支援CPU
# Python 3.6
pip install https://anaconda.org/intel/tensorflow/1.4.0/download/tensorflow-1.4.0-cp36-cp36m-linux_x86_64.whl
# Python 2.7
pip install https://anaconda.org/intel/tensorflow/1.4.0/download/tensorflow-1.4.0-cp27-cp27mu-linux_x86_64.whl

文章裡還提供了修改venv配置和使用intel版numpy的方法。

單純安裝intel tensorflow在vmware虛機內,效能不會改善。

其他開源包

  • keras / pydot
    course 4 week 02 作業
pip install keras
pip install pydot

pydot需要graphviz支援,沒有的話,會出現這個錯誤 “FileNotFoundError: [Errno 2] No such file or directory: ‘dot’”

sudo apt-get install graphviz 

安裝測試

TensorFlow測試

# Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

使用測試

source activate deeplearn

jupyter notebook

進入notebook環境

import numpy as np
A = np.array([[1, 2], [3, 4]])
print(A)

從主機訪問虛擬機器

如果ssh對映到本地,參考文件

bivisw裡面配置C2S埠對映(port forwording)
Listen interface/port是主機的
Destination host/port是虛擬機器的

兩個IP可以都是127.0.0.1或者localhost
虛擬機器的埠是8888(notebook預設埠),主機埠任意。

另外一種方法,直接改變監聽的IP

jupyter notebook --help 

jupyter notebook --ip=0.0.0.0 # listen all network interface

To see a list of all packages installed in a specific environment:

  • If the environment is not activated:

    conda list -n myenv

  • If the environment is activated:

    conda list

匯出Export your active environment to a new file:

conda env export > environment.yml

name: deeplearn
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
dependencies:
- bleach=1.5.0=py36_0
- certifi=2016.2.28=py36_0
- cycler=0.10.0=py36_0
- dbus=1.10.20=0
- decorator=4.1.2=py36_0
- entrypoints=0.2.3=py36_0
- expat=2.1.0=0
- fontconfig=2.12.1=3
- freetype=2.5.5=2
- glib=2.50.2=1
- gst-plugins-base=1.8.0=0
- gstreamer=1.8.0=0
- h5py=2.7.0=np112py36_0
- hdf5=1.8.17=2
- html5lib=0.9999999=py36_0
- icu=54.1=0
- ipykernel=4.6.1=py36_0
- ipython=6.1.0=py36_0
- ipython_genutils=0.2.0=py36_0
- ipywidgets=6.0.0=py36_0
- jbig=2.1=0
- jedi=0.10.2=py36_2
- jinja2=2.9.6=py36_0
- jpeg=8d=2
- jsonschema=2.6.0=py36_0
- jupyter=1.0.0=py36_3
- jupyter_client=5.1.0=py36_0
- jupyter_console=5.2.0=py36_0
- jupyter_core=4.3.0=py36_0
- libffi=3.2.1=1
- libgcc=5.2.0=0
- libgfortran=3.0.0=1
- libiconv=1.14=0
- libpng=1.6.30=1
- libsodium=1.0.10=0
- libtiff=4.0.6=2
- libxcb=1.12=1
- libxml2=2.9.4=0
- markupsafe=1.0=py36_0
- matplotlib=2.0.2=np112py36_0
- mistune=0.7.4=py36_0
- mkl=2017.0.3=0
- nbconvert=5.2.1=py36_0
- nbformat=4.4.0=py36_0
- notebook=5.0.0=py36_0
- numpy=1.12.1=py36_0
- olefile=0.44=py36_0
- opencv=3.1.0=np112py36_1
- openssl=1.0.2l=0
- pandas=0.20.3=py36_0
- pandocfilters=1.4.2=py36_0
- path.py=10.3.1=py36_0
- pcre=8.39=1
- pexpect=4.2.1=py36_0
- pickleshare=0.7.4=py36_0
- pillow=3.4.2=py36_0
- pip=9.0.1=py36_1
- prompt_toolkit=1.0.15=py36_0
- ptyprocess=0.5.2=py36_0
- pygments=2.2.0=py36_0
- pyparsing=2.2.0=py36_0
- pyqt=5.6.0=py36_2
- python=3.6.2=0
- python-dateutil=2.6.1=py36_0
- pytz=2017.2=py36_0
- pyzmq=16.0.2=py36_0
- qt=5.6.2=2
- qtconsole=4.3.1=py36_0
- readline=6.2=2
- scikit-learn=0.19.0=np112py36_0
- scipy=0.19.1=np112py36_0
- setuptools=36.4.0=py36_1
- simplegeneric=0.8.1=py36_1
- sip=4.18=py36_0
- six=1.10.0=py36_0
- sqlite=3.13.0=0
- terminado=0.6=py36_0
- testpath=0.3.1=py36_0
- tk=8.5.18=0
- tornado=4.5.2=py36_0
- traitlets=4.3.2=py36_0
- wcwidth=0.1.7=py36_0
- wheel=0.29.0=py36_0
- widgetsnbextension=3.0.2=py36_0
- xz=5.2.3=0
- zeromq=4.1.5=0
- zlib=1.2.11=0
- pip:
  - enum34==1.1.6
  - ipython-genutils==0.2.0
  - jupyter-client==5.1.0
  - jupyter-console==5.2.0
  - jupyter-core==4.3.0
  - keras==2.1.3
  - markdown==2.6.10
  - prompt-toolkit==1.0.15
  - protobuf==3.5.0.post1
  - pydot==1.2.4
  - pyyaml==3.12
  - tensorflow==1.4.1
  - tensorflow-tensorboard==0.4.0rc3
  - werkzeug==0.13
prefix: /home/ubuser/miniconda3/envs/deeplearn