Building Caffe (1.0) for Windows - t-kuha/caffe-win-dependency GitHub Wiki
This is an instruction for how to build Caffe (static version) from source.
- git (For example: https://git-scm.com/download/win)
- CMake (Tested with 3.12.4)
- Be sure to use CMake 3.9.3 or newer
- Reference: https://stackoverflow.com/questions/42123509/cmake-finds-boost-but-the-imported-targets-not-available-for-boost-version/42124857
 
- Visual Studio 2017 (64 bit)
- CUDA (10.0) & cuDNN (7.0) (If you want GPU acceleration)
- Python (As necessary; Tested with Miniconda 3 (64 bit) / Python 3.7.4)
- 
Clone Caffe source from my GitHub: > git clone https://github.com/t-kuha/caffe.git # Check out Windows branch > cd caffe > git checkout windows # You can run "git status" to make sure you're on "windows" branch # Go back to the original direcroty > cd .. 
- 
Download dependency files from my repo: # Add --recursive if you also want sources > git clone https://github.com/t-kuha/caffe-win-dependency.git # Checkout necessary version > cd caffe-win-dependency > git checkout python-3.7 > cd .. 
# Run build command
> mkdir _build
> cd _build
# Build with VS2017
# CPU-only version
> ..\caffe-win-dependency\build_caffe.cmd <Full path to root dir>/caffe-win-dependency/_vs2017
# GPU version
> ..\caffe-win-dependency\build_caffe_gpu.cmd <Full path to root dir>/caffe-win-dependency/_vs2017- 
Copy _< Build directory >/install/python/caffe to /Lib/site-packages 
- 
Check if Caffe works in Python: 
> python -c "import caffe"- Check if command line tool works:
> cd < Build directory >/_install
> bin/caffe.exe
caffe.exe: command line brew
usage: caffe <command> <args>
commands:
  train           train or finetune a model
  test            score a model
  device_query    show GPU diagnostic information
  time            benchmark model execution time
  No modules matched: use -help
- 
Copy < Caffe Source >\examples into < Build directory >_install 
- 
Download MNIST data & Convert it to LMDB 
> bin\convert_mnist_data.exe examples\mnist\t10k-images.idx3-ubyte examples\mnist\t10k-labels.idx1-ubyte examples/mnist/mnist_test_lmdb
> bin\convert_mnist_data.exe examples\mnist\train-images.idx3-ubyte examples\mnist\train-labels.idx1-ubyte examples/mnist/mnist_train_lmdb- Train
> bin\caffe.exe train --solver=examples\mnist\lenet_solver.prototxtc
    ...
I0410 13:52:01.257920  3040 solver.cpp:447] Snapshotting to binary proto file examples/mnist/lenet_iter_10000.caffemodel
I0410 13:52:01.268927  3040 sgd_solver.cpp:273] Snapshotting solver state to binary proto file examples/mnist/lenet_iter_10000.solverstate
I0410 13:52:01.274931  3040 solver.cpp:310] Iteration 10000, loss = 0.00263578
I0410 13:52:01.275933  3040 solver.cpp:330] Iteration 10000, Testing net (#0)
I0410 13:52:01.402025  9560 data_layer.cpp:73] Restarting data prefetching from start.
I0410 13:52:01.407029  3040 solver.cpp:397]     Test net output #0: accuracy = 0.992
I0410 13:52:01.407029  3040 solver.cpp:397]     Test net output #1: loss = 0.0278062 (* 1 = 0.0278062 loss)
I0410 13:52:01.407029  3040 solver.cpp:315] Optimization Done.
I0410 13:52:01.407029  3040 caffe.cpp:260] Optimization Done.