1. Introduction In recent years, artificial intelligence (AI) technology has been developing continuously. From intelligent news recommendations to song recognition, to the widely used face recognition technology, AI can be seen everywhere. It has to be said that AI has gradually penetrated into people's daily lives and become an indispensable part. So, how to realize an AI function from "zero"? Let UCloud help you.
UCloud has launched the AI as a Service platform. Based on UCloud's rich computing resources and distributed system practical experience, the platform is committed to providing cheap, highly reliable, highly elastic, and easy-to-use AI online services, freeing customers from the complicated platform system development and operation and maintenance work. Taking online facial expression recognition as an example, it explains how to use UAI-Service and open source algorithms to easily implement online services and get started with AI from "zero foundation". In addition, the performance of AI online services is evaluated and compared with GPU performance, so that users can more intuitively understand the performance advantages of AI online services. 2. Implementation steps The entire implementation process mainly consists of two parts. First, use tensorflow1.1.0 to train the required model files, and then deploy the online service according to the instructions for using UAI-SERVICE. The specific steps are as follows: 1. Model training (1) Install TensorFlow 1.1.0 The installation environment is ubuntu14.04.5, the python version is 2.7.6, and tensorflow is installed directly with pip. The instructions are as follows:
(2) Choose a suitable database UCloud chose to use the largest public database for facial expression recognition, fer2013, which contains 35,887 face images, including 28,709 training sets, 3,589 validation sets, and 3,589 test sets. The samples in the database have relatively large differences in age, facial orientation, etc., which has certain practical significance and makes expression recognition more challenging. At the same time, all the images in the database are grayscale images with a size of 48*48 pixels. The samples are divided into seven categories: angry, disgusted, fearful, happy, neutral, sad, and surprised. The distribution of various types is basically even. (The database is actually data provided by a Kaggle competition project. The official file format is csv, which was manually converted into image format.) (3) Data preprocessing The TF-Slim experimental library provided by tensorflow is actually used. For details, please refer to the official documentation of TF_Slim. TF-Slim is a new lightweight API for tensorflow to define, train, and evaluate complex models. It provides a collection of widely used convolutional neural network image classification model codes and pre-trained models, as well as running scripts. With it, you can quickly get started, either training models from scratch or fine-tuning already trained network weights. TF-Slim provides code for converting datasets into tfrecord format. After adjusting the code, the fer2013 dataset used can be converted into tfrecord format. The data format is as follows, where labels.txt contains the category mapping: (4) Training This training uses a larger model, inception_v3, to fine-tune the official pre-trained model. Since the purpose of training the model is only to try out online services, the training process does not involve much parameter adjustment. The following are examples of calling instructions:
When fine-tuning the model, the system automatically retains the last five generated models. If an interruption occurs, fine-tuning will continue based on the last model. The training model files are as follows: 2. Deploy online services Once the model is trained, it’s ready to be deployed! According to the official document (AI Online Service UAI-Service), the main steps of online deployment are as follows (due to personal preference, I chose to use command line deployment this time. The official also provides instructions for using Console deployment). (1) Install UCloud UFile SDK and UAI SDK
(2) Write inference code based on the code framework in the SDK toolkit The code is as follows:
(3) Package and upload the required models and code files File directory structure:
Package upload files:
(4) Establishment of agency services Create a service:
After creating the service, the following is returned: (5) Deployment service Deployment service:
After successful deployment, the following is returned: You can see that the URL of the service has been returned, but notice that the status is "ToStart". After starting, you can use the URL to access the service. (6) Start the service Start the service:
After successful startup, the following is returned: 3. Testing After completing the above steps, it indicates that the facial expression recognition online service has been deployed successfully, and online facial expression recognition can be realized! 1. URL Testing The URL can be accessed through the cloud host, as follows: The above results show that the URL given after deploying the online service through UAI is valid and can be used to perform sentiment classification on the input images. The figure divides the input image "happy.jpg" into category "4", which corresponds to the "neutral" class, indicating that the recognition rate of the model needs to be improved. 2. Online service performance testing The performance of the service was evaluated with the help of ab test, and compared with local test and GPU (K80). (The local test method is introduced on the official website. If you are interested, you can click TensorFlow local code test method) The test results are as follows, and we can see that:
Artificial intelligence (AI) will be an important part of UCloud's "CBA" strategy. Using the AI as a Service platform launched by UCloud can help artificial intelligence companies quickly commercialize artificial intelligence algorithms, while also providing all-round guarantees in resource management and resource scheduling. [This article is an original article by 51CTO columnist "Big U's Technology Classroom". For reprinting, please contact the author through the WeChat public account (ucloud2012)] Click here to read more articles by this author |
<<: How to re-flash iOS 11 and downgrade to iOS 10: without losing data
For the person in charge of bidding SEM, the most...
Animal shows are bad. There have been several new...
As we all know, excellent cases are of great sign...
There is such a horrifying scene in the Chinese s...
The site group strategy of SEM strategy is differ...
According to @Beijing Fengtai Fire Department, at...
Review expert: Jiang Tao, Vice Chairman of the Sc...
In recent years, online education has become a ho...
During the Spring Festival, I finished reading Hu...
The third day of the third lunar month every year...
When spring comes and flowers bloom, it is finall...
As soon as I arrived at the company in the mornin...
Recently, with the spread of the epidemic and the...
As of now, the number of mini programs has reache...
I wanted to buy something for my home, but found ...