Build caffe, pycaffe and matcaffe on Windows


Download and install the following software's:
  1. Git for Windows:
  2. Visual Studio 2015: To download older versions of visual studio you can go to 
  3. Cmake 3.4 or higher
  4. Python 3.5 Anaconda x64 (Required to build pycaffe).
  5. CUDA 8.0
  6. cuDNN v5.1 (optional)
  7. Matlab (Required to build matcaffe)


  1. Install Cmake and add it to system path.
  2. Install CUDA v8.0 (For GPU support only)
  3. Extract cuDNN (For GPU Support only)
    • copy all files from bin folder to 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin'
    • similarly from include to 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include' 
    • and 'lib/x64' to  ''C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib/x64'.
  4. Optional - Install Anaconda, make sure you select Register Anaconda as system path for Python 3.5 (required to build pycaffe).
  5. Optional - Install and activate Matlab using your Matlab licence (required to build matcaffe).
  6. Open command window in the desired folder "D:\Downloads\caffe" (Shift+RightClick and Open Command Window here).
  7. Enter the following commands
    D:\Downloads\caffe> git clone
    D:\Downloads\caffe> cd caffe
    D:\Downloads\caffe\caffe> git checkout windows
  8. Open scripts folder and edit build_win.cmd
    • set WITH_NINJA=0
    • set PYTHON_VERSION=3
    • set CONDA_ROOT to Anaconda folder, "C:\Program Files\Anaconda3".
    • set BUILD_MATLAB=1
    • Add -CUDNN_ROOT="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0" in cmake configuration in line 170.
  9. Save build_win.cmd and enter following command in command window
    D:\Downloads\caffe\caffe> scripts\build_win.cmd
  10. After successful build enter the following commands to run caffe
    D:\Downloads\caffe\caffe> cd build\tools\Release
    D:\Downloads\caffe\caffe\build\tools\Release> caffe -help
  11. Pycaffe instructions:

  12. Enter the following commands
    D:\Downloads\caffe\caffe\build\tools\Release> cd ..\..\..\
    D:\Downloads\caffe\caffe> conda config --add channels conda-forge
    D:\Downloads\caffe\caffe> conda install ninja --yes
  13. Copy the contents of D:\Downloads\caffe\caffe\python to site-packages folder [C:\Program Files\Anaconda3\]Lib\site-packages.
  14. Now run the following commands:
    D:\Downloads\caffe\caffe> python
    >>> import caffe
  15. You should be able to successfully import and run pycaffe.
  16. Matcaffe instructions:

  17. Enter the following command to download caffe bvlc model
    D:\Downloads\caffe\caffe> python scripts\ models\bvlc_reference_caffenet
  18. Copy caffe_.mexw64 from D:\Downloads\caffe\caffe\matlab\+caffe\private\Release\ to D:\Downloads\caffe\caffe\matlab\+caffe\private.
  19. Add D:\Downloads\caffe\caffe\build\libraries to Matlab Path using setenv() command.
  20. Now you should be able to run classification_demo.m in C:\Projects\caffe\matlab\demo folder.

No comments:

Post a Comment

How to run R code in Python

R is freely available language and computational tool which is very popular among the statisticians and bioinformatics community. In this p...