c++ - 如何在 Windows 上安装 TensorFlow?

标签 c++ windows visual-studio machine-learning tensorflow

我开始使用 TensorFlow 库进行深度学习,https://www.tensorflow.org/ .

我找到了在 linux 和 Mac 上使用它的明确指南,但我没有找到如何在 Windows 下使用它。我尝试通过网络,但缺乏信息。

我将 Visual Studio 2015 用于我的项目,并且我正在尝试使用 Visual Studio Compiler VC14 编译库。

如何在 Windows 下安装和使用它?

我可以用Bazel for Windows 用于生产?

最佳答案

How to install TensorFlow and to use it under Windows?



16 年 8 月 4 日更新

Windows 10 现在有一个 Ubuntu Bash 环境,又名 Bash on Ubuntu on Windows ,作为标准选项提供(与 Insider Preview updates for developers 相反)。 (StackOverflow 标记 wsl)此选项随 Windows 10 anniversary update 一起提供(版本 1607)于 2016 年 8 月 2 日发布。这允许使用 apt-get安装 Python 等软件包和 TensorFlow .

注意:Windows 上的 Ubuntu 上的 Bash 无法访问 GPU,因此用于安装 TensorFlow 的所有 GPU 选项都不起作用。

日期 installation instructions对于 Windows 上的 Ubuntu 上的 Bash 基本上是正确的,但只有这些步骤是必要的:
先决条件
启用适用于 Linux 的 Windows 子系统功能 (GUI)
出现提示时重新启动
在 Windows 上运行 Bash

不再需要的步骤:
开启开发者模式
启用适用于 Linux 的 Windows 子系统功能(命令行)

然后使用 apt-get 安装 TensorFlow
sudo apt-get install python3-pip python3-dev
sudo pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl 

现在测试 TensorFlow
$ python3
...
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>> exit()

并运行一个实际的神经网络
python3 -m tensorflow.models.image.mnist.convolutional

较早的回答

在了解了 Windows 上的 Bash 开发者预览版之后。

Playing with TensorFlow on Windows作者 Scott Hanselman,使用 Bash on Windows 10

原答案

巴泽尔是问题

TensorFlow 不是用 build automation tools 制作的如 make ,但使用 Google 的内部构建工具 Bazel . Bazel 仅适用于基于 Unix 的系统如 LinuxOS X .

由于当前已发布/已知的构建 TensorFlow 的方法使用 Bazel Bazel 不能在 Windows 上运行,不能在 Windows 上本地安装或运行 TensorFlow。

来自 Bazel FAQ

What about Windows?

Due to its UNIX heritage, porting Bazel to Windows is significant work. For example, Bazel uses symlinks extensively, which has varying levels of support across Windows versions.

We are currently actively working on improving Windows support, but it's still ways from being usable.



地位

见:TensorFlow issue #17
见:Bazel issue #276

解决方案

解决方案按照复杂性和所需工作的顺序列出;从大约一个小时到甚至可能都不起作用。
  • Docker
    ~ 1 小时

  • Docker installation

    Docker 是一个系统,用于构建在您的机器上运行的 Linux 操作系统的自包含版本。当您通过 Docker 安装和运行 TensorFlow 时,它会将安装与您机器上预先存在的软件包完全隔离。

    还看TensorFlow - which Docker image to use?
  • 操作系统
    ~ 1 小时

  • 如果您当前使用的是运行 OS X 的 Mac,请查看:Installation for Mac OS X
  • Linux

  • recommend Linux system往往是 Ubuntu 14.04 LTS ( Download page )。

    一种。虚拟机 - Hardware Virtualization - Full Virtualization
    ~ 3 小时

    下载安装虚拟机如商用VMware或免费 Virtual Box ,之后您可以安装 Linux,然后安装 TensorFlow。

    当您去安装 TensorFlow 时,您将使用 Pip - Python 的包管理系统。 Visual Studio 用户应该考虑 NuGet。这些包被称为 wheels .

    见:Pip Installation

    如果您需要从源代码构建,请参阅:Installing From Sources
    ~ 4 小时

    注意:如果您计划使用虚拟机并且以前从未这样做过,请考虑使用 Docker 选项,因为 Docker 是虚拟机、操作系统和 TensorFlow 都打包在一起。

    Dual boot
    ~ 3 小时

    如果您想在装有 Windows 的同一台机器上运行 TensorFlow 并使用 GPU 版本,那么您很可能必须将此选项用作在托管虚拟机上运行,​​Type 2 hypervisor , 将不允许您访问 GPU。
  • 远程机器
    ~ 4 小时

  • 如果您有 remote access到另一台可以安装 Linux 操作系统和 TensorFlow 软件并允许远程连接的机器,然后您可以使用 Windows 机器将远程机器呈现为在 Windows 上运行的应用程序。
  • 云服务
    我没有这方面的经验。如果您知道,请编辑答案。

  • Cloud服务如 AWS正在使用。

    来自 TensorFlow Features

    Want to run the model as a service in the cloud? Containerize with Docker and TensorFlow just works.



    来自 Docker

    Running Docker on AWS provides a highly reliable, low-cost way to quickly build, ship, and run distributed applications at scale. Deploy Docker using AMIs from the AWS Marketplace.


  • 等待 Bazel 在 Windows 上工作。

  • 目前看来唯一的阻碍是 Bazel,但是 Bazel's roadmap在 Windows 上工作的列表今年应该可用。

    为 Windows 列出了两个功能:
    2016‑02  Bazel can bootstrap itself on Windows without requiring admin privileges.  
    
    2016‑12  Full Windows support for Android: Android feature set is identical for Windows and Linux/OS X.
    
  • 手动构建 TensorFlow。
    几天或更长时间取决于您的技能水平。我放弃了这个;要构建的子项目和要定位的文件太多。

  • 请记住,Bazel 仅用于构建 TensorFlow。如果您获得 Bazel 运行的命令以及正确的源代码和库,您应该能够在 Windows 上构建 TensorFlow。见:How do I get the commands executed by Bazel .

    虽然我没有对此进行更多研究,但您可以查看 continuous integration所需文件的信息以及有关如何构建它以进行测试的信息。 ( Readme ) ( site )
  • 在 Windows 上构建 Bazel
    几天或更长时间取决于您的技能水平。我也放弃了这个;找不到 Windows 所需的必要源文件。

  • Bazel that boots on Windows的公开实验源码版本.您可以利用这一点让 Bazel 在 Windows 等上工作。

    此外,这些解决方案需要使用 CygwinMinGW这增加了另一层复杂性。
  • 使用替代构建系统,例如 Make
    如果你让这个工作,我想在 GitHub 上看到。

  • 目前 TensorFlow 不存在此功能。这是一个功能请求。

    见:TensorFlow issue 380
  • 交叉构建
    如果你让这个工作,我想在 GitHub 上看到。

  • 您使用 Bazel 在 Linux 上构建 TensorFlow,但更改构建过程以输出可安装在 Windows 上的轮子。这将需要详细了解 Bazel 以更改配置,并找到适用于 Windows 的源代码和库。我只建议作为最后的手段的选项。它甚至可能是不可能的。
  • 在适用于 Linux 的新 Windows 子系统上运行。

  • 见:Windows Subsystem for Linux Overview

    通过阅读引用文章,您会和我一样了解。

    Can I use Bazel for Windows for production use?



    由于它是实验性软件,我不会在生产机器上使用。

    请记住,您只需要 Bazel 即可构建 TensorFlow。所以使用非生产机器上的实验代码来构建wheel ,然后将车轮安装在生产机器上。见:Pip Installation

    TLDR;

    目前我有几个版本可供学习。大多数使用 VMWare 7.1 工作站来托管 Ubuntu 14.04 LTS 或 Ubuntu 15 或 Debian。我的 Windows 机器上还有一个双启动 Ubuntu 14.04 LTS 来访问 GPU,因为装有 VMware 的机器没有合适的 GPU。我建议你给这些机器至少 8G 的内存作为 RAM 或 RAM 和交换空间,因为我有几次内存不足。

    关于c++ - 如何在 Windows 上安装 TensorFlow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34785414/

    相关文章:

    java - Maven Surefire 2.13 无法在 Windows 上 fork

    c++ - 如何使用 CMake 将 NMake 从 VS9 切换到 VS10

    c# - visual studio 2008 部署项目可以在系统未安装.net 的情况下运行吗?

    c++ - 将 unique_ptr 转移到另一个的有效和/或正确的方法是什么?

    c++ - 用于 C++ 游戏的通用 FSM?

    c++ - 如何将 qprocess 带到前面?

    C# 设计器 : Removing redundant code from Design. cs

    c++ - 为什么不允许使用此引用集?

    c++ - 断然阻止或阻止带有特定参数的对象实例化

    c++ - WinAPI SetWindowLongPtr - 改变 windowProc