博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在Ubuntu 20.04上安装TensorFlow
阅读量:2509 次
发布时间:2019-05-11

本文共 5996 字,大约阅读时间需要 19 分钟。

介绍 (Introduction)

An open-source machine learning software library, is used to train neural networks. Expressed in the form of , each node in the graph represents the operations performed by neural networks on multi-dimensional arrays. These multi-dimensional arrays are commonly known as “tensors,” hence the name TensorFlow.

是开放源代码的机器学习软件库,用于训练神经网络。 以的形式表示, 中的每个节点表示神经网络在多维数组上执行的操作。 这些多维数组通常称为“张量”,因此名称为TensorFlow。

In this tutorial, you’ll install TensorFlow in a Python virtual environment with virtualenv. This approach isolates the TensorFlow installation and gets things up and running quickly. Once you complete the installation, you’ll validate your installation by importing Tensorflow to ensure you have no errors.

在本教程中,您将使用virtualenv在Python虚拟环境中安装TensorFlow。 这种方法可以隔离TensorFlow安装并快速启动和运行。 完成安装后,您将通过导入Tensorflow来验证安装,以确保没有错误。

先决条件 (Prerequisites)

Before you begin this tutorial, you’ll need the following:

在开始本教程之前,您需要满足以下条件:

  • One Ubuntu 20.04 server with at least 4GB of RAM set up by following , including a sudo non-root user and a firewall.

    按照 (包括sudo非root用户和防火墙)设置一台至少具有4GB RAM

  • Python 3.8 or higher and virtualenv installed. Follow to configure Python and virtualenv.

    Python 3.8或更高版本并安装了virtualenv 。 遵循来配置Python和virtualenv

第1步-创建编程环境 (Step 1 — Creating a Programming Environment)

In this step, we’ll create a virtual environment in order to install TensorFlow into it without compromising our other programming projects. If you already have a clean programming environment set up, feel free to skip this step.

在此步骤中,我们将创建一个虚拟环境,以便将TensorFlow安装到其中,而不会影响其他编程项目。 如果您已经设置了干净的编程环境,请随时跳过此步骤。

First, create a project directory. We’ll call it tf-demo for demonstration purposes, but choose a directory name that is meaningful to you:

首先,创建一个项目目录。 出于演示目的,我们将其称为tf-demo ,但选择一个对您有意义的目录名称:

  • mkdir ~/tf-demo

    mkdir〜/ tf-demo

Navigate to your newly created tf-demo directory:

导航到新创建的tf-demo目录:

  • cd ~/tf-demo

    cd〜/ tf-demo

Then create a new virtual environment called tensorflow-dev, for instance. Run the following command to create the environment:

然后创建一个新的虚拟环境,例如tensorflow-dev 。 运行以下命令来创建环境:

  • python3 -m venv tensorflow-dev

    python3 -m venv tensorflow-dev

This creates a new tensorflow-dev directory which will contain all of the packages that you install while this environment is activated. It also includes pip and a standalone version of Python.

这将创建一个新的tensorflow-dev目录,其中将包含激活此环境时安装的所有软件包。 它还包括pip和Python的独立版本。

Now activate your virtual environment:

现在激活您的虚拟环境:

  • source tensorflow-dev/bin/activate

    源tensorflow-dev / bin / activate

Once activated, your terminal prompt will reflect that you are in the virtual environment:

激活后,您的终端提示将反映您处于虚拟环境中:

(tensorflow-dev)username@hostname:~/tf-demo $

At this point you can install TensorFlow in your virtual environment.

此时,您可以在虚拟环境中安装TensorFlow。

第2步—安装TensorFlow (Step 2 — Installing TensorFlow)

When installing TensorFlow, we want to make sure we are installing and upgrading to the newest version available in .

在安装TensorFlow时,我们要确保要安装并升级到可用的最新版本。

Therefore, we’ll be using the following command syntax with pip:

因此,我们将对pip使用以下命令语法:

  • pip install --upgrade tensorflow

    pip install --upgrade张量流

Once you press ENTER, TensorFlow will install, and you should receive output that indicates that the install along with any dependent packages was successful.

一旦按ENTER ,TensorFlow将安装,并且您应该收到输出,指示安装以及所有相关软件包均已成功。

Output   
...Successfully installed absl-py-0.7.1 astor-0.7.1 gast-0.2.2 grpcio-1.19.0 h5py-2.9.0 keras-applications-1.0.7 keras-preprocessing-1.0.9 markdown-3.0.1 mock-2.0.0 numpy-1.16.2 pbr-5.1.3 protobuf-3.7.0 setuptools-40.8.0 tensorboard-1.13.1 tensorflow-1.13.1 tensorflow-estimator-1.13.0 termcolor-1.1.0 werkzeug-0.15.0 wheel-0.33.1...Successfully installed bleach-1.5.0 enum34-1.1.6 html5lib-0.9999999 markdown-2.6.9 numpy-1.13.3 protobuf-3.5.0.post1 setuptools-38.2.3 six-1.11.0 tensorflow-1.4.0 tensorflow-tensorboard-0.4.0rc3 werkzeug-0.12.2 wheel-0.30.0

You can deactivate your virtual environment at any time by using the following command:

您可以随时使用以下命令停用虚拟环境:

  • deactivate

    停用

To reactivate the environment later, navigate to your project directory and run source tensorflow-dev/bin/activate.

要稍后重新激活环境,请导航到您的项目目录并运行source tensorflow-dev /bin/activate

Now that you have installed TensorFlow, let’s make sure the TensorFlow installation works.

现在您已经安装了TensorFlow,让我们确保TensorFlow安装正常。

步骤3 —验证安装 (Step 3 — Validating Installation)

To validate the installation of TensorFlow, we are going to ensure that we can import the TensorFlow package.

为了验证TensorFlow的安装,我们将确保我们可以导入TensorFlow软件包。

  • python

    Python

The following prompt will appear on your terminal:

以下提示将出现在您的终端上:

>>>

This is the prompt for the Python interpreter, and it indicates that it’s ready for you to start entering some Python statements.

这是Python解释器的提示,它表明您已经准备好开始输入一些Python语句。

First, type this line to import the TensorFlow package and make it available as the local variable tf. Press ENTER after typing in the line of code:

首先,输入以下行以导入TensorFlow软件包,并将其用作局部变量tf 。 在代码行中ENTER后按ENTER

  • import tensorflow as tf

    将tensorflow作为tf导入

As long as you have received no errors, you have installed TensorFlow successfully. If you have received an error, you should ensure that your server is powerful enough to handle TensorFlow. You may need to resize your server, making sure it has at least 4GB of memory.

只要没有收到任何错误,便表示您已成功安装TensorFlow。 如果收到错误,则应确保服务器足够强大以处理TensorFlow。 您可能需要调整服务器的大小,以确保它至少有4GB的内存。

结论 (Conclusion)

In this tutorial, you have installed TensorFlow in a Python virtual environment and validated that TensorFlow works by importing it.

在本教程中,您已在Python虚拟环境中安装了TensorFlow,并通过导入TensorFlow验证了该功能是否正常。

TensorFlow’s provides a useful resource and reference for TensorFlow development. You can also explore , a competitive environment for practical application of machine learning concepts that pit you against other machine learning, data science, and statistics enthusiasts.

TensorFlow的为TensorFlow开发提供了有用的资源和参考。 您还可以探索 ,这是一个实际应用机器学习概念的竞争环境,可让您与其他机器学习,数据科学和统计爱好者一道。

翻译自:

转载地址:http://johgb.baihongyu.com/

你可能感兴趣的文章
Centos MySQL数据库迁移详细步骤
查看>>
2初出茅庐--初级篇2.1
查看>>
新建 WinCE7.0 下的 Silverlight 工程
查看>>
腾讯的张小龙是一个怎样的人?
查看>>
jxl写入excel实现数据导出功能
查看>>
linux文件目录类命令|--cp指令
查看>>
.net MVC 404错误解决方法
查看>>
linux系统目录结构
查看>>
git
查看>>
btn按钮之间事件相互调用
查看>>
Entity Framework 4.3.1 级联删除
查看>>
codevs 1163:访问艺术馆
查看>>
冲刺Noip2017模拟赛3 解题报告——五十岚芒果酱
查看>>
并查集
查看>>
sessionStorage
查看>>
代码示例_进程
查看>>
Java中关键词之this,super的使用
查看>>
人工智能暑期课程实践项目——智能家居控制(一)
查看>>
前端数据可视化插件(二)图谱
查看>>
kafka web端管理工具 kafka-manager【转发】
查看>>