Compile MatConvNet on Windows

Matconvnet is a convolutional neural network (CNN) toolbox for Matlab. Being integrated into Matlab it gives you the flexibility to use Matlab built in functions but it's execution time is slightly slower compared to C++ based caffe and other deep learning libraries. In addition, you need Matlab licence to run this library. Similar to other Matlab toolboxes it's relatively easier to compile compared to open source caffe and tensorflow. I have listed the set of instructions to compile MatConvNet on a Windows machine.


  1. Matlab version 2017a
  2. MatConvNet :,
  3. Visual Studio 2015:,
  4. CUDA 8.0: (For GPU Support only)
  5. cuDNN v5.1 (For GPU support only):


  1. Extract MatConvNet to a folder.
  2. Install Visual Studio. Make sure you select the option for programming languages when you install visual studio otherwise Matlab will not be able to find the compiler.
  3. Run Matlab and setup MatConvnet extracted folder as working directory.
  4. In command window enter the following command to setup Visual Studio as your compiler
    >> mex -setup C++
    MEX configured to use 'Microsoft Visual C++ 2015 Professional' for C++ language compilation.
  5. Now add path to 'matlab' folder in the extracted library and compile
    >> addpath matlab 
    >> vl_compilenn('verbose', 1)
  6. At this point MatConvNet should be succesfully compiled to run on CPU. To test this run the following commands.
    >> run matlab\vl_setupnn.m 
    >> vl_testnn
  7. GPU Support

  8. Install CUDA v8.0
  9. Extract cuDNN
    • 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'.
  10. Follow step 1 to 5 and enter the following command
    >> vl_compilenn('enableGpu', true, ...
    'cudaRoot', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0', ...
    'cudaMethod', 'nvcc', ... 
    'enableCudnn', true, ... 
    'cudnnRoot', 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0');
  11. After succesfull build you can test the mex files by entering the command below
    >> vl_testnn('gpu', true); 



  1. This comment has been removed by the author.

  2. Hi, when I compile matconvnet (vl_compilenn), I have an error message: "Error using mex". When I try "mex -setup C++", the response is "MEX configured to use 'MinGW64 Compiler (C++)' for C++ language compilation." From matconvnet documentation, I know matconvnet doesn't support MinGW as a compiler. I have installed Visual Studio 2015 Community but it seems matlab always compile with MinGW instead of Visual Studio C++. Could you help me?

    1. First read and Install visual studio from this link:
      second: use this link
      if have problem then ask

  3. This comment has been removed by the author.

  4. when i perform 9th step i.e., compiling cudu in matlab.. it shows error like the following..

    vl_compilenn: CUDA: MEX config file: 'C:\Program Files\MATLAB\R2016a\toolbox\distcomp\gpu\extern\src\mex\win64\mex_CUDA_win64.xml'
    nvcc fatal : Unsupported gpu architecture 'compute_20'
    Error using vl_compilenn>nvcc_compile (line 540)
    Command "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc" -c "D:\3 Deep Learning\1
    Software\matconvnet-1.0-beta24\matlab\src\bits\" -DNDEBUG -DENABLE_GPU -DENABLE_CUDNN -I"C:\Program Files\NVIDIA
    GPU Computing Toolkit\CUDA\v9.0\include" -DENABLE_DOUBLE -D__SSSE3__ -gencode=arch=compute_20,code=\"sm_20,compute_20\"
    -gencode=arch=compute_30,code=\"sm_30,compute_30\" -I"C:\Program Files\MATLAB\R2016a\extern\include" -I"C:\Program
    Files\MATLAB\R2016a\toolbox\distcomp\gpu\extern\include" -gencode=arch=compute_20,code=\"sm_20,compute_20\"
    -gencode=arch=compute_30,code=\"sm_30,compute_30\" -O3 -Xcompiler /MD --compiler-bindir "C:\Program Files (x86)\Microsoft
    Visual Studio 14.0\VC\..\VC\bin" -o "D:\3 Deep Learning\1 Software\matconvnet-1.0-beta24\matlab\mex\.build\bits\data.obj"

    Error in vl_compilenn (line 485)
    nvcc_compile(opts, srcs{i}, objfile, flags.nvcc) ;


    1. Am getting the same error. Did you fix it?

    2. First read and Install visual studio from this link:
      second: use this link
      if have problem then ask

  5. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here. rprogramming training in bangalore

  6. Thanks after long time successfully complete it


Post a Comment

Popular posts from this blog

Build caffe, pycaffe and matcaffe on Windows

Running Tensorboard on Windows

Build TensorFlow on Windows