2016년 3월 16일 수요일

(Windows) keras 설치

Backend를 Theano로 사용하므로 아래 설명은 theano설치도 포함한다.

먼저, cuda(v7.5), vs2013, git설치
git은 설치 중 옵션에서 "Run Git from the WIndows command prompt" 선택

TDM GCC x64 설치
Anaconda x64 설치

cmd 창을 관리자 모드로 연다(방법은 아래).
(or open Anaconda prompt)
conda update conda
conda update --all
conda install mingw libpython

Install latest version of Theano
git clone git://github.com/Theano/Theano.git
(or pip install git+git://github.com/Theano/Theano.git)
cd Theano
python setup.py develop

Install keras
git clone https://github.com/fchollet/keras
(pip install keras)
cd keras
python setup.py develop

Test
cd examples
ipython mnist_mlp.py


제어판->시스템->고급시스템설정->환경변수->사용자변수에 가서
PATH 변수에 cuda의 nvcc가 있는 bin폴더 추가
THEANO_FLAGS 변수 만들고 다음 사항 추가
"floatX=float32,device=gpu,nvcc.fastmath=True"


cmd 창을 관리자 모드로 여는법
시작->프로그램 및 파일검색
cmd 입력
리스트에 나타난 cmd를 클릭해서 “관리자모드로 시작”.


설치를 확인하는 법
cmd창에서 
where cl
where gcc
where nvcc
where g++


cuDNN을 같이 설치하면 학습 속도가 더욱 빨라진다. 
nvidia에서 cuDNN 4.0을 다운 받아 압축을 풀면 bin, include, lib의 3개의 폴더가 있다. 
내부의 파일들을   
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5
아래의 해당 위치에 옮겨주면 된다.



출처:
1. Setup a Deep Learning Environment on Windows (Theano & Keras with GPU Enabled)
2. How to install Keras and Theano in Anaconda Python 2.7 in Windows
3. FunMV
4. Installing Keras, Theano and Dependencies on Windows 10












댓글 16개:

  1. 설치 후 한동안 잘 사용하다가 anaconda를 upgrade 후에 theano의 gpu 컴파일 오류가 발생하였다.
    해결 방법으로는 사용자 폴더에 있는 ".theanorc.txt" 파일을 수정하고 해결하였다.

    ===========================
    [global]
    device = gpu
    floatX = float32

    [nvcc]
    flags=--use-local-env --cl-version=2013
    compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin
    ===========================

    상기 파일 내용 중에
    flags=--use-local-env --cl-version=2013

    를 제거 후에
    flags=-L"d:\Anaconda2\libs"

    로 치환하였다. 이 flags는 새로 설치한 Anaconda의 설치 경로이다.

    답글삭제
  2. windows10 (64bit) 설치에는 git, vs2013 설치 후에 가상환경(python 2.7) 만들고, theano 설치 후에 keras 설치하면 된다. c:/ 디스크로 가서,
    >cd %USERPROFILE%
    >md .keras
    .keras아래에 keras.json파일을 수정해 주어야 한다. 디폴트 백엔드가 tensorflow로 되어 있어, theano로 바꾸어 주어야 한다.
    (출처) http://ankivil.com/installing-keras-theano-and-dependencies-on-windows-10/

    답글삭제
    답글
    1. keras.json:
      {
      "floatx": "float32",
      "epsilon": 1e-07,
      "image_dim_ordering": "th",
      "backend": "theano"
      }

      삭제
  3. windows 10에서 tensorflow backend로 keras 설치
    (출처) How to install TensorFlow, Theano, Keras on Windows 10 with Anaconda
    https://groups.google.com/forum/#!topic/keras-users/_hXfBOjXow8

    (1) cuda, cudnn, anaconda 설치
    (2) conda create -n dev35 python=3.5 anaconda
    (3) activate dev35
    (4) conda install numpy, matplotlib, scipy, scikit-learn
    (5) pip install tensorflow-gpu
    (6) conda install mingw libpython
    (7) conda install theano
    (8) pip install keras
    (9) conda update jupyter

    jupyter notebook 실행 오류 나면 실행 폴더 바꾸어 재 실행



    (원문)
    As a newb who just spend a weekend figuring this out, here is a recipe for other newbs that works as of mid January 2017 (no doubt things will change over time, but it's already much easier than a few months ago now that TensorFlow is available as a simple pip install on Windows):


    install cuda, cuDNN if GPU
    install anaconda if not already there

    from anaconda command prompt:
    update conda and update conda-build (as of Jan 2017 required to build qt correctly, may be fixed later)
    create conda env python=3.5
    conda install numpy, matplotlib, scipy, scikit-learn (last is optional)
    pip install tensorflow gpu (using URL on TensorFlow web site, Windows pip install section)
    conda install mingw libpython (theano dependencies)
    conda install theano (apparently no gpu yet via pip install)
    conda install keras dependencies – in particular, need to install theano even if using tensorflow backend because pip install keras will try to install theano if not already installed (and something may break during this process); also install pyyaml, HDF5 and h5py
    pip install keras (will install with tensorflow as backend by default)

    No module named keras theano errors on attempt to import in notebook caused by failure of jupyter to install correctly in conda env, corrected by updating conda-build then reinstalling jupyter in the env

    답글삭제
    답글
    1. conda install numpy, matplotlib, scipy, scikit-learn
      에서 중간에 ','은 다 빼야 함

      삭제
    2. keras를 낮은 버전으로 설치 시에는
      >pip install keras==1.2.2

      삭제
  4. [OpenCV 설치]
    windows10 + anaconda + python 3.5 + tensorflow-backend + keras 환경에서 opencv를 설치하기 위해 여러번 시도하다 실패 후,

    http://stackoverflow.com/questions/23119413/how-to-install-python-opencv-through-conda

    를 참고해서
    > conda install --channel https://conda.anaconda.org/menpo opencv3

    로 설치하였다. 원래 Ubuntu에서 실행되었다고 했으나 그냥 설치 하였음.
    여전히 작동하지 않아,
    >pip uninstall opencv-python

    으로 기존 설치해 준 opencv-python을 제거해 보았다.

    정상적으로 설치되었고
    import cv2
    cv2.__version__

    헤보니 버전이 3.1.1 이었다.

    답글삭제
    답글
    1. anaconda python 3.6에서 다음 명령으로 설치(버전 3.4):
      > conda install -c conda-forge opencv
      https://www.scivision.co/install-opencv-python-windows/

      삭제
    2. [Opencv 설치 새로운 방법]
      (1) http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
      에 들어가서 opencv_python-3.4.1-cp36-cp36m-win_amd64.whl 파일을 다운 받는다.
      (2) pip install ~.whl로 설치
      (3) numpy-1.14.3+mkl-cp36-cp36m-win_amd64.whl 파일을 다운 받는다. 버전 유의.
      (4) pip install ~.whl로 설치

      삭제
  5. [pyqt4 설치]
    anaconda3, py35에서는 default가 pyqt5이다. 몇가지 호환성 문제로 pyqt4를 설치하려고 하면, 먼저 pyqt버전이 뭐가 있는지 검색하고,
    > conda search pyqt

    필요한 버전을 설치하면 된다.
    > conda install -c anaconda pyqt=4.11.4

    답글삭제
    답글
    1. (참고) http://stackoverflow.com/questions/21637922/how-to-install-pyqt4-in-anaconda

      삭제
  6. [matplotlib.pyplot 설치]
    증상: anaconda3+py35+tf+keras 설치 후 matplotlib.pyplot가 설치되지 않는다(font 문제인것 같음)
    해결: pyqt5->pyqt4로 downgrade하게 되면 설치 과정 중에
    ...
    matplotlib: 2.0.0-np111py35_0 --> 1.5.1-np111py35_0 anaconda
    ...
    처럼 matplotlib를 다운그레이드하는 부분이 있어서 혹시나 하고 stackoverflow를 찾아보니
    Error on import matplotlib.pyplot (on Anaconda3 for Windows 10 Home 64-bit PC)
    처럼 해결하는 부분이 있었다. 이 부분을 참고해서 C:\Users\Anaconda3\envs\py35\Lib\site-packages\matplotlib
    아래에 있는 font_manage.py파일의 win32InstalledFonts()함수 내에 있는 부분을 수정하였다.
    direc = os.path.abspath(direc).lower() -->
    direc = direc.split('\0',1)[0]



    (참고) http://stackoverflow.com/questions/34004063/error-on-import-matplotlib-pyplot-on-anaconda3-for-windows-10-home-64-bit-pc



    답글삭제
  7. windows10 pytorch 설치
    ----------------------
    [참고] https://github.com/peterjc123/pytorch-scripts

    >conda create -n pytorch36 python=3.6
    >activate pytorch36
    >conda install -c peterjc123 pytorch cuda90
    >python
    import torch
    x=torch.rand(5,3)
    print(x)

    # 제거 시는 conda remove -n yourenvname --all

    >conda install graphviz
    >pip install -r requirements.txt
    #requirements.txt: ipdb tqdm scipy imageio tensorboardX

    답글삭제
  8. windows10 1803버전에서 cuda설치
    -------------------------------
    장치관리자->디스플레이아답터->속성->드라이브엡뎃->컴퓨터에서 드라이버검색->컴목록에서 직접 선택->MS기본 디스플레이어댑터
    이것으로 선정하고, nvidia driver, cuda 등을 모두 삭제 후 다시 설치.

    답글삭제
    답글
    1. tensorflow 설치 후, import tensorflow했을 때,
      D:\Anaconda3\envs\dev35\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
      from ._conv import register_converters as _register_converters

      와 같은 오류 발생 시에
      >pip install h5py==2.8.0rc1
      로 해결하였음.

      삭제
  9. windows10에서 tensorflow 설치
    -----------------------------
    cuda 9.0, cudnn 7.1에서 tensorflow 1.8 설치.
    whl파일을 통한 설치.

    pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.8.0-cp35-cp35m-win_amd64.whl

    1.8.0은 tf 버전 표시이고 cuda9.0, cudnn 1.7에는 이버전이 잘 맞았음.
    cp35-cp35m은 python version에 대한 것인데 3.6버전에 설치할 때는 이것을 수정해야 한다.

    답글삭제