Professional Documents
Culture Documents
HCNA-AI
Image Recognition Programming
Experiment Guide
Version: 1.0
1
Copyright © Huawei Technologies Co., Ltd. 2018. All rights reserved.
No part of this document may be reproduced or transmitted in any form or by any means without prior written consent
of Huawei Technologies Co., Ltd.
and other Huawei trademarks are trademarks of Huawei Technologies Co., Ltd.
All other trademarks and trade names mentioned in this document are the property of their respective holders.
Notice
The purchased products, services and features are stipulated by the contract made between Huawei and the customer.
All or part of the products, services and features described in this document may not be within the purchase scope or
the usage scope. Unless otherwise specified in the contract, all statements, information, and recommendations in this
document are provided "AS IS" without warranties, guarantees or representations of any kind, either express or implied.
The information in this document is subject to change without notice. Every effort has been made in the preparation of
this document to ensure accuracy of the contents, but all statements, information, and recommendations in this
document do not constitute a warranty of any kind, express or implied.
Website: http://huawei.com
Brief Introduction
This document is an HCNA-AI certification training course. It is intended for trainees who are
preparing for HCNA-AI tests or readers who want to know about AI basics. After
understanding this document, you will be able to perform basic AI image recognition
programming.
Contents
This document contains one experiment (TensorFlow image recognition) to help trainees or
readers get started and build the basic AI programming capability.
The experiment includes image data preparation, library and module installation, and finally
image recognition realization.
Contents
1.3 CNN
1.3.1 Structure
The CNN, one of the mainstream deep learning and neural network algorithms, is mainly used
for image recognition. The following figure shows the CNN structure.
1.3.2 Overview
The CNN is an in-depth Forward Feedback Artificial Neural Network (FFANN), which has
been successfully applied in the field of image recognition. The network structure mainly
includes the input layer, convolutional layer, pooling layer, full connection layer, and output
layer.
Generally, the basic structure of the CNN includes two layers. The first layer is the feature
extraction layer: The input of each neuron is connected to the local acceptance field of the
previous layer, and the features of the local acceptance field are extracted. Once a local
feature is extracted, the location relationship between it and other features is determined. The
second layer is the feature mapping layer. Each computing layer of the network consists of
multiple feature mappings. Each feature mapping is a plane and the weights of all neurons on
the plane are the same. The feature mapping structure uses the sigmoid function that has the
smallest influence function kernel as the activation function of the convolutional network, so
that the feature mapping has the rotation invariance.
1.4 Experiment
1.4.1 Content
This experiment focuses on image recognition. Based on TensorFlow depth learning
framework and CNN, it aims to identify flower types using an open-source data set.
1.4.2 Step
The main steps of the experiment are as follows:
1. Importing frameworks
2. Preparing paths
3. Processing images
4. Defining placeholders
5. Defining the network structure
6. Defining the loss function and optimizer.
7. Model training and prediction
8. Model prediction
1.5 Summary
This chapter mainly introduces the environment and data set of the image recognition
experiment, briefly explains the CNN, and addresses the preparations based on the
TensorFlow framework.
----End
Run mkdir HCNA-AI and ll to create a file folder. Check the result.
----End
The preceding jpg files are the sample pictures in the flower_photos data set.
----End
2.3 Summary
This chapter describes how to obtain the experiment data, download the experiment data, and
view related data sets to facilitate subsequent data operations.
----End
----End
----End
----End
Calculate the sparse cross entropy between the prediction tag logits and original tag y_.
----End
Step 3 Define the model operation on the training set and verification set, and print the results.
Train a total of five epoches. Each epoch needs to run on the training set and verification set.
Print the corresponding loss value and accuracy of two data sets as well as the duration of
each epoch operation.
----End
----End
3.4 Summary
This chapter describes how to construct a CNN, define the model, set related parameters, and
test sample data based on the TensorFlow.
In the file directory, flower_photos is the data set and image.py is the image recognition
script.
Step 2 Open vim and create the Python script.
vim image_recog.py
cat image.py
----End
4.2 Summary
This chapter describes how to recognize images based on data sets and test the model effect.
As shown in the figure, the accuracy is high.