Troubleshooting DLIBDOTNET and FaceRecognitionDotNet CUDA libraries

I’ve been building a Facial Recognition C# application leveraging the DLIBDOTNET and FaceRecognitionDotNet libraries. I tested a variety of free libraries and this is the most accurate at reliably predicating/recognizing faces. It also does a decent job of differentiating people of color.

There are two libraries, the regular “FaceRecognitionDotNet” library and the CUDA versions. Although it isn’t necessary to have CUDA to use this library, the recognition will be much faster if you leverage the CUDA version.

It’s been a process to get the CUDA version of these two libraries to work but it’s been worth it. Here’s a guide that could help you troubleshoot if you are having difficulties getting this to work.

What you’ll need & Steps

Although not necessary, the setup may work more smoothly if you follow these steps in this order.

  1. 64 bit Intel CPU. Visit the GitHub repository for current supported CPUs.
  2. Nvidia CUDA supported GPU
  3. Visual Studios 2019 & NET CORE 2.0+. I initially wrote my application using the old school Visual Studios Forms. After banging my head against the wall, I did some research and found out that WPF type applications have more native support for GPU applications. After switching to .NET Core 2.0 and a WPF application, I finally got the CUDA version of this library to work.
  4. Nvidia CUDA development kit. The CUDA Nvidia development kit will detect your graphics card and will most likely install an older graphics card driver. Let it install the older version otherwise you will get an error message during the install. After the install completes, reinstall the most current Nvidia drivers for your graphics card. It’s also important to install Visual Studios before the CUDA development kit because the installation package will attempt to install integration tools for Visual Studios. After installation is complete, make sure CUDA was installed properly by running one or more of the sample projects. You shouldn’t receive error messages after building and running the sample project. This is how you know it was installed properly.
  5. NVIDIA cuDNN – Follow the instructions on NVIDIA’s website to install cuDNN. You are simply just copying files into the CUDA installation directory. Yes, there isn’t anymore to the cuDNN installation. I used version 10.0. I also tested with newer version of CUDA however these tests were unsuccessful so I decided to stick with 10.0. Remember, you need to install the CUDA development kit before attempting to install cuDNN.
  6. You will also need at least 25 Gigs free space on the drive that has Windows. Visual Studios, CUDA and NVIDIA graphic drivers are bulky.

This is using a barebones Visual Studios installation. The DLIBDOTNET notes on NuGet mention that you need these files. Visual C++ 2017 Redistributable Package, cublas64_92.dll, cudnn64_7.dll, curand64_92.dll and cusolver64_92.dll. I attempted to simply just install the latest Visual C++ 2019 Redistributable and that itself didn’t work so I installed a few other C++ and .NET CORE components. See below for my barebones install of Visual Studios.

Individual Components

.NET

  • .NET Core 2.1 LTS Runtime
  • .NET Core 3.1 LTS Runtime
  • .NET Core SDK
  • NuGet package manager
  • .NET Framework 4.6.1 targeting pack
  • .NET Framework 4.7.2 SDK
  • .NET Framework 4.7.2 targeting pack
  • .NET Framework 4.8 SDK
  • .NET Native
  • .NET Portable Library targeting pack
  • Development Tools plus .NET Core 2.1

Cloud, database, and server

  • CLR data types for SQL Server

Code tools

  • C# and Visual Basic Roslyn compliers
  • C++ 2019 Redistributable MSMs
  • C++ 2019 Redistributable Update
  • C++ Cmake tools for Windows
  • MSBuild
  • MSVC v142 – VS 2019 C++ x64/x86 build tools (v14.25)

Debugging and testing

  • .NET profiling tools
  • C++ AddressSanitizer (Experimental)
  • C++ profiling tools
  • Just-in-Time debugger

Development activities

  • C# and Visual Basic
  • C++ core features
  • F# language support
  • IntelliCode

Games and Graphics

  • Graphics debugger and GPU profiler for DirectX

SDK, libraries and frameworks

  • C++ ATL for latest v142 build tools (x86 & x64)
  • Windows 10 SDK(10.0.18362.0)

After you are done with the above steps, create a simple Windows WPF .NET CORE application and run call the “TryGetDriverVersion” function. Sample code below. If everything was installed properly, you should see an output like this

“***HELLO CUDA Version:10010”

using DlibDotNet;

//C# example code to check if DLIB Cuda is installed properly. Make sure you are using the CUDA version from NuGet

 Cuda.TryGetDriverVersion(out int version);
         Debug.WriteLine("***************************************HELLO CUDA Version:" + version.ToString()) ;

I’ve been able to get this to work with a few different CUDA supported GPUs following the instructions above. Enjoying coding.