Setting Up Caffe on Windows 8.1

It took a fair bit of fussing with CMake, but I’ve successfully compiled Caffe from the Berkeley Vision and Learning Center. There does appear to still be an issue with a psudorandom generator in one of the linked libraries that will probably impair training new nets, but I can currently run existing models and compare images against them for classification.

I’ll outline some of the issues I ran into along the way.

First of all, always check the installation requirements before starting. Per the installation guide:
CUDA 7+ is required for GPU mode
BLAS (Basic Linear Algebra System) – OpenBLAS libraries are downloaded with the dependency install, don’t need to install separate
BOOST – this is a C++ cross compilation libary, don’t install – python dependency script will get it
protobuf, glog, gflags, hdf5 – Don’t install any of these either!
OpenCV – Script will fetch this too
leveldb, lmdb – Script gets one of these

cuDNN – This one you do need to download for an nVidea GPU setup. Ensures fastest operation

Why are these listed in the requirements if you don’t need to install them!? Well if you were compiling from scratch in linux you’d need to get all these installed first.

Python is also listed as optional, but you’ll need it to run the dependency install scripts. Get Anaconda 2.7. 3.5 doesn’t appear to be supported at the moment. Also download CMake 3.4+. I used 3.6.

OK, got CUDA 8, cuDNN 5, and Anaconda 2.7, and CMake 3.4+ installed? Now start following these windows install instructions.

First issue I ran into was a conflicting python install trying to install dependencies since I have probably at least 5 python installs on my machine.
C:\Programming\caffe>py -2.7
File "C:\tools\python\lib\site.py", line 176
file=sys.stderr)
^
SyntaxError: invalid syntax

Double check your %PATH%, user PATH, PYTHONPATH, PYTHONHOME variables. Why do they have so many variables? After scrubbing that I used the Visual Studio 2015 dependency install from the Caffe root.
> python scripts\download_prebuilt_dependencies.py --msvc_version=v140

I initially tried using the Ninja generator since it supposedly will build faster. Eventually gave up. One note on that process was that the command prompt needs to run in Admin Mode to use conda install commands at least on Windows8.1

I used the “Visual Studio 14 2015 Win64” CMAKE_GENERATOR. The CMAKE generation command I eventually got to work was
cmake -G%CMAKE_GENERATOR% -DBLAS=Open -DCMAKE_BUILD_TYPE=%CMAKE_CONFIGURATION% -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="C:/Programming/caffe" -DCUDNN_ROOT="D:/Programming/cudnn-8.0-windows7-x64-v5.1/cuda" -DBoost_COMPILER=-vc140 -DBoost_DEBUG=ON -DBoost_USE_STATIC_LIBS=OFF -DBUILD_python_layer=1 -DBUILD_python=1 -DCUDA_gpu_detect_output=FALSE -DCPU_ONLY=0 -DCUDA_VERBOSE_BUILD=ON -DUSE_OPENCV=ON -C %CAFFE_DEPENDENCIES%\caffe-builder-config.cmake ..\

Had a problem where HDF5 library wasn’t found.

CMake Error at C:/Program Files/Anaconda2/Library/cmake/FindHDF5.cmake:85 (include)
include could not find load file:

HDF5_ROOT_DIR-NOTFOUND/hdf5-config.cmake
Call Stack (most recent call first):
cmake/Dependencies.cmake:39 (find_package)
CMakeLists.txt:68 (include)
Delete everything in your CMAKE build directory and try rebuilding. Fixed it for me anyway.

Once I finally got the exe’s built, I also had to move a bunch of DLL’s to the binary directory that Caffe lives in. Not sure if that’s expected or if that’s an incorrect build flag, but Caffe runs after moving them in.

To setup the pycaffe directory you also need to copy the %CAFFE_ROOT%\python\caffe into your site_packages.

After all that I can use the caffe package in IPython and am able to load different caffe models from the community model zoo .

This guide on using pycaffe is very helpful.

Here’s some example out from the InceptionBN-21K-for-Caffe model.
sandwich

In [128]: im = caffe.io.load_image(wd+'examples/images/sandwich.jpg')

In [129]: net.blobs[‘data’].data[…] = transformer.preprocess(‘data’, im)

In [130]: out = net.forward()

In [131]: top_k = net.blobs[‘softmax’].data[0].flatten().argsort()[-1:-6:-1]

In [132]: print labels[top_k]
[‘n07698401 Bacon-lettuce-tomato sandwich, BLT’
‘n07697825 Bomber, grinder, hero, hero sandwich, hoagie, hoagy, Cuban sandwich,
Italian sandwich, poor boy, sub, submarine, submarine sandwich, torpedo, wedge,
zep’
‘n07696403 Sandwich plate’ ‘n07696625 Ham sandwich’
‘n07696839 Club sandwich, three-decker, triple-decker’]

No bacon or ham in there, but pretty good for top 5 results.

Leave a Comment