Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Setting Up Caffe on Windows with Visual Studio 2013, CUDA 10.0, and Anaconda Python 2.7

Tech May 15 1

Although Caffe is an older deep learning framework, specific legacy projects may still require it. This guide documents the process of building Caffe on Windows using Visual Studio 2013, CUDA 10.0, and a Python 2.7 environment managed via Anaconda.

1. Environment Preparation

First, create a dedicated Conda environment for Python 2.7. Note that if you ancounter connection issues with default or specific Chinese mirrors (like Tsinghua or USTC), you may need to rely on alternative sources like SJTU.

conda create -n caffe_py27 python=2.7
activate caffe_py27
pip install numpy scikit-image

Important: Run Visual Studio 2013 as Administrator. Avoid repeatedly uninstalling and reinstalling VS, as it consumes significant disk space.

2. Source Code Acquisition

Do not clone the generic Caffe repository from GitHub, as it lacks specific Windows configurations. Instead, download a Windows-specific fork (e.g., the "windows-caffe" variants available on GitHub or referenced in legacy tutorials).

3. Resolving CuDNN Compatibility

When using CUDA 10.0, you are likely using a newer version of CuDNN. The Caffe source code often expects an older API. If you encounter errors regarding "too few arguments in function call" in cudnn.hpp, it is because newer CuDNN versions added a type parameter to functions like cudnnSetConvolution2dDescriptor.

You must manually patch the header files in include/caffe/util/cudnn.hpp to add the missing parameter (usually CUDNN_DATA_FLOAT or the appropriate data type) to the function calls.

4. Fixing OpenCV NuGet Packages

The OpenCV NuGet packages (e.g., version 2.4.10 or 2.4.11) included in these old builds often contain XML configuration errors.

  • Navigate to NugetPackages/OpenCV.2.4.x/build/native/.
  • Open OpenCV.props and OpenCV.targets.
  • Look for misplaced or malformed private asset tags (e.g., extra slashes before the word "private") and remove them to fix the XML structure.
  • Deelete the specific OpenCV folder in NugetPackages and restore it via NuGet if simply editing the XML does not work, ensuring no stale configurations remain.

5. Windows SDK and Missing Headers

If you encounter C1083: Cannot open include file: 'corecrt.h', it indicates your Visual Studio 2013 is looking for Windows 10 SDK headers which might not be correctly linked.

Instead of a full Windows 10 SDK install (which is large), download the SDK installer, choose the "download" option, and extract only the ucrt headers. Copy the contents of C:\Program Files (x86)\Windows Kits\10\Include\10.0.x.x\ucrt into your Visual Studio include directory (e.g., D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include).

6. Boost Library Linking

Caffe requires specific versions of Boost (usually 1.59). The project files might reference vc140 (VS 2015) toolsets even if you are using VS 2013 (vc120).

If you see linking errors like LNK1104: cannot open file 'libboost_date_time-vc140-mt-1_59.lib':

  1. Open the NuGet Package Manager Console.
  2. Ensure you are installing the correct version for your compiler. For VS 2013, use vc120.
  3. If disk space is an issue during NuGet install, manually download the .nupkg files from the NuGet gallery, add a local NuGet source pointing to your download folder, and install offline.
  4. Verify the .targets file paths in the .vcxproj file point to the correct NugetPackages directory relative to your project.

7. Build Configuration

Ensure you are building for x64 and Release. If the build fails with "warnings treated as errors," go to the project properties -> C/C++ -> General and set "Treat Warnings As Errors" to "No."

8. Compiling PyCaffe

Once the C++ libraries are built, compile the pycaffe project.

  • Numpy Headers: If you get fatal error C1083: 'numpy/arrayobject.h', ensure the include path in the project properties points to your Anaconda environment's numpy headers (e.g., ...\Anaconda3\envs\caffe_py27\Lib\site-packages\numpy\core\include).
  • Python Path: Ensure the library paths point to the Python 2.7 libraries in your Conda environment.

9. Python Runtime Dependencies

After copying the generated caffe folder to your site-packages, you may face import errors.

import caffe
# Error: No module named skimage.io

Install the missing dependencies in your Conda environment:

conda install scikit-image
conda install -c menpo opencv  # Legacy opencv for python 2.7

10. Final Runtime Fixes

You might encounter specific numpy/skimage version conflicts:

  • numpy.coree._multiarray_umath: Upgrade numpy using pip install --upgrade numpy==1.16.3.
  • _validate_lengths: If skimage fails to import due to deprecated numpy functions, you may need to edit skimage/util/arraycrop.py to remove the import of _validate_lengths and implement a simple fallback or upgrade/downgrade the library versions to match compatibility.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.