在一个系统上构建Tensorflow,在另一个系统上部署 [英] Build Tensorflow on one system, deploy on another

查看:70
本文介绍了在一个系统上构建Tensorflow,在另一个系统上部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 TensorFlow 部署在与构建它的计算机不同的计算机上?需要复制哪些文件?在每台目标PC上从源代码构建都是不切实际的。就我而言,我需要从源代码构建,因为 TensorFlow 的标准安装并未针对我的目标进行优化(非GPU构建,但具有AVX / AVX2),不是那样应该有所作为。我正在建造&

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.

推荐答案

思考: python Tensorflow 本质上是一个python软件包,并且python软件包使用 pip 安装。

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

在这种特定情况下,使用 pip3 install可以很容易地在目标系统上安装 TensorFlow (1.5版)的标准安装- -根据标准TensorFlow指示升级tensorflow 。但是,当我测试了已经开发的示例时,由于 AVX AVX2 指令而被警告安装不是最佳的可用,但未被使用。

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.

从源头重建 Tensorflow 来利用 AVX2 ,请遵循此处的说明,尤其是:

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


  • 从github获取源代码: git clone https://github.com/tensorflow/tensorflow

  • 选择Bazel或CMake构建选项(我选择了 CMake ,这需要 SWIG

  • 自定义构建以指定使用 AVX AVX2 (对我来说,我在 CMake 步骤中将 -Dtensorflow_WIN_CPU_SIMD_OPTIONS = / arch:AVX2 添加到选项中) / li>
  • 构建tensorflow python pip软件包( CMake 中的最后一条说明p指令)

  • 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)

一旦您收到了包裹(滚轮 .whl )文件,将其移至目标PC,然后使用 pip3 install tensorflow-< version-specific-details> .whl

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.

此过程已经过测试:


  • 开发PC:Windows 7-64位,Python 3.6.4(64位),SWIG 3.0.12

  • 目标PC:Windows 8.1 Pro(64位),Python 3.6.4( 64位)

出于记录目的,使用 AVX2 指令我的网络培训速度提高了大约20%。另外,尽管已知的限制之一是需要使用Python 3.5进行CMake构建,但到目前为止,我发现使用Python 3.6.4并没有问题。

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.

这篇关于在一个系统上构建Tensorflow,在另一个系统上部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆