Python机器学习项目
在开发识别程序之前,你需要安装一些依赖项并创建一个工作区来存放你的文件。
我们将使用 Python 3 虚拟环境来管理我们项目的依赖项。为你的项目创建一个新目录并进入该目录:
mkdir tensorflow-demo
cd tensorflow-demo
执行以下命令来为本教程设置虚拟环境:
python3 -m venv tensorflow-demo
source tensorflow-demo/bin/activate
接下来,安装本教程中将使用的库。我们将通过在项目目录中创建一个 requirements.txt
文件来指定所需的库及其特定版本。创建 requirements.txt
文件:
(tensorflow-demo) $ touch requirements.txt
在你的文本编辑器中打开该文件,并添加以下行来指定 Image、NumPy 和 TensorFlow 库及其版本:
requirements.txt
image==1.5.20
numpy==1.14.3
tensorflow==1.4.0
保存文件并退出编辑器。然后使用以下命令安装这些库:
(tensorflow-demo) $ pip install -r requirements.txt
安装好依赖项后,我们就可以开始我们的项目了。
你准备好进入下一步了吗?
Step 1 — Configuring the Project
Before you can develop the recognition program, you’ll need to install a
few dependencies and create a workspace to hold your files.
We’ll use a Python 3 virtual environment to manage our project’s
dependencies. Create a new directory for your project and navigate to the
new directory:
mkdir tensorflow-demo
cd tensorflow-demo
Execute the following commands to set up the virtual environment for
this tutorial:
python3 -m venv tensorflow-demo
source tensorflow-demo/bin/activate
Next, install the libraries you’ll use in this tutorial. We’ll use specific
versions of these libraries by creating a requirements.txt file in the
project directory which specifies the requirement and the version we
need. Create the requirements.txt file:
(tensorflow-demo) $ touch requirements.txt
Open the file in your text editor and add the following lines to specify
the Image, NumPy, and TensorFlow libraries and their versions:
requirements.txt
image==1.5.20
numpy==1.14.3
tensorflow==1.4.0
Save the file and exit the editor. Then install these libraries with the
following command:
(tensorflow-demo) $ pip install -r requirements.txt
With the dependencies installed, we can start working on our project.