如何在 Windows 上安装 TensorFlow? [英] How to install TensorFlow on Windows?

查看:40
本文介绍了如何在 Windows 上安装 TensorFlow?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am starting to work with TensorFlow library for deep learning, https://www.tensorflow.org/.

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

I found a explicit guide to work on it on linux and Mac but I did not find how to work with it under Windows. I try over the net, but the information are lacking.

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

I use Visual Studio 2015 for my projects, and I am trying to compile the library with Visual studio Compiler VC14.

如何在Windows下安装和使用?

How to install it and to use it under Windows?

我可以将 Bazel for Windows 用于生产用途吗?

Can I use Bazel for Windows for production use?

推荐答案

如何安装TensorFlow并在Windows下使用?

How to install TensorFlow and to use it under Windows?

2016 年 8 月 4 日更新

Windows 10 现在有一个 Ubuntu Bash 环境,也就是 Bash on Ubuntu on Windows,作为标准选项提供(与 面向开发人员的 Insider Preview 更新).(StackOverflow 标记 wsl)此选项随 Windows 10 周年更新(版本 1607)于 2016 年 8 月 2 日发布.这允许使用 apt-get 来安装软件包,例如 PythonTensorFlow.

Windows 10 now has a Ubuntu Bash environment, AKA Bash on Ubuntu on Windows, available as a standard option (as opposed to Insider Preview updates for developers). (StackOverflow tag wsl) This option came with the Windows 10 anniversary update (Version 1607) released on 8/2/2016. This allows the use of apt-get to install software packages such as Python and TensorFlow.

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

Note: Bash on Ubuntu on Windows does not have access to the GPU, so all of the GPU options for installing TensorFlow will not work.

Bash on Ubuntu on Windows 的过时安装说明基本上是正确,但只需要这些步骤:
先决条件
启用适用于 Linux 的 Windows 子系统功能 (GUI)
出现提示时重新启动
在 Windows 上运行 Bash

The dated installation instructions for Bash on Ubuntu on Windows are basically correct, but only these steps are necessary:
Prerequisites
Enable the Windows Subsystem for Linux feature (GUI)
Reboot when prompted
Run Bash on Windows

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

Steps no longer needed:
Turn on Developer Mode
Enable the Windows Subsystem for Linux feature (command-line)

然后使用 apt-get 安装 TensorFlow

Then install TensorFlow using apt-get

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

and now test 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()

并运行一个实际的神经网络

and run an actual neural network

python3 -m tensorflow.models.image.mnist.convolutional

较早的回答

了解 Windows 上的 Bash 开发者预览版后.

Earlier Answer

After learning about the developer preview of Bash on Windows.

参见 Scott Hanselman 的 在 Windows 上使用 TensorFlowhttp://www.hanselman.com/blog/DevelopersCanRunBashShellAndUsermodeUbuntuLinuxBinariesOnWindows10.aspx" rel="noreferrer">Windows 10 上的 Bash

See Playing with TensorFlow on Windows by Scott Hanselman which uses Bash on Windows 10

巴泽尔是问题

TensorFlow 不是使用 构建自动化工具制作的,例如 make,但使用 Google 的内部构建工具 巴泽尔.Bazel 仅适用于基于 Unix 的系统,例如 LinuxOS X.

TensorFlow is not made with build automation tools such as make, but with Google's in-house build tool Bazel. Bazel only works on systems based on Unix such as Linux and OS X.

由于当前已发布/已知的构建 TensorFlow 的方法使用 Bazel 并且 Bazel 在 Windows 上不起作用,因此不能在 Windows 上本地安装或运行 TensorFlow.

Since the current published/known means to build TensorFlow uses Bazel and Bazel does not work on Windows, one can not install or run TensorFlow natively on Windows.

来自 Bazel 常见问题

Windows 怎么样?

What about Windows?

由于其 UNIX 传统,将 Bazel 移植到 Windows 意义重大工作.例如,Bazel 广泛使用符号链接,它具有不同的跨 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.

我们目前正在积极致力于改进 Windows 支持,但是距离可用还有很长的路要走.

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

状态

请参阅:TensorFlow 问题 #17
请参阅:Bazel 问题 #276

解决方案按照复杂性和所需工作的顺序列出;从大约一个小时到甚至可能无法工作.

The solutions are listed in the order of complexity and work needed; from about an hour to may not even work.

  1. Docker
    约 1 小时

Docker 安装

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

Docker is a system to build self contained versions of a Linux operating system running on your machine. When you install and run TensorFlow via Docker it completely isolates the installation from pre-existing packages on your machine.

另请参阅TensorFlow - 要使用哪个 Docker 映像?

  1. OS X
    约 1 小时

如果您当前使用的是运行 OS X 的 Mac,请参阅:Mac OS X 安装

If you have a current Mac running OS X then see: Installation for Mac OS X

  1. Linux

推荐 Linux 系统趋于成为 Ubuntu 14.04 LTS (下载页面).

一个.虚拟机 - 硬件虚拟化 - 完全虚拟化
~ 3 小时

a. Virtual Machine - Hardware Virtualization - Full Virtualization
~ 3 hours

下载并安装虚拟机,例如商用 VMware 或免费的 Virtual Box,之后就可以安装Linux,再安装TensorFlow.

Download and install a virtual machine such as the commercial VMware or the free Virtual Box, after which you can install Linux and then install TensorFlow.

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

When you go to install TensorFlow you will be using Pip - Python's package management system. Visual Studio users should think NuGet. The packages are known as wheels.

请参阅:Pip 安装

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

If you need to build from the source then see: Installing From Sources
~ 4 hours

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

Note: If you plan on using a Virtual Machine and have never done so before, consider using the Docker option instead, since Docker is the Virtual Machine, OS and TensorFlow all packaged together.

B.双启动
~ 3 小时

b. Dual boot
~ 3 hours

如果您想在装有 Windows 的同一台机器上运行 TensorFlow 并使用 GPU 版本,那么您很可能必须将此选项用作在托管虚拟机上运行,​​类型 2 管理程序,将不允许您访问 GPU.

If you want to run TensorFlow on the same machine that you have Windows and make use of the GPU version then you will most likely have to use this option as running on a hosted Virtual Machine, Type 2 hypervisor, will not allow you access to the GPU.

  1. 远程机器
    ~ 4 小时

如果您可以远程访问另一台可以安装 Linux 操作系统和 TensorFlow 软件的机器并允许远程连接到,然后您可以使用您的 Windows 机器将远程机器呈现为在 Windows 上运行的应用程序.

If you have remote access to another machine that you can install the Linux OS and TensorFlow software on and allow remote connections to, then you can use your Windows machine to present the remote machine as an application running on Windows.

  1. 云服务
    我没有这方面的经验.如果您知道,请编辑答案.

服务,例如 AWS 正在使用.

Cloud services such as AWS are being used.

来自 TensorFlow 功能

想要在云中将模型作为服务运行?使用 Docker 和 TensorFlow 进行容器化很有效.

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

来自 Docker

在 AWS 上运行 Docker 提供了一种高度可靠、低成本的方式快速大规模构建、发布和运行分布式应用程序.部署Docker 使用来自 AWS Marketplace 的 AMI.

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.

  1. 等待 Bazel 在 Windows 上工作.

目前看来唯一的障碍是 Bazel,但是 Bazel 的路线图 应该可以在 Windows 上使用今年.

Currently it appears the only hold up is Bazel, however Bazel's roadmap list working on Windows should be available this year.

为 Windows 列出了两个功能:

There are two features listed for 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.

  1. 手动构建 TensorFlow.
    几天或更长时间取决于您的技能水平.我放弃了这个;要构建的子项目和要定位的文件太多.

请记住,Bazel 仅用于构建 TensorFlow.如果您获得 Bazel 运行的命令以及正确的源代码和库,您应该能够在 Windows 上构建 TensorFlow.请参阅:如何获取 Bazel 执行的命令.

Remember that Bazel is only used to build TensorFlow. If you get the commands Bazel runs and the correct source code and libraries you should be able to build TensorFlow on Windows. See: How do I get the commands executed by Bazel.

虽然我没有对此进行更多研究,但您可以查看持续集成信息以了解需要文件和有关如何构建它以进行测试的信息.(自述文件)(网站)

While I have not researched this more, you can look at the continuous integration info for needed files and info on how to they build it for testing. (Readme) (site)

  1. 在 Windows 上构建 Bazel
    几天或更长时间取决于您的技能水平.我也放弃了这个;找不到 Windows 所需的必要源文件.

有一个 Bazel 的公开实验源代码版本在 Windows 上.您可以利用这一点让 Bazel 在 Windows 等上工作.

There is a public experimental source code version of Bazel that boots on Windows. You may be able to leverage this into getting Bazel to work on Windows, etc.

此外,这些解决方案需要使用 CygwinMinGW 这又增加了一层复杂性.

Also these solutions require the use of Cygwin or MinGW which adds another layer of complexity.

  1. 使用替代构建系统,例如 Make
    如果你让这个工作起来,我希望在 GitHub 上看到.

目前不存在 TensorFlow.这是一个功能请求.

This currently does not exist for TensorFlow. It is a feature request.

参见:TensorFlow 问题 380

  1. 交叉构建
    如果你让这个工作起来,我希望在 GitHub 上看到.

您使用 Bazel 在 Linux 上构建 TensorFlow,但更改构建过程以输出可安装在 Windows 上的轮子.这将需要 Bazel 的详细知识来更改配置,并找到适用于 Windows 的源代码和库.我只建议作为最后手段的一个选项.这甚至可能是不可能的.

You build TensorFlow on Linux using Bazel but change the build process to output a wheel that can be installed on Windows. This will require detailed knowledge of Bazel to change the configuration, and locating the source code and libraries that work with Windows. An option I would only suggest as a last resort. It may not even be possible.

  1. 在适用于 Linux 的新 Windows 子系统上运行.

请参阅:Windows 子系统Linux 概览

通过阅读参考文章,您会和我一样了解.

You will know as much as I do by reading the referenced article.

我可以将 Bazel for Windows 用于生产用途吗?

Can I use Bazel for Windows for production use?

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

Since it is experimental software I would not use on a production machine.

请记住,您只需要 Bazel 即可构建 TensorFlow.所以在非生产机器上使用实验代码构建轮子,然后在生产机器上安装轮子.请参阅:Pip 安装

Remember that you only need Bazel to build TensorFlow. So use the experimental code on a non production machine to build the wheel, then install the wheel on a production machine. See: Pip Installation

TLDR;

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

Currently I have several versions for learning. Most use a VMWare 7.1 Workstation to host Ubuntu 14.04 LTS or Ubuntu 15 or Debian. I also have one dual boot of Ubuntu 14.04 LTS on my Windows machine to access the GPU as the machine with VMware does not have the proper GPU. I would recommend that you give these machines at least 8G of memory either as RAM or RAM and swap space as I have run out of memory a few times.

这篇关于如何在 Windows 上安装 TensorFlow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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