Caffe Windows Install

 

Caffe is a deep learning framework popular in Linux with Python or Matlab interface. I just managed to compile Caffe in Windows, and I think it’s worth sharing. Was of great help. This repository is organized in a way that future update merging from would be very straight forward.

For quick setup and usage go to my. For quick and dirty start, go to, where I’ll provide 1) the modified file that can be compiled in windows right away; 2) the vs2013 project that I’m currently using. Below is my step by step record to compile Caffe from source in Windows 8.1 + vs2013 + OpenCV 2.4.9 + CUDA 6.5. Download source from and unzip. Create a new project in Visual Studio 2013. File - New - Project.

Choose Win32 Console Application. Set location to the root of Caffe. Change Name to caffe (the generated exe file later is named after the project name, so please use this low case word). Click OK. Check Empty project, and then Finish.

Change the platform from Win32 to. Build - Configuration Manager - Active solution platform - new - x64 - OK. An empty project called caffe is generated into the root of Caffe now. To compile big project like Caffe, good practice is to compile a few.cpp files first and figure out dependencies one by one. Drag files in caffe/src/caffe to Source Files in VS. Let’s set some directories of the project.

In Property Manager, both Debug x64 and Release x64 need to be set:. In Configuration Properties - General, set Output Directory to ‘./bin’. The generated exe files will be easy to use later. Change for both Debug and Release mode. In Configuration Properties - C/C - General, edit Additional Include Directories (Both Debug and Release) to include:./include;./src;. Make sure to check Inherit from parent or project defaults. Now let’s fix dependencies one by one: (My pre-built 3rdparty folder can be downloaded:, if you are using Windows 64bit + vs2013).

CUDA 6.5. Download and install (You have to have a GPU on your PC lol). OpenCV 2.4.9 + CUDA 6.5. OpenCV libraries should work. If you want to build OpenCV with CUDA to enable OpenCV’s GPU support such as GpuMat, a tutorial can be found. Seems it’s not required by Caffe though. Boost. ones works fine.

OpenBLAS. ones works fine. Update: required 3 dll files (libgccsseh-1.dll, libgccssjlj-1.dll, libgfortran-3.dll, libquadmath-0.dll) can be found here: (x64). Add OpenCV + CUDA + Boost into the project:. I used to put these 3 libraries outside Caffe folder because they are so useful.

Add include path to Additional Include Directories: (Both Debug and Release) $(CUDAPATHV65) include $(OPENCVX64VS2013249) include $(OPENCVX64VS2013249) include opencv $(BOOST1560). CUDAPATHV65 is added by CUDA initialization. OPENCVX64VS2013249 and BOOST1560 need to be added to the Environment Variables Also, the bin (e.g. /to/opencv-2.4.9/x64-vs2013/bin) folder of OpenCV need to be added to Path. You may need to log off to enable them. I have some problem when building your code on x64 debug mode. Can you help me solve the two problems?

1common.obj: error LNK2019: unresolved external symbol “declspec(dllimport) void cdecl google::InstallFailureSignalHandler(void)” (imp?InstallFailureSignalHandler@google@@YAXXZ) referenced in function “void cdecl caffe::GlobalInit(int.,char.)” (?GlobalInit@caffe@@YAXPEAHPEAPEAPEAD@Z) 1datalayer.obj: error LNK2019: unresolved external symbol “class boost::sharedptr,class caffe::Datum,struct caffe::datasetinternal::DefaultCoder ,struct caffe::datasetinternal::DefaultCoder cdecl caffe::DatasetFactory,class caffe::Datum(enum caffe::DataParameterDB const &)”. @Sepehr for matlab wrapper do the following step, 1) In tools Drag matlab/caffe/matcaffe.cpp file into Visual Studio’s Source Files.

2) C/C Add include path of matlab to Additional Include Directories in my case “C: Program Files MATLAB R2011b extern include” 3) Add matlab lib path to Additional Library Directories in Configuration Properties - Linker - General: In my case “C: Program Files MATLAB R2011b extern lib win64 microsoft”. 4) Configuration Properties - General set Target Extension to “.mexw64” and configuration type “Dynamic Library (.dll)” 5) under “Additional Dependencies” add libmx.lib; libmex.lib; libmat.lib. I had build and test it on the windows 8, Core-i7 x64 without CUDA mode. Thanks for your help. I have the new problem.

I test the net in debug and release mode. In the debug mode, I got the valid Test net output in first iteration. But in the release mode, I got the invalid test net loss output. I0302 17:44 9944 solver.cpp:320 Test net output #0: accuracy = 0.0128 I0302 17:95 9944 solver.cpp:320 Test net output #1: loss = -1.#QNAN (. 1 = -1.#QNAN loss) What’s different with debug and release mode?

I got strange problems. I followed exactly your steps when building OpenCV gpu module with VS2010 and CUDA 6.5.

I successfully compiled 2.4.9 with Debug mode and 2.4.10 with release mode. But failed 2.4.9release/2.4.10 debug. Errors look like: CMake Error at modules/highgui/cmakeinstall.cmake:42 (file): 48 file INSTALL cannot find 48 “D:/MyProgram/opencv-2.4.9/gpubuild/bin/Release/opencvhighgui249.dll”. Firstly, thanks for this very detailed and useful tutorial. I managed (or I think I did) through all the steps of compilation but I finally have an error when running createmnist.bat (modified with leveldb format).

I have only the following message: “The application was unable to start correctly (0xc000007b) “. I downloaded the leveldb-formatted mnist dataset from niuzhiheng’s GitHub to try launching the training but the same error occurs when running trainlenet.bat. I have no idea where it can come from.

Hoping someone can help. Thanks in advance! Regards, Stephane. Hello, I used the openblas version provided in the tutorial and just copied the dlls in the bin directory as indicated.

I think it worked correctly as I did not have to reinstall it. Libgfortran-3.dll is also present in MinGW so be sure to have the correct version (64-bit). For information, in my case, the problem came from the anaconda distribution that I use for Python development, it was in 32-bit version and it was this libgfortran-3 file called by caffe.exe. Hope it helps.

Regards, Stephane. Hi Thanks for you help. I am stuck in training.

I have generate mnisttrainleveldb and mnisttestleveldb. And modified caffe/examples/mnist/lenettraintest.prototxt, substituted “lmdb” with “leveldb”. When i do train i got error. Snapshotprefix: “examples/mnist/lenet” solvermode: CPU net: “examples/mnist/lenettraintest.prototxt” I0322 17:19 4880 solver.cpp:70 Creating training net from net file: examples/mnist/lenettraintest.prototxt libprotobuf ERROR.

Src google protobuf textformat.cc:274 Error parsing text -format caffe.NetParameter: 17:3: Unknown enumeration value of “leveldb” for fie ld “backend”. F0322 17:19 4880 upgradeproto.cpp:928 Check failed: ReadProtoFromTe xtFile(paramfile, param) Failed to parse NetParameter file: examples/mnist/lene ttraintest.prototxt. Check failure stack trace:. Thank you for excellent guide. I was able to build ‘convertimages’ and ‘caffe’. But didnt find any documentation about using trained net so I decided to build Python module.

Getting through it I still, after days wasn’t able to solve such a error: caffe.obj: error LNK2001: unresolved external symbol “declspec(dllimport) struct object. cdecl boost::python::detail::initmodule(struct PyModuleDef &,void (cdecl.)(void))” (imp?initmodule@detail@python@boost@@YAPEAUobject@@AEAUPyModuleDef@@P6AXXZ@Z) 1G: Ilya Projects caffe-master bin caffe.exe: fatal error LNK1120: 1 unresolved externals I think I added everything that I could about boost in Additional Include Directories and Additional Library Directories Could you advise something? I created new project in Visual Studio(dll type), added everything as mentioned above, just copied it from previous project where we build caffe.cpp and other tools.cpp and.h files shloud be already changed according to this blog, so you need just add them in project(for folders layers and others do not forget to change “Build Customization”). I have Anaconda with Python 3.4, so I added essential dependencies for python and numpy(I can write explicitly what dependencies when Ill get to my work PC, but you can figure it out by looking at errors building project).

Also you need build Boost 1.56(prebuild didnt work in this case) and separatly Boost.Python. I ran into this same problem, and it turns out that this error occurs when python can’t find the caffe extension itself (which is the obvious interpretation), but that it can also occur when Windows can’t find some of the dependencies for the caffe extension. The first thing to try is to rename caffe.dll to caffe.pyd (since python only imports files with the pyd extension) and then to make sure that caffe.pyd is in your PYTHONPATH (for example, add it to your sitepackages directory). You can find the directories in your PYTHONPATH from within python with: import sys print sys.path If that doesn’t work, then use Dependency Walker to find out if the module is having trouble loading any of it’s dependencies. Just use dependency walker to open the caffe.pyd file that you just moved.

In my case, I had forgotten to add libglog.dll and libopenblas.dll to my Windows PATH. After that, you will probably also run into a problem with protobuf. Namely, you won’t have the caffe.proto submodule. In order to make this, you have to put protoc.exe in your path and then cd to the caffe directory and use these commands: mkdir -p python/caffe/proto && touch python/caffe/proto/init.py && protoc –protopath=src/caffe/proto –pythonout=python/caffe/proto src/caffe/proto/caffe.proto && protoc –protopath=src/caffe/proto –pythonout=python/caffe/proto src/caffe/proto/caffeprettyprint.proto This will give you caffe.proto, which you won’t get when building caffe.dll in VS. Finally, if you get an “unexpected keyword argument” error when loading protobuf, this is likely from using protobuf 3.0.

Use protobuf 2.6 instead (recompile caffe.dll with the protobuf 2.6 libs as well). Hope that helps! After fixing that I have another error error MSB4018: The “VCMessage” task failed unexpectedly.

System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. Brothers, I have some troubles.

Caffe

After compile the caffe,I have 631 link errors like this:1solver.obj: error LNK2019: 无法解析的外部符号 “public: virtual cdecl caffe::SolverParameter::SolverParameter(void)” (??1SolverParameter@caffe@@UEAA@XZ),该符号在函数 “public: cdecl caffe::Solver::Solver(class std::basicstring const &)” (??0?$Solver@M@caffe@@QEAA@AEBV?$basicstring@DU?$chartraits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用, How can I solve them? Best Wishes Thank you very much. Hello Neil, Thank you very much for your useful guide.

Two errors occured when I tried to compile the code in CPUONLY mode. I am using visual studio 12 and I entered CPUONLY in preprocessor definitions to run in CPUONLY mode. I didn’t add the.cu files for this mode caffe src caffe syncedmem.cpp(93): error C4716: ‘caffe::SyncedMemory::gpudata’: must return a value caffe src caffe syncedmem.cpp(109): error C4716: ‘caffe::SyncedMemory::mutablegpudata’: must return a value I could compile the codes for GPU but as soon as I go to the CPUONLY mode I encounter these errors. I would appreciate your help. Also would you please elaborate on your following reply? Where do you enter these commands?

An example is roughly like this: // Set CPU Caffe::setmode(Caffe::CPU); // Set to TEST Phase Caffe::setphase(Caffe::TEST); // Load net Net net(“deploy.prototxt”); // Load pre-trained net (binary proto) net.CopyTrainedLayersFrom(“trainedmodel.caffemodel”). Hi; First, thank you for the tutorial here. I faces a problem during compiling the Caffe inside Visual Studio 2013 in Windows 7. The VS keeps telling me that I have a syntax error inside “hdf5outputlayer.cpp”. I didn’t change any code inside this one and didn’t find anyone with this problem.

This is the list of problems: Error18error C2143: syntax error: missing ‘;’ before ‘. Hi, thanks for this tutorial, but i have met some problems. Thanks for the great tutorial! I have been using Caffe on linux for a while now, but since I’m new to linux I was always struggling to get things working. This makes life a lot easier! I compiled it on windows 7, VS2013, CUDA7.0 Everything works, including my own previous “linux caffe” experiments. Only problem: it’s quite a lot slower, in the order of 3 times slower.

This is probably due to CUDNN, which I couldn’t get to work. Got it fixed adding “SCLSECURENOWARNINGS” in preprocessor definitions (Configuration Properties - C/C - Preprocessor - Preprocessor Definitions ).

Now all the files in layers folder are getting compiled but contrastivelosslayer.cpp the following three error appears when i try to compile this. Error23error C2784: ‘Ty std::max(std::initializerlist,Pr)’: could not deduce template argument for ‘std::initializerlist’ from ‘float’ Error24error C2780: ‘const Ty &std::max(const Ty &,const Ty &,Pr)’: expects 3 arguments – 2 provided Error26error C2782: ‘const Ty &std::max(const Ty &,const Ty &)’: template parameter ‘Ty’ is ambiguous Thanks in advance. Folks, after compiling the files, I am getting a huge bunch of errors of type LNK 2001. Indeed is something about 165 unresolved externals like the one showed below: error LNK2001: unresolved external symbol “declspec(dllimport) public: thiscall google::base::CheckOpMessageBuilder::CheckOpMessageBuilder(void)” (imp??1CheckOpMessageBuilder@base@google@@QAE@XZ)C: Users mhsc Documents Visual Studio 2012 Projects caffe-master caffe-master caffe caffe solver.obj I don´t know what I am missing and i´m going crazy Please, any suggestion is very welcomed and I thank you so much. Thanks for this helpful guide! One comment I would make is that it’s important to get the runtime library correct across all of the packages. As an example, I had downloaded OpenCV 3.0.0 and found the the only location for the OpenCV libs mentioned in the guide were in the staticlib dir, which doesn’t work well with the other precompiled 3rd-party libs provided.

Fortunately, OpenCV 2.4.11 has the proper libs. Also, is there an alternative location to get the OpenBLAS package? SourceForge seems to be having troubles at the moment. I’ve found some other OpenBLAS distributions (such as openblas.net) but it’s not clear they are related to the one from SourceForge.

Hi, Can someone please explain in detail how can I use one of the famous pretrained nets (e.g AlexNet)? That includes: 1) How can I download the pretrained net? (Is it already included in the windows library?) I didn’t find any suitable script in the caffe-windows folder. 2) How can I give an input to the net? (like RGB of pixels in an image)- I want to give the input myself 3) How can I extract features from “middle” layers of the net? (when I test the net after I give my input) This information will be very helpful to me, thanks in advance!

Hi, Has anyone tried HDF5 file input on Windows? I got a lot of errors using Neil’s 3rd party library.

I tried to fix it by re-building the hdf5 libraries from a more recent release. But I got a lot of unsatisfied externals.

Detailed messages are attached here:. Caffe error at runtime I0728 15:72 8684 net.cpp:368 data - label I0728 15:73 8684 net.cpp:120 Setting up data I0728 15:73 8684 hdf5datalayer.cpp:80 Loading list of HDF5 filenam es from: hdf5classification/data/test.txt I0728 15:72 8684 hdf5datalayer.cpp:94 Number of HDF5 files: 1 HDF5-DIAG: Error detected in HDF5 (1.8.14) thread 0: #000:.

Src H5Dio.c line 173 in H5Dread: can’t read data major: Dataset minor: Read failed #001:. Src H5Dio.c line 550 in H5Dread: can’t read data major: Dataset minor: Read failed #002:.

Anaconda Caffe Install Windows 10

Src H5Dchunk.c line 1872 in H5Dchunkread: unable to read raw data chunk major: Low-level I/O minor: Read failed #003:. Src H5Dchunk.c line 2902 in H5Dchunklock: data pipeline read failed major: Data filters minor: Filter operation failed #004:.

Src H5Z.c line 1357 in H5Zpipeline: required filter ‘deflate’ i s not registered major: Data filters minor: Read failed #005:. Src H5PL.c line 298 in H5PLload: search in paths failed major: Plugin for dynamically loaded library minor: Can’t get value #006:. Src H5PL.c line 466 in H5PLfind: can’t open directory major: Plugin for dynamically loaded library minor: Can’t open directory or file F0728 15:73 8684 io.cpp:273 Check failed: status = 0 (-1 vs.

0) Fai led to read float dataset data. Check failure stack trace:. Error linking with new HDF5 library 1—— Build started: Project: caffe, Configuration: Release x64 —— 1C: Program Files (x86) MSBuild Microsoft.Cpp v4.0 V120 Microsoft.CppBuild.targets(364,5): warning MSB8004: Output Directory does not end with a trailing slash. This build instance will add the slash as it is required to allow proper evaluation of the Output Directory. Hi Neil, great instructions.

However, I got stuck while compiling blob.cpp. When I hit right click on caffe to run the pre-build command line I receive the notice that the files and have been generated, followed by a warning that a path has not been found. Here is my report: 1—— Build started: Project: caffe, Configuration: Debug x64 —— 1 caffe.pb.h is being generated 1 The system cannot find the path specified. 1 caffeprettyprint.pb.h is being generated 1 The system cannot find the path specified. 1C: Program Files (x86) MSBuild Microsoft.Cpp v4.0 V120 Microsoft.CppCommon.targets(122,5): error MSB3073: The command “”././scripts/GeneratePB.bat” 1C: Program Files (x86) MSBuild Microsoft.Cpp v4.0 V120 Microsoft.CppCommon.targets(122,5): error MSB3073::VCEnd” exited with code 1.

Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped Can you help with this? Thanks in advance! Thanks for you help.

I am stuck in training. I have generate mnisttrainleveldb and mnisttestleveldb. And modified caffe/examples/mnist/lenettraintest.prototxt, substituted “lmdb” with “leveldb”. For matlab wrapper do the following step, 1) In tools Drag matlab/caffe/matcaffe.cpp file into Visual Studio’s Source Files. 2) C/C Add include path of matlab to Additional Include Directories in my case “C: Program Files MATLAB R2011b extern include” 3) Add matlab lib path to Additional Library Directories in Configuration Properties - Linker - General: In my case “C: Program Files MATLAB R2011b extern lib win64 microsoft”. 4) Configuration Properties - General set Target Extension to “.mexw64” and configuration type “Dynamic Library (.dll)” 5) under “Additional Dependencies” add libmx.lib; libmex.lib; libmat.lib.

Thanks for the great tutorial. I could manage to set everything up as mentioned here, But I am getting wierd errors. Thanks for the instructions.

Everything compiles for me successfully and I am able to generate leveldb train and test folders. However when I try to run “trainlenet.bat”, I get following errors: I0112 18:31 8052 caffe.cpp:184 Using GPUs 0 I0112 18:87 8052 common.cpp:32 System entropy source not available, using fallback algorithm to generate seed instead. F0112 18:83 8052 solverfactory.hpp:76 Check failed: registry.count(type) 1 (0 vs. 1) Unknown solver type: SGD (known types: ).

Check failure stack trace:. I have a hopefully simple question re: installing cuDNN on Visual Studio 2013 with Windows 7 system having CUDA 7.0 already installed. Downloaded cudnn Library for Windows and extracted it into directory C: cuDNNExtracted 2. That generates a new folder C: cuDNNExtracted cuda which contains 3 more sub-folders: bin, include, lib. NV installation instructions say to A) Add to the PATH environment variable. I add: C: cuDNNExtracted cuda is this correct?

Winmend folder hidden password retriever. Recover data with the best Winmend folder hidden recovery software Here, EaseUS is the best Winmend folder hidden recovery software that we would like to recommend. To do you a favor, here we would like to introduce you the best Winmend folder hidden recovery software and shows you how to restore files from Winmend folder hidden step by step. Even there is numerous data recovery software helps to retrieve data from common hard drives or external storage devices like USB or memory card, but few of them supports to recover files from Winmend folder hidden. No matter how you get your files lost from Winmend folder hidden, it can help you effectively retrieve them back with no hassle. The program performs perfectly well in Winmend folder hidden file recovery.

B) In VS project properties NV says add to Include Directories C) In VS add to Library Directories In both cases B,C, I added C: cuDNNExtracted cuda without any $ or Is this correct? D) NV says add cudnn.lib to Linker- Input-Additional Dependencies which I do. Is this correct? When I try to run the program always get linker error that can’t link cudnn.lib What am I doing wrong? Thanks in advance, Windows Nvidia experts. I have a problem, so i need your help.

Hi, Now I am able to compile all the files but when I try to build the caffe project, I met some problems. The errors are like below: 1caffe.obj: error LNK2001: Unresolved external symbol “private: void cdecl caffe::Layer::Lock(void)” (?Lock@?$Layer@M@caffe@@AEAAXXZ) 1sigmoidcrossentropylosslayer.obj: error LNK2001: Unresolved external symbol “private: void cdecl caffe::Layer::Lock(void)” (?Lock@?$Layer@M@caffe@@AEAAXXZ) 1softmaxlosslayer.obj: error LNK2001: Unresolved external symbol “private: void cdecl caffe::Layer::Lock(void)” (?Lock@?$Layer@M@caffe@@AEAAXXZ) I have no idea how to solve the problem.

Any suggestion is welcomed and thank you very much. Can you please help me im stuck with this line. GFlags + GLog + ProtoBuf + LevelDB Download source code from the internet.

Use CMake to generate.sln for vs2013. Remember to set “CMAKEINSTALLPREFIX”, which is where the output files will be generated by build “INSTALL”. Build in vs2013.

Usually build “BUILDALL” first, then “INSTALL”. Both Debug and Release mode.

Copy compiled files to caffe/3rdparty. Debug versions should be renamed “+d” before copy, e.g. “lib” - “gflagsd.lib”. I’ve build GFlags + GLog + ProtoBuf + LevelDB those lib using cmake. Didnt understand this line “Copy compiled files to caffe/3rdparty. Debug versions should be renamed “+d” before copy, e.g. “lib” - “gflagsd.lib”.” please if possible explain a bit.

Like i need to copy the whole cmake build files to 3rdparty?