0% found this document useful (0 votes)
107 views45 pages

HCIA-AI V3.0 Experiment Environment Setup Guide

This document provides guidance on setting up lab environments for the HCIA-AI certification training course on different operating systems (Windows, MacOS, Ubuntu). It covers downloading and installing Anaconda, creating virtual environments, installing TensorFlow and MindSpore, and using Huawei Cloud services. Background knowledge of Python, TensorFlow, and Python programming is recommended for understanding the course materials.

Uploaded by

Gamselo Selogams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views45 pages

HCIA-AI V3.0 Experiment Environment Setup Guide

This document provides guidance on setting up lab environments for the HCIA-AI certification training course on different operating systems (Windows, MacOS, Ubuntu). It covers downloading and installing Anaconda, creating virtual environments, installing TensorFlow and MindSpore, and using Huawei Cloud services. Background knowledge of Python, TensorFlow, and Python programming is recommended for understanding the course materials.

Uploaded by

Gamselo Selogams
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

HCIA-AI

Lab Environment Setup Guide


Issue: 3.0

Huawei Technologies Co., Ltd.


About This Document

Overview
This document is designed for the HCIA-AI certification training course and is intended for people
who wish to understand AI and TensorFlow programming basics. You can configure the lab
environment based on your actual environment.

Description
This document covers the following four parts:
⚫ Windows lab environment setup

⚫ MacOS lab environment setup

⚫ Ubuntu lab environment setup

⚫ HUAWEI CLOUD user guide

Background Knowledge Required


This course is a basic course for Huawei certification. To better understand this course, familiarize
yourself with the following requirements:
⚫ Basic Python knowledge

⚫ Basic concepts of TensorFlow

⚫ Basic Python programming knowledge


HCIA-AI Lab Environment Setup Guide V3.0 Page 1

Contents

About This Document ................................................................................................................. 2


Overview ............................................................................................................................................................................. 2
Description .......................................................................................................................................................................... 2
Background Knowledge Required ....................................................................................................................................... 2
1 Windows Lab Environment Setup ............................................................................................ 3
1.1 Installing Anaconda....................................................................................................................................................... 3
1.1.1 About Anaconda ........................................................................................................................................................ 3
1.1.2 Procedure .................................................................................................................................................................. 3
1.2 Changing Channels ........................................................................................................................................................ 7
1.2.1 Changing the conda Channel ..................................................................................................................................... 7
1.3 Installing TensorFlow .................................................................................................................................................... 7
1.3.1 About TensorFlow ...................................................................................................................................................... 7
1.3.2 Installing TensorFlow 2.1.0 CPU ................................................................................................................................ 8
1.4 Installing MindSpore ................................................................................................................................................... 10
1.4.1 About MindSpore .................................................................................................................................................... 10
1.4.2 Installing MindSpore 1.2 .......................................................................................................................................... 10
1.5 Anaconda Virtual Environments ................................................................................................................................. 11
1.5.1 Overview .................................................................................................................................................................. 11
1.5.2 Creating a Virtual Environment Using the Command Prompt ................................................................................. 11
1.5.3 Activating a Virtual Environment ............................................................................................................................. 12
1.5.4 Viewing a Virtual Environment ................................................................................................................................ 12
1.5.5 Deleting a Virtual Environment ............................................................................................................................... 13
1.6 Switching the Kernel in Jupyter Notebook ................................................................................................................. 14
1.6.1 Checking Jupyter Notebook ..................................................................................................................................... 14
1.6.2 Installing nb_conda_kernels .................................................................................................................................... 15
1.6.3 Installing ipykernel ................................................................................................................................................... 15
2 MacOS Lab Environment Setup .............................................................................................. 17
2.1 Overview ..................................................................................................................................................................... 17
2.1.1 About This Lab ......................................................................................................................................................... 17
2.1.2 Objectives ................................................................................................................................................................ 17
2.1.3 Modules Required for the Exercise .......................................................................................................................... 17
2.2 Downloading Anaconda and Configuring the Python Environment ........................................................................... 17
2.2.1 Downloading Anaconda ........................................................................................................................................... 18
2.2.2 Installing Anaconda.................................................................................................................................................. 18
2.2.3 Creating a Virtual Environment ............................................................................................................................... 18
2.2.4 Testing the Environment ......................................................................................................................................... 20
HCIA-AI Lab Environment Setup Guide V3.0 Page 2

2.3 Installing TensorFlow .................................................................................................................................................. 21


2.3.1 Installing TensorFlow 2.1.0 ...................................................................................................................................... 21
2.4 Installing Jupyter Notebook ........................................................................................................................................ 22
2.4.1 Using a Terminal ...................................................................................................................................................... 22
2.4.2 Using Anaconda Navigator ...................................................................................................................................... 24
2.5 Testing the Environment ............................................................................................................................................ 27
3 Ubuntu Lab Environment Setup ............................................................................................. 30
3.1 Installing Miniconda.................................................................................................................................................... 30
3.2 Creating Virtual Environments .................................................................................................................................... 34
3.3 Changing the pip Channel ........................................................................................................................................... 34
3.4 Installing MindSpore ................................................................................................................................................... 35
3.5 Installing TensorFlow (CPU Version) ........................................................................................................................... 36
4 HUAWEI CLOUD User Guide ................................................................................................... 36
4.1 Overview ..................................................................................................................................................................... 36
4.2 Account Application and Real-Name Authentication ................................................................................................. 37
4.2.1 HUAWEI CLOUD Accounts ....................................................................................................................................... 37
4.2.2 Registration .............................................................................................................................................................. 37
4.2.3 Application ............................................................................................................................................................... 39
4.3 Obtaining the AK and SK ............................................................................................................................................. 39
4.3.1 Overview .................................................................................................................................................................. 39
4.3.2 Generating the AK and SK ........................................................................................................................................ 40
4.4 Commonly Used HUAWEI CLOUD Products ............................................................................................................... 42
HCIA-AI Lab Environment Setup Guide V3.0 Page 3

1 Windows Lab Environment Setup

1.1 Installing Anaconda

1.1.1 About Anaconda


Anaconda is a distribution of the Python programming language for scientific computing. It supports
Linux, MacOS, and Windows operating systems (OSs) and provides the package and environment
management functions. It can easily cope with coexistence and switchover of multiple Python
versions and installation of various third-party packages. Anaconda uses the conda tool or command
to manage packages and environments. (You can also use pip.) In addition, Anaconda contains
Python and related tools. Anaconda is a Python tool for enterprise-level big data analysis. It contains
more than 720 open-source packages related to data science and covers data visualization, machine
learning, and deep learning. It can be used not only for data analysis, but also in the big data and
artificial intelligence (AI) fields.
Anaconda has the following features:
1. After the Anaconda is installed, you do not need to install Python. The Python version is
automatically selected during download.
2. During development, you may need different frameworks. In that case, you only need to add
virtual environments to Anaconda to achieve development in different environments without
compatibility issues. You can configure corresponding environments for special projects to facilitate
management.

1.1.2 Procedure

Step 1 Download Anaconda.


Download the installation package at https://www.anaconda.com/distribution/#download-section.
You can select the Windows, Mac, or Linux version based on your OS. In this example, select 64-Bit
Graphical Installer under Python 3.8, Windows. (This course does not support a 32-bit computer.)
HCIA-AI Lab Environment Setup Guide V3.0 Page 4

Figure 1-1

Step 2 Install Anaconda.


Double-click the downloaded Anaconda3-x.x.x-Windows-x86_64.exe file. In the displayed dialog box
as follows, click Next.

Figure 1-2

Click I Agree.
HCIA-AI Lab Environment Setup Guide V3.0 Page 5

Figure 1-3

Choose Just me for Install for and click Next.

Figure 1-4

Step 3 Choose the installation directory.


Choose the installation directory for the software and click Next.
HCIA-AI Lab Environment Setup Guide V3.0 Page 6

Figure 1-5

Step 4 Set the environment variables.


Select both options. The first option adds environment variables. The second option uses Python 3.8
by default, which reduces subsequent configuration steps. Then, click Install to start the installation.
(Note: If you have installed another version of Python on the local host, we recommend that you
delete it before installing Anaconda. If it is not deleted, deselect the two options. Otherwise, a path
error may occur.)

Figure 1-6

After the installation is complete, click Finish.


HCIA-AI Lab Environment Setup Guide V3.0 Page 7

1.2 Changing Channels

1.2.1 Changing the conda Channel


Generally, the use of conda or pip commands downloads required module packages from a server
outside China. This takes a long time when the network is poor. Therefore, it is recommended that
you download the module from a source in China, which greatly improves the download speed.
On the command prompt interface, run the following command to change the conda channel to the
Tsinghua source.

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/Anaconda/pkgs/free/


conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/Anaconda/pkgs/main/

See the following example:

Figure 1-7

Note: When installing Jupyter Notebook or Spyder, it is recommended that you use conda
installation. After conda is installed, the corresponding icon is displayed in the start menu, and the
virtual environment to which the IDE belongs is marked in the parentheses next to the IDE name to
facilitate startup. See the following example:

Figure 1-8

1.3 Installing TensorFlow


If you want to install multiple frameworks, create a virtual environment first. For details, see section
1.5 "Anaconda Virtual Environments". To install only one framework, you can directly start the
installation after changing the channel.

1.3.1 About TensorFlow


TensorFlow is the second-generation AI learning system developed by Google based on DistBelief. Its
name derives from its own operating principle. The graph nodes represent mathematical operations,
while the graph edges represent the multidimensional data arrays (tensors) that flow between them.
TensorFlow is a system that transmits complex data structures to AI neural networks for analysis and
processing.
TensorFlow 2.1.0 focuses on simplicity and ease of use, featuring easy to use, powerful, and scalable.
It provides the following updates:
⚫ Introduction of the Keras module
⚫ Eager execution (dynamic graph mechanism)
HCIA-AI Lab Environment Setup Guide V3.0 Page 8

⚫ Support for more platforms and languages


⚫ Removal of deprecated APIs and reduction of duplicate APIs
⚫ Compatibility and continuity

1.3.2 Installing TensorFlow 2.1.0 CPU

Step 1 Install TensorFlow 2.1.0 CPU.


After the Anaconda is installed, open the Terminal window of the Anaconda in the start menu. See
the following figure:

Figure 1-9

Before installation, ensure that the computer is properly connected to the network.

Step 2 Create a virtual environment. A virtual environment is created to ensure that a single
framework is available in a single environment, which facilitates development. The
relationship between a virtual environment and a framework is similar to that between a
virtual machine and a system. When you create a new virtual environment, you can install a
new framework. Run the following command to create a virtual environment:

conda create –n tf21 python==3.6.5

The italic part in red is the name of the virtual environment, which can be customized.

Figure 1-10
Note: TensorFlow 2.1.0 is not compatible with Python 3.7 and later versions. Therefore, it is
recommended that you install Python 3.6.5 in the virtual environment.

Step 3 Enter y if y/n is displayed during the installation.


Step 4 After the installation is complete, run the activate tf21 command to start the virtual
environment. The italic part in red is the name of the virtual environment created in Step 2.

Step 5 Run the pip install tensorflow-cpu==2.1.0 command, as shown in the following figure:
HCIA-AI Lab Environment Setup Guide V3.0 Page 9

Figure 1-11

If the default channel is not changed, we recommend that you run the following command to
change the channel to one in China:
pip install tensorflow-cpu==2.1.0 -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com
If Successfully is displayed, the installation is successful.

Figure 1-12

Step 6 Python modules required for this exercise, such as pandas numpy scikit-image, are installed
along with Anaconda. Therefore, you do not need to install the modules separately.
However, if a required module does not exist, run the pip install + installation package
name command to install it. In the follow example, enter pip install matplotlib:

Figure 1-13

Step 7 Check the installation.


Run the pip list command to check all installed Python modules. The command output is as follows:
HCIA-AI Lab Environment Setup Guide V3.0 Page 10

Figure 1-14

1.4 Installing MindSpore

1.4.1 About MindSpore


MindSpore is a Huawei-developed AI computing framework that implements on-demand device-
edge-cloud synergy in all scenarios. It provides unified APIs for all scenarios and provides end-to-end
capabilities for AI model development, running, and deployment in all scenarios.
MindSpore uses the device-edge-cloud collaborative distributed architecture, new paradigm of
differential native programming, and new execution mode of AI Native to achieve better resource
efficiency, security, and reliability, lower the AI development threshold in the industry, and release
the computing power of Ascend chips, helping achieve inclusive AI.

1.4.2 Installing MindSpore 1.2

Step 1 Open a new command line window and create a virtual environment. For details, see section
1.5 "Anaconda Virtual Environments." Ensure that the Python version is 3.7.5. You can run
the following command to specify the version:

conda create –n MindSpore python==3.7.5

The italic part in red is the environment name, which can be customized.
Note: Python versions other than 3.7.5 are not supported.

Step 2 Run the activate command to activate the virtual environment. (The italic part in red is the
environment name.)

activate MindSpore

Step 3 Run the following command to install MindSpore 1.2. Alternatively, go to the official website
https://www.mindspore.cn/install to obtain the latest version.

pip install https://ms-release.obs.cn-north-


4.myhuaweicloud.com/1.2.0/MindSpore/cpu/windows_x64/mindspore-1.2.0-cp37-cp37m-win_amd64.whl --
trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple

Step 4 After the installation succeeds, enter Python in the command line window to access the
development environment. Run the following command to import MindSpore. If no error is
reported, the installation is successful.

Import mindspore
HCIA-AI Lab Environment Setup Guide V3.0 Page 11

1.5 Anaconda Virtual Environments

1.5.1 Overview
Anaconda allows you to virtualize multiple Python environments that are irrelevant to each other on
the local host. This feature helps boost its popularity. When chaotic dependence exists among
different Python modules or different development frameworks exist, you can use virtual
environments to isolate them.
Note: Modules are independent of each other in different virtual environments. That is, if you
installed TensorFlow in environment A, to use TensorFlow in environment B, you need to install
TensorFlow in environment B. This mechanism also applies to Spyder and Jupyter Notebook.

1.5.2 Creating a Virtual Environment Using the Command Prompt

Step 1 Search for cmd in the search box on the taskbar to open the command prompt.
Step 2 Run the conda create –n environment name python==x.x command. The environment name
can be customized. Specify the Python version based on your needs.

Figure 1-15

Step 3 When the system prompts you to select a value, enter y.


Wait until the installation is complete.
HCIA-AI Lab Environment Setup Guide V3.0 Page 12

Figure 1-16

1.5.3 Activating a Virtual Environment


In the command prompt, enter the activate Environment name command to activate the
corresponding virtual environment. If the name in the square brackets before the command line
changes, it indicates that the system has started and entered the environment.

Figure 1-17

Then, you can run pip or conda commands to install the modules.

1.5.4 Viewing a Virtual Environment


You can use the Anaconda Navigator to view the created virtual environment.

Figure 1-18

You can also click the triangle on the right of the environment name to go to the command prompt
window of the virtual environment.
HCIA-AI Lab Environment Setup Guide V3.0 Page 13

Figure 1-19

In this case, you can install modules in the current environment without starting the virtual
environment.

1.5.5 Deleting a Virtual Environment


You can run the conda remove –n Environment name –all command and enter y to delete an
environment, as shown in the following figure:
HCIA-AI Lab Environment Setup Guide V3.0 Page 14

Figure 1-20

1.6 Switching the Kernel in Jupyter Notebook


During development, we usually need to install multiple frameworks in different environments.
Therefore, you may need to switch the Python kernel between different environments during the
development of a project. This section provides a simple method for switching the kernel.

1.6.1 Checking Jupyter Notebook


The nb_conda_kernels module and Jupyter Notebook must be installed in the same environment.
Check whether Jupyter Notebook is installed in the current environment.
Run the following command to view the installation packages in the current environment:

conda list

Figure 1-21
If jupyter is in the list, Jupyter Notebook is installed in the environment.

Figure 1-22
Note: If ipykernel is installed in other environments, jupyter_client and jupyter_core are in the list,
but not jupyter.
HCIA-AI Lab Environment Setup Guide V3.0 Page 15

1.6.2 Installing nb_conda_kernels


The nb_conda_kernels module must be installed in the same environment as Jupyter Notebook.
Generally, when Anaconda is installed, Jupyter Notebook is installed in the base environment. This
environment is the basic environment used when the command prompt window is opened without
any activate command.
Run the following command to install nb_conda_kernels in the base environment:

conda install nb_conda_kernels

Figure 1-23
Note: This module must be installed in the same environment as Jupyter Notebook. On some
computers, when the command prompt window is started, (base) is not displayed before the
address; however, when the Anaconda prompt window is started, (base) is displayed before the
address.

Figure 1-24

1.6.3 Installing ipykernel


After nb_conda_kernels is installed, run the activate command to enter the environment where you
want to add the kernel. In this example, the tfgpu environment is used.
Run the following command to enter the environment. (The italic part in red is the environment
name, which can be customized.)

activate tfgpu

Figure 1-25
Run the conda install ipykernel command to install the ipykernel module.
HCIA-AI Lab Environment Setup Guide V3.0 Page 16

Figure 1-26
After the installation is complete, you can switch to another kernel from the Notebook kernel. Then,
if you want to create a virtual environment, you only need to install the ipykernel module in the
environment to find the new kernel in Jupyter. You do not need to install nb_conda_kernels again.

Figure 1-27
HCIA-AI Lab Environment Setup Guide V3.0 Page 17

2 MacOS Lab Environment Setup

2.1 Overview

2.1.1 About This Lab


This document describes how to set up a development environment for all HCIA-AI exercises based
on the MacOS system, including downloading and installing Anaconda, selecting the Python version,
installing the dependencies, and installing Jupyter Notebook.

2.1.2 Objectives
Upon completion of this task, you will be able to set up the HCIA-AI development environment of
the CPU version based on the MacOS system.

2.1.3 Modules Required for the Exercise


Anaconda 3.7 or later
Python 3.6.5
TensorFlow 2.1.0

2.2 Downloading Anaconda and Configuring the Python


Environment
Anaconda is a distribution of the Python programming language for scientific computing. It supports
Linux, MacOS, and Windows OS and provides the package and environment management functions.
It can easily cope with coexistence and switchover of multiple Python versions and installation of
various third-party packages. Anaconda uses the conda tool or command to manage packages and
environments. In addition, Anaconda contains Python and related tools. Anaconda is a Python tool
for enterprise-level big data analysis. It contains more than 720 open-source packages related to
data science and covers data visualization, machine learning, and deep learning. It can be used not
only for data analysis, but also in the big data and AI fields.
After the Anaconda is installed, you do not need to install Python.
HCIA-AI Lab Environment Setup Guide V3.0 Page 18

2.2.1 Downloading Anaconda

Step 1 Go to the Anaconda official website at https://www.Anaconda.com/ and click Download to


download the MacOS version, as shown in the following figure:

Figure 2-1

Download the Python 3.8 installer (654 MB).

2.2.2 Installing Anaconda


Step 1 Double-click the downloaded Anaconda installation package in .pkg format to install
Anaconda.

Step 2 Click Continue and then Install.

Step 3 Enter the system password to confirm the installation.

Step 4 Wait until the installation is complete.

2.2.3 Creating a Virtual Environment

Step 1 Go to the Anaconda Navigator.


HCIA-AI Lab Environment Setup Guide V3.0 Page 19

Figure 2-2

Step 2 Click Environments in the left navigation pane, and click Create in the lower left corner to
create a Python development environment of a new version.

Figure 2-3

Step 3 Set the name as required. Select the Python version. Version 3.6 is recommended.
HCIA-AI Lab Environment Setup Guide V3.0 Page 20

Figure 2-4
Wait until the environment is successfully created.

2.2.4 Testing the Environment

Step 1 Click the triangle icon on the right of the environment name to go to the newly created
environment, and choose Open Terminal.

Figure 2-5
Step 2 Enter python to verify the Python version of the environment.
HCIA-AI Lab Environment Setup Guide V3.0 Page 21

Figure 2-6
If 3.6.8 is displayed, the installation is successful.

2.3 Installing TensorFlow

2.3.1 Installing TensorFlow 2.1.0

Step 1 Create a virtual environment. A virtual environment is created to ensure that a single
framework is available in a single environment, which facilitates development. The
relationship between a virtual environment and a framework is similar to that between a
virtual machine and a system. When you create a new virtual environment, you can install a
new framework. Run the following command to create a virtual environment:

conda create –n tf21 python==3.6.5

The italic part in red is the name of the virtual environment, which can be customized.
Note: TensorFlow 2.1.0 is not compatible with Python 3.7 and later versions. Therefore, it is
recommended that you install Python 3.6.5 in the virtual environment.

Step 2 Enter y if y/n is displayed during the installation.


Step 3 After the installation is complete, run the activate tf21 command to start the virtual
environment. The italic part in red is the name of the virtual environment created in Step 2.

Step 4 Run the pip install tensorflow-cpu==2.1.0 command to install the TensorFlow2.1.0
framework.
HCIA-AI Lab Environment Setup Guide V3.0 Page 22

Step 5 If an error in the following example is returned, the connotation package is insufficient. In this
case, manually install the corresponding package.

Figure 2-7
Step 6 Run the pip command to install the corresponding packages, and then run the pip install
tensorflow-cpu==2.1.0 command. Then, the TensorFlow is successfully installed.

2.4 Installing Jupyter Notebook


You can install Jupyter Notebook in two ways: using a terminal or using the Anaconda navigator.

2.4.1 Using a Terminal


On the terminal, run the pip install jupyter notebook command to install Jupyter Notebook, as
shown in the following figure:
HCIA-AI Lab Environment Setup Guide V3.0 Page 23

Figure 2-8
HCIA-AI Lab Environment Setup Guide V3.0 Page 24

Figure 2-9

The Jupyter Notebook is successfully installed.

2.4.2 Using Anaconda Navigator

Step 1 Go to the Anaconda home page.


Go to the Anaconda home page and click Home on the left.
HCIA-AI Lab Environment Setup Guide V3.0 Page 25

Figure 2-10

Step 2 Install Jupyter Notebook.


In Application on, choose the environment and click Install under Jupyter Notebook. After the
installation is complete, the following page is displayed:

Figure 2-11

The Install button under Jupyter Notebook changes to Launch.

Step 3 Verify the installation result.


HCIA-AI Lab Environment Setup Guide V3.0 Page 26

Click Launch under Jupyter Notebook. The Jupyter home page is displayed, as shown in the
following figure:

Figure 2-12

Step 4 Click New in the upper right corner and choose python 3 to create a Jupyter file.

Figure 2-13

Enter the following code in the text box:

for i in range(100):
if i%2 == 0:
print(i)

Click Run. The result is as shown in the following figure:


HCIA-AI Lab Environment Setup Guide V3.0 Page 27

Figure 2-14

2.5 Testing the Environment


This section describes how to verify that the Python 3.6.5 and TensorFlow development
environments created upon Anaconda can run properly.
The exercise content is to construct the constant addition operation of the TensorFlow graph
mechanism based on the Python 3.6.5, Jupyter, and TensorFlow frameworks to test whether the
HCIA-AI environment built based on Anaconda can run properly.

Step 1 Go to the Jupyter page.


Click Launch under Jupyter. The Jupyter page is displayed, as shown in the following figure:

Figure 2-15

Step 2 Create a Jupyter project.


Click New in the upper right corner and choose python 3 to create a script.
HCIA-AI Lab Environment Setup Guide V3.0 Page 28

Figure 2-16

Click Unnamed in the upper left corner and name the script as tf_demo.
Enter the following code in the text box:

##Import modules
import tensorflow as tf
import numpy as np

# Create two constant tensors


mat1 = tf.constant(np.array([[1.0, 2.0]]))
mat2 = tf.constant(np.array([[2.],[2.]]))

# Create a multiplication operator


mul = tf.matmul(mat1,mat2)

print(mul)

The result is as shown in the following figure:

Figure 2-17

Step 3 Test Keras.


The main update of TensorFlow2 is the integration of the Keras module. Therefore, the Keras
module is tested here.
HCIA-AI Lab Environment Setup Guide V3.0 Page 29

Enter the following code:

import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam',
loss=['sparse_categorical_crossentropy'],
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)

model.evaluate(x_test, y_test)

Click Run above the code to run the code. The result is as follows:

Figure 2-18

This exercise mainly verifies whether the HCIA-AI lab environment is successfully set up. If no error is
reported during code execution, the lab environment is set up successfully.
HCIA-AI Lab Environment Setup Guide V3.0 Page 30

3 Ubuntu Lab Environment Setup

3.1 Installing Miniconda


Download the 64-bit Miniconda installation package for Linux from
https://docs.conda.io/en/latest/miniconda.html. If you are located in China, the download speed at
the official website is slow. In this case, you can use the Tsinghua source. Use the installation
package with x86_64 in its name.

Figure 3-1 Miniconda (Ubuntu) installation package download page


Step 1 Find the downloaded file, right-click the file, choose Properties from the shortcut menu, and
click Permissions. Select Allow executing files as program for Execute at the bottom.

Figure 3-2 Configuring the file execution permission (1)


HCIA-AI Lab Environment Setup Guide V3.0 Page 31

Figure 3-3 Configuring the file execution permission (2)


Step 2 Right-click the blank area in the folder where the file is located and choose Open in Terminal.
If you log in as a common user, run the following command to switch to the bash mode:

bash

Figure 3-4 Open in Terminal


HCIA-AI Lab Environment Setup Guide V3.0 Page 32

Figure 3-5 Switching to the bash mode


Step 3 Run the following command to execute the installation file. Use the actual name of the
downloaded file in the command.

./Miniconda3-py38_4.8.2-Linux-x86_64.sh

Step 4 During the installation, enter yes to agree to the installation terms. The default value is no.
HCIA-AI Lab Environment Setup Guide V3.0 Page 33

Figure 3-6 Agreeing to the installation terms


Step 5 After the installation is complete, enter yes to initialize Miniconda.
HCIA-AI Lab Environment Setup Guide V3.0 Page 34

Figure 3-7 Confirming the initialization of Miniconda


Step 6 After the preceding operations are complete, the Miniconda is successfully installed. Close the
current terminal and open a new terminal to perform subsequent operations.

Figure 3-8 Miniconda installed

3.2 Creating Virtual Environments


Step 1 MindSpore and TensorFlow require a large number of dependencies. If they are installed in
the same environment, errors may occur. Therefore, you need to create different virtual
environments for different frameworks. Open the command line window and run the
following commands to create a virtual environment for MindSpore and TensorFlow CPU,
respectively. During the process, enter y for confirmation.

conda create –n MindSpore python==3.7.5


conda create –n TensorFlow-CPU python==3.6.5

Step 2 Run the following command to activate the virtual environment:

conda activate MindSpore

3.3 Changing the pip Channel


You can install Python in pip or conda mode. Because the two modes are not fully compatible with
each other, you are advised to install Python in either mode. In this exercise, the pip mode is used.
HCIA-AI Lab Environment Setup Guide V3.0 Page 35

Step 1 Open a new terminal and run the following commands in sequence to update the index and
install Vim:

sudo apt-get update


sudo apt-get install vim

Step 2 Run the following commands to create and edit the pip configuration file:

mkdir ~/.pip/
touch ~/.pip/pip.conf
vim ~/.pip/pip.conf

Step 3 Press i to enter the editing mode, copy the following content to the file. Press Esc, enter :, and
then enter wq!. Save the configuration and exit.

[global]
index-url = https://mirrors.huaweicloud.com/repository/pypi/simple
trusted-host = mirrors.huaweicloud.com
timeout = 120

3.4 Installing MindSpore


Step 1 Open a new command line window and create a virtual environment. For details, see section
1.5 "Anaconda Virtual Environments." Ensure that the Python version is 3.7.5. Run the
activate command to activate the virtual environment.

activate MindSpore

Step 2 Run the following command to install MindSpore 1.2. Alternatively, go to the official website
https://www.mindspore.cn/install to obtain the latest version.

pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.2.0/MindSpore/cpu/ubuntu_x86/mindspore-


1.2.0-cp37-cp37m-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i
https://pypi.tuna.tsinghua.edu.cn/simple

Step 3 After the installation succeeds, enter Python in the command line window to access the
development environment. Run the following command to import MindSpore. If no error is
reported, the installation is successful.
Note: Due to dependency problem of the GLIBC package, Ubuntu 16.04 does not support
MindSpore. Use Ubuntu 18 or later.

import mindspore
HCIA-AI Lab Environment Setup Guide V3.0 Page 36

3.5 Installing TensorFlow (CPU Version)


Step 1 Open a new command line window. Ensure that the Python version is 3.6.5. Run the activate
command to activate the virtual environment. (The italic part in red is the name of the
virtual environment.)

activate TensorFlow-CPU

Step 2 Run the following command to install the latest version of TensorFlow. If you need to specify a
TensorFlow version, enter another line to specify the version. For details, visit
https://tensorflow.google.cn/install.

pip install tensorflow-cpu==2.1.0

Step 3 After the installation succeeds, enter Python in the command line window to access the
development environment. Run the following command to import TensorFlow. If no error is
reported, the installation is successful.

import tensorflow

4 HUAWEI CLOUD User Guide

4.1 Overview
HUAWEI CLOUD provides abundant cloud resources and cloud services to meet developers'
requirements. This document describes how to apply for HUAWEI CLOUD resources, including
account application and real-name authentication, access key (AK) and secret access key (SK)
obtaining, and main services of HUAWEI CLOUD.
After reading this manual, you will be able to:
⚫ Understand the specific content of the AI development environment;
HCIA-AI Lab Environment Setup Guide V3.0 Page 37

⚫ Apply for an AI development environment;


⚫ Perform function tests based on the established environment.

4.2 Account Application and Real-Name Authentication

4.2.1 HUAWEI CLOUD Accounts


You can use a HUAWEI CLOUD account to:
⚫ Enable corresponding services on the HUAWEI CLOUD official website to carry out the
exercises in the course.
⚫ Experience various convenient and cost-effective cloud services provided by HUAWEI
CLOUD, including deep learning, machine learning, image recognition, speech
recognition, and natural language processing.

4.2.2 Registration

Step 1 Go to the HUAWEI CLOUD official website.


Visit the HUAWEI CLOUD official website at http://www.huaweicloud.com/, as shown in the
following figure:

Figure 4-1

Step 2 Click Register in the upper right corner of the home page.
Click Register in the upper right corner to register an account, as shown in the following figure:
HCIA-AI Lab Environment Setup Guide V3.0 Page 38

Figure 4-2

Step 3 Verify the real name.


Click Real-Name Authentication to perform real-name authentication for the account. Choose
Individual to go to the next step.

Figure 4-3

Choose Individual Bank Card Authentication to go to the next step.


HCIA-AI Lab Environment Setup Guide V3.0 Page 39

Figure 4-4

Enter the related information and click Submit.


After you pass the real-name authentication, you can proceed with other operations.

4.2.3 Application
HUAWEI CLOUD provides various cloud services. You can apply for cloud resources based on your
tasks and requirements.
Follow the application wizard of the corresponding service that you apply for.

4.3 Obtaining the AK and SK

4.3.1 Overview
An AK and SK are the identification codes required for the use of HUAWEI CLOUD services. When
you use some HUAWEI CLOUD services for the first time, you need to enter the AK and SK, as shown
in the following figure:
HCIA-AI Lab Environment Setup Guide V3.0 Page 40

Figure 4-5

In the preceding figure, enter the AK in Access Key ID and the SK in Secret Access Key. The AK and SK
are required when you use the OBS.

4.3.2 Generating the AK and SK

Step 1 Log in to HUAWEI CLOUD. On the home page, go to the account center in the upper right
corner, as shown in the following figure:

Figure 4-6

Step 2 On the Account Center page, click Manage My Credentials in the Security Credentials row.
HCIA-AI Lab Environment Setup Guide V3.0 Page 41

Figure 4-7

Step 3 In the list on the left, click Access Keys.

Figure 4-8

Step 4 On the Access Keys page, click New Access Key to create an AK. You can also edit, disable, or
delete an AK by clicking the corresponding button in the Actions column.
HCIA-AI Lab Environment Setup Guide V3.0 Page 42

Figure 4-9

Note: A table file is automatically downloaded after you create an AK. The HUAWEI CLOUD AK is
stored in the table file. Therefore, keep the file with caution.

4.4 Commonly Used HUAWEI CLOUD Products


ModelArts is a one-stop AI development platform. It provides mass data preprocessing, semi-
automated data labeling, distributed training, automated model building, and on-demand
deployment of device-edge-cloud models to help AI developers build models quickly and manage
the AI development lifecycle during machine learning and deep learning.

Figure 4-10

After accessing ModelArts, you can select multiple GPU-accelerated instances and various services
provided by ModelArts, which will be demonstrated in Chapter 8.
HCIA-AI Lab Environment Setup Guide V3.0 Page 43

Figure 4-11

Figure 4-12

You might also like