Caffe Windows Matlab
Caffe for windows中的matlab经常会崩死,本质是mex包在caffe遇到错误又不能自行容错的情况下会直接kill掉自己的thread,但是又不给.
The purpose of this series it to get working in windows in the most quick and dirty way: I’ll provide 1) the modified file that can be compiled in windows right away; 2) the vs2013 project that I’m currently using. In short:. Install CUDA, Boost, OpenCV. Download caffe code with vs2013 from. Download and unzip to ‘3rdparty’ folder.
Edit ‘Caffe-vs2013 – Debug.props’ and ‘Caffe-vs2013 – Release.props’ files so that the path of CUDA, Boost and OpenCV make sense for you. Also, the given ‘compute50,sm50’ is for GPU. Change 50 to 20 for and 30 for.
Open caffe-vs2013.sln. Set platform to Release, x64 and change ‘caffe’ project’s ‘Configuration Type’ to ‘Application (.exe)’. Right click on ‘caffe’ project and ‘compile’.
Run test on MNIST. For caffe.exe, please use Release x64 mode. Debug version of caffe.exe makes no sense and is slow.
32 bit version should work but lacking support for lmdb and hdf5 because I didn’t compile them. Lol Setup:. CUDA 6.5. You have to have a Nvidia GPU on your PC to enable GPU version of Caffe. My impression was that you get maybe 10x speed-up using GPU over CPU, and another 10x speed-up by enable library. The installation will create system variable for you, e.g. If you are using a GPU with the architecture of Fermi or Kepler:.
If you are using a GeForce GTX9xx GPU with the architecture of Maxwell:. should be fine also. Boost. Pre-built version of boost are available. I’m using boost 1.56.0 myself. Get and install. Add boost’s path to system’s path.
I added BOOST1560:. OpenCV. Since we are not using GPU supported OpenCV here, e.g. Are good enough for a quick start. I use OpenCV 3.0 here as example.
Add system path variable for OpenCV also:. System variable need ‘log off’ or ‘restart’ your system to take effect. Download the code for caffe from my.
The original code was forded from. Then I manually added the changes from to support “vector”.
Download the 3rdparty.zip and unzip its content to 3rdpary folder. 3rdparty.zip (Version 2015.7.18) (code: 6147). Included is the support for gflags, glog, google/protobuf, hdf5, leveldb, liblmdb, openblas, cudnn, etc. Before compile (skip if you’re familiar with vs2013 already):. When it comes to a big project, many errors can happen. Let’s get things a bit clear first. In a project, usually functions are declared in.h/.hpp files and implemented in.c/.cpp files.
Missing.hpp file is usually shown in the editor and missing.cpp file usually gives linking error. All.cpp files added to the vs project will be compiled to.obj files which can be linked later.
While no.hpp files will be compiled. Adding.hpp files to the vs project or not makes no difference to the compiling. If you want to include.hpp file from another project, e.g. You need to add the path of the header files to ‘AdditionalIncludeDirectories’. Adding header files to the vs project does NOT add the path automatically. Adding the path of.cpp files to ‘AdditionalIncludeDirectories’ is NOT needed and has NO effect.
For example if the file path is “D: toolkits opencv-3.0.0 build include opencv2 opencv.hpp”, you can either:. 1) add “D: toolkits opencv-3.0.0 build include” to ‘AdditionalIncludeDirectories’ and write #include “opencv2/opencv.hpp”; or. 2) add “D: toolkits opencv-3.0.0 build include opencv2” to ‘AdditionalIncludeDirectories’ and write #include “opencv.hpp”;. After the.hpp file is included, the compiler knows that these functions exist so ‘unknown namespace cv’ kind of error will not happen any more.
After all.cpp files in your project are compiled, here comes the linking. The implementation of functions have to be either in.cpp files of your project or.lib files generated by other projects. Enabling lib files requires 1) path to be added to ‘AdditionalLibraryDirectories’; and 2) file names to be added to ‘AdditionalDependencies’. For example, you might add “D: toolkits opencv-3.0.0 build x86 vc12 lib” to ‘AdditionalLibraryDirectories’ and add “opencvts300.lib; opencvworld300.lib;” to ‘AdditionalDependencies’.
Usually the path of lib files changes according to the ‘PlatformTarget’, i.e. ‘x86’, and the ‘Configuration’, i.e. I usually let Visual Studio handle the difference, e.g. I add “$(OPENCV300) $(PlatformTarget) vc12 lib” for OpenCV in later sections. If you solve compile error by having proper.hpp files and solve linking error by have proper.lib files, you program will run. Yet it might have missing.dll error. Some library are compiled in the static way to generate.lib files only, like gflags, protobuf, etc.
Some library are compiled in the dynamic way to generate both.lib and.dll files. In this case your program will require.dll files on run-time. Personally I like to copy required.dll files to the same folder of the.exe file for simplicity. Compile:. Open the ‘caffe-vs2013.sln’. In Property Manager you’ll see that 2.props files are added to the project: ‘Caffe-vs2013 – Debug.props’ and ‘Caffe-vs2013 – Release.props’.
Ubuntu Installation
This is a very handy way to setup you project quickly. The idea is that some fixed configuration are written in the property sheet file, i.g. ‘Caffe-vs2013 – Release.props’. After that the project’s property, i.e. ‘Release x64’, can inherit from it. Open the ‘Caffe-vs2013 – Release.props’ from disk, you’ll see the setting for CUDA, Boost, OpenCV, etc.
If your system path for CUDA, Boost, OpenCV are different from mine, you need to change them in these 2.props files. Output folder is changed to ‘$(SolutionDir)build $(Platform) $(Configuration) ’ for later use caffe as a lib in other projects. Noted that ‘compute50,sm50′ in the 2.props files means the generation of CUDA to use. ’50’ works for Maxwell GPU.
Use ’20’ for Fermi and ’30’ for Kepler. If you changed things in the.props files, you need to close and reopen your vs solution to take effect. Right click on ‘caffe’ and click ‘Property’. In ‘General’ - ‘Configuration Type’, make sure it’s ‘Application (.exe)’. Make sure it’s Release and x64. Right click on ‘caffe’ and click ‘compile’.
‘caffe.exe’ will be generated to ‘build/x64/Release’ folder. Copy ‘opencvffmpeg30064.dll’, ‘opencvworld300.dll’ from OpenCV to the folder of ‘caffe.exe’. Copy the following from 3rdparty folder (be aware of the configuration, i.e. Debug/Release, Win32/x86) to the same folder of ‘caffe.exe’:. libglog.dll. libopenblas.dll. cudnn6465.dll.
msvcp120.dll. msvcr120.dll. Run ‘caffe.exe’, should display like this:. Test on MNIST.
Go to ‘caffe/data/mnist’ folder and run ‘getmnist.bat’ to fetch dataset for MNIST. Go to ‘caffe/examples/mnist’ folder and. run ‘createmnist-leveldb.bat’ to convert MNIST dataset to leveldb format. run ‘trainlenet-leveldb.bat’ to start the training. There’s a ‘lmdb’ version but it does NOT work. Fix was given by Kazukuni Hosoi but I didn’t try it myself.
Caffe Install Windows Matlab
Not a fan of lmdb. Following. (II) Use caffe as lib like OpenCV in a normal vs2013 project. I’m having a same error. Debugging also shows that assertion fails assert(::caffe::LayerParameterLayerTypeIsValid(value)); // file caffe.pb.h, line 9239 When I look at LayerParameter objects, I see the valid names of layers (‘mnist’, ‘conv1’, etc), but, the integer fields type all have garbage values. I believe it should be 5 for data layer, 4 for convolution, etc according to enum LayerParameterLayerType. I’m afraid that protobuf isn’t parsed properly, though parsing functions return true.
Because of this c LayerParameter objects are not filled correctly. I cannot debug protobuf parsing itself yet as it is in 3rd parties without debugging symbols. I’ll try to build it myself and look inside a bit later. Thanks for your work, Neil. I’ve tried to build your solution with boost 1.58, but got linkage errors that 1.56 libs are missing. It appears that ‘leveldb.lib’ from your 3rd parties is already linked to some 1.56 libs, so boost version is not really configurable.
I have also tried cuda 7 and had caffe.exe built. But then discovered that your tool ‘convertmnistdata.exe’ still needs cuda 6.5 installed. Will you be able to add those 3rd party tools to your caffe solution, so that they can be built with same dependencies that are easy to switch? Hi Neil, I’m a beginner of caffe. I have successfully config the caffe according to your tutorial, that is I have got the “caffe.exe” and successfully open it.
But when I train to train the Lenet(executing the “trainlenet-leveldb.bat”), at the end of cmd window shows ” I0824 23:46 8136 solver.cpp:72 Creating training net from net file: examples/mnist/lenettraintest-leveldb.prototxt I0824 23:51 8136 net.cpp:274 The NetState phase (0) differed from th e phase (1) specified by a rule in layer mnist I0824 23:51 8136 net.cpp:274 The NetState phase (0) differed from th e phase (1) specified by a rule in layer accuracy F0824 23:51 8136 layerfactory.cpp:257 Layer mnist has unspecified t ype. Check failure stack trace:. ” I speed lots of time still can’t figure it out, could you please tell me how to solve this problem?
Thanks a lot!!! Hello Neil, Thank you so much for sharing a wonderful work here. I really apologize, I was able to install caffe in both linux and windows. Make.config is something that belongs to the linux system. It is a very simple file with the setting that you can just turn on and off for compilation. I strongly suggest you do a dual-booth with linux/ubuntu and install caffe there since there are much more support for linux and ubuntu that with windows.
I’m not really well-versed in Visual Studio, but I think there is a way to turn off CUDA for compilation. However, I will suggest to you to actually install CUDA v6.5 into your system. You can always turn it off when you actually run it. I will update to you back once I figured out how to turn CUDA compilation off for windows.
I cannot load ‘caff’ project. When I try to load it, I met the following message. I didn’t install CUDA, and I want to do this with CPU mode, but I don’t know how to do. Unable to read the project file “caffe.vcxproj”. C: Users MyName Documents Visual Studio 2013 Projects caffe-vs2013-master caffe caffe.vcxproj(55,5): The imported project “C: Program Files (x86) MSBuild Microsoft.Cpp v4.0 V120 BuildCusomizations CUDA 6.5.props” was not found.
Install Caffe Windows
Confirm that the path in the declaration is correct, and that the file exists on disk. I just have a couple of issues/observations: It’s strange that your code compiles with vs2013. I tried it with vs2012 (which I’d expect to be virtually the same) and it fails because it does not find std::isnan, std::signbit and round. (The first one isn’t really needed, and I had to the implement the other two by hand.) Your leveldb.lib in the 3rdparty folder is hardcoded to use Boost 1.56. (As in, it expects the existence of several library files called libboost.-mt-156.lib.) For that reason, the project won’t link against any other version of Boost. This can be worked around by adding those library file names to “exclude default libraries” field in linker settings, and adding correct file names to linker input libraries.
Even with that done, it still won’t link with VS2012 because I get linker conflicts between some pre-built objects and stuff that gets compiled on my end. I’m downloading VS2013 now. Your props file is looking for “opencvworld300.lib”. I haven’t tried OpenCV 3.0.0, but I have 2.4.9 and it does not have a opencvworld249.lib. The corresponding file is, I think, opencvcore249.lib.
(That said, this is still far better than compiling caffe from source in Windows – tried to do that, it’s a dependency hell.). I am trying to compile caffe with VS2013 running in windows 7. The caffe project was built without any errors. When I tried to buld the trainMNIST project, i initially go a missing caffe.lib which went away after copying the caffe.lib to the trainMNIST release folder. On subsequent attempts to build, i get 16 unresolved references error like the one below: unresolved external symbol “public: virtual cdecl caffe::SolverParameter::SolverParameter(void)” (??1SolverParameter@caffe@@UEAA@XZ)train-MNIST.objtrain-MNIST What is the problem and how can I fix it?