Building libraries of TensorFlow neuronetsin Windows environment

Сonvolutional neural networks (CNN) development and testing in the Python environment currently does not cause any difficulties. Many ready-made frameworks are available for implementing CNN of any kind of structure. Difficulties usually arise when you need to implement CNN outside of Python, for example in C ++, in some program to run on Windows. Prediction functionality typically needs to be implemented on a trained model.

Let's say wehavecreated a TensorFlow or kerasmodel, trained and saved it (usually in hdf5 format). Next we want to write the predict function in C ++ language in the Windows 7x64 or higher environment, load the model, some data and get the network response. There are a lot of similar examples in C ++, but you will need TensorFlow libraries to build any of them. This article describes the steps to build TensorFlow libraries, version 1.10.0 using CMake.

SystemREQUIREMENTS

Windows 7 x64 or higher, 16Gb RAM, 128Gb SSD (HDD will also work, of course, but it will be slower)

Python environmentDownload and install the Anaconda package. This is a fully configured Python along with a pre-installed set of the most popular modules. During the installation process, do not forget to tick the box to add the package to the system variable PATH.

CMake, Git, SWIGDownload and install CMake for Windows. Add the installation path to the PATH.Download and install Git for Windows. Add the installation path to the PATH.Download and install SWIG. This package provides the ability to call functions written in onelanguages from code in other languages.CUDAOptional. We have test version 9.0Run the environment preparation script C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat

tensorflow_ENABLE_GRPC_SUPPORT, in fact, we don't need it, but without it, I didn't want to assemble a project.

tensorflow_BUILD_SHARED_LIB needs to be enabled because our goal is to get the DLL library

tensorflow_ENABLE_GPU - if enabled, then you need to install the CUDA Development Tools package (I compiled with version 9.0) and the project will be assembled twice as long.

tensorflow_WIN_CPU_SIMD_OPTIONS - flag for using new sets of instructions. This flag must be set carefully. If you install AVX2, the assembly will not work on processors where this instruction set does not exist.

There have been several attempts to use the Intel MKL libraries — these are optimized algorithms for convolutional networks. Oddly enough, the inclusion of these libraries slowed down the work of models by almost two times. It may well be that I missed something, but decided to remove them from the configuration.

After running this configuration file, all the files for the build will be created.

If you have a multicore processor, you can set the parameter / m: 3 and / p: CL_MPCount = 3 this will speed up the build process.After running the script, the build process begins and you can safely go for a walk for a couple of hours. If you plan to build libraries using CUDA, you can walk for four hours.After the build process is complete, the following directory will appear: C: \ src \ tensorflow \ v1.10.0.cpu \ tensorflow \ contrib \ cmake \ build \ Release where you can find our compiled libraries tensorflow.dll, tensorflow.lib, tensorflow.def

In conclusion, please note that all actions described above, the TensorFlow developers consider to be unofficial and in the future, probably, the possibility of assembling via CMake will not be possible. However, for the time being, this is the only way to build your TensorFlow library.