Build Tensorflow on one system, deploy on another

2019-08-18 16:39发布

How can I deploy TensorFlow on a different computer from the one I build it on? Which files need to be copied across? Building from source on each and every target PC is impractical. In my case I need to build from source since the standard install of TensorFlow is not optimized for my target (non-GPU build but with AVX/AVX2 available), not that that should make any difference. I am building & deploying on Windows PCs, which almost certainly will make a difference.

1条回答
Melony?
2楼-- · 2019-08-18 17:22

Think: python. Tensorflow is essentially a python package, and python packages are installed with pip.

In this specific case, the standard installation of TensorFlow (version 1.5) was easily installed on my target system using pip3 install --upgrade tensorflow as per standard TensorFlow instructions. But when I tested examples I had already developed I was warned that the install was not optimal, since AVX and AVX2 instructions were available, but not being used.

To rebuild Tensorflow from source to make use of AVX2, follow instructions here, in particular:

  • Obtain the source from github: git clone https://github.com/tensorflow/tensorflow
  • Choose either the Bazel or CMake build option (I chose CMake, which required SWIG)
  • Customise the build to specify use of AVX or AVX2 (for me, I added -Dtensorflow_WIN_CPU_SIMD_OPTIONS=/arch:AVX2 to the options during the CMake step)
  • build the tensorflow python pip package (very last instruction in the CMake step-by-step instructions)

Once you have the package (a wheel or .whl) file, move it to the target PC, and install it using pip3 install tensorflow-<version-specific-details>.whl.

This process has been tested on:

  • Development PC: Windows 7-64 bit, Python 3.6.4 (64-bit), SWIG 3.0.12
  • Target PC: Windows 8.1 Pro (64-bit), Python 3.6.4 (64-bit)

For the record, the use of AVX2 instructions gave me approximately a 20% speed increase on my network training. Also, despite one of the known limitations being the need to use Python 3.5 for the CMake build, I have found no issue (so far) using Python 3.6.4.

查看更多
登录 后发表回答