Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build a serverless picture classification system by Serverless

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to build a serverless image classification system based on Serverless. The content is concise and easy to understand, and it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Foreword

Here is a new design pattern: event-based real-time data processing. In order to describe it more vividly, we take picture classification as an example, first introduce how to build a Web application of picture classification through APIG trigger, and then introduce how to construct a real-time picture classification system through OBS trigger.

Serverless advantage

Compared with the traditional architecture, the serverless architecture has the following advantages:

1. There is no need to pay attention to any server, just focus on the core business logic to improve the efficiency of development and operation and maintenance.

two。 Event triggering, flexible expansion

3. The operation of the function is flexible and flexible with the volume of business, and it is paid on demand and billed only after execution. For scenarios where the load peak and trough are very obvious, the cost can be reduced a lot.

4. Through simple configuration, you can connect function workflows and other cloud services, even cloud services and cloud services.

Building a serverless Web application for picture classification

As described in previous articles, serverless is very good at building a Web application, such as the image below, which classifies and tags the images uploaded by users.

We can quickly build this system through functional workflow services, and do not pay attention to the server at all, and run flexibly and charge on demand.

Create a function and call the image tag API of Huawei Cloud Image Analysis Service in the function to label and classify the images. Then configure an APIG trigger for this function, so that you can provide an API of image classification, and finally deploy the front-end page to OBS and host it as a static website, thus building a complete image classification serverless Web application. When the page calls API, it automatically triggers the function execution, and the function written by the developer only needs to implement the logic of how to deal with the image after receiving the image, and finally returns the result to the page.

Next, we will show how to build this serverless Web application in its entirety.

1. Preparatory work

Enter Huawei cloud image detection service and apply to activate the image tag feature of the image detection service. After successful application, you can call the image tag API.

two。 Build a back-end program

Enter the function workflow service, select the template "Picture tagged Web backend", and create the function. After the function is created, configure the delegate with IAM access, because the user's ak and sk in the code of this function need to have the permission to access IAM.

After the creation is successful, the URL of API can be seen in the "trigger" column of the function details page.

At this point, we have successfully built a serverless image classification API.

3. Build a front-end page

In order to build the front-end page more easily, we provide the corresponding function template to quickly build the front-end page. Select the template "Image tagged Web Front end" to create a function in which the API URL created in the previous step is set in the custom data REST_API. After the creation is completed, the URL in the "trigger" column of the function details page is the browser access address of the page.

So far, we have successfully built a serverless image classification Web application. Next, we will introduce another scenario.

Build a real-time picture classification system triggered by events

Next, this article will introduce the real-time data processing scenarios triggered by events. Consider the following scenario in which users upload images to an OBS bucket, automatically perform image classification, and dump them to different directories of another bucket according to category. For example, in the following example, upload an image of a penguin to a bucket, and the image will be automatically dumped to the penguins, seabird, and bird directories of another bucket.

We can quickly build this system through functional workflow services, and do not pay attention to the server at all, and run flexibly and charge on demand.

Create a function and call the image tag API of Huawei Cloud Image Analysis Service in the function to label and classify the images. Then configure an OBS trigger for the function to monitor the POST event of the bucket. When a file is uploaded to the bucket, the function execution will be triggered automatically, thus realizing a serverless system based on event trigger. When the user uploads a picture to the bucket, it automatically triggers the function execution, while the function written by the developer only needs to implement the logic of downloading the image from the bucket and sorting the dump.

Next, we will show how to completely build the image classification system triggered by this event.

Preparatory work

1. Apply to activate the image recognition service "image label" function

two。 Enter the object Storage Service (OBS) service, create two buckets, one for receiving classified images (source) and one for storing classified images (result), and set the bucket policy to public read and write.

Create function

1. Go to the function workflow service creation function page and select the "picture real-time classification (by picture type)" function template, which has provided you with the code for this case.

two。 Set the environment variable result_bucket to the name of the bucket where the classified images are stored (result)

3. Configure the OBS trigger, the bucket selects the bucket to accept the image to be classified (source), and the event selects post. Function execution is triggered when a new picture is uploaded to the bucket.

4. Click create to create functions and triggers.

Configuration function

1. Go to the function details page, enter the "configuration" tab, and set a delegate to the function with access to IAM and OBS, so that the function can obtain the user's AK, SK, and access OBS bucket resources.

two。 Save configuration

Test function

1. Upload a picture to the bucket (source) that receives the picture to be classified

two。 Look at the files in the result where the classification results are stored, and you will find that the pictures are stored in the directory of the corresponding category.

The above is how Serverless builds a serverless image classification system. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report