• Shubhang Yadav

Deploying Machine Learning Models on Google Cloud Platform as serverless functions

Updated: Jul 22

Deployment of a model always sparks joy for the developer. Services such as Google Cloud Platform, AWS, and Microsoft Azure enable a developer to share his or her work with the world without caring about the server aspect of deployment.

In recent years, cloud services have come to the forefront and are being utilized by large organizations and individual developers alike due to their sheer versatility.

In this article, we shall explore one such service, i.e., Google Cloud Platform, and how it has made model deployment a fun task instead of a strenuous one.


What is Google Cloud Platform (GCP)?

Google Cloud Platform is a set-up of open distributed computing administrations offered by Google. It is a suite of cloud computing services that run on the very foundation that Google utilizes internally for its end-user products, such as Google Search, Gmail, Google Photos, and YouTube. The stage incorporates Computing, Networking, Storage, Big Data, Machine Learning, and Management services. Google Cloud Platform administrations can be accessed by programming engineers, cloud directors, and other venture IT experts over the open web or through a committed system association.


Introduction to Serverless Architecture

Serverless architecture (also known as serverless computing) is a software configuration pattern where applications are hosted by a third-party service, dropping the requirement for server software and device supervision by the developer. Applications are divided into individual functions that can be invoked and scaled separately.

With a serverless architecture, the focus is thoroughly on the individual functions in the application code. Services such as Google Cloud Functions, AWS Lambda, and Microsoft Azure Functions handle all the physical hardware, virtual machine OS, and web server software management. One may only be concerned with the code.

Some of the advantages of serverless architecture are-

  1. Server management is not required.

  2. Developers are solely charged for the server space they use, therefore decreasing expenses.

  3. Serverless architectures are naturally scalable.

  4. Swift deployments and updates are feasible.

  5. The code runs near the end-user, thus minimizing latency.


Steps for deploying a model as a Google Cloud Function


Step 1- Training the model on your local machine

The deployment of a machine learning model to production commences with developing the model, which may be accomplished in numerous ways. Whenever model development is mentioned, it entails an iterative method where hypotheses are examined. The models are derived, trained, tested, and built until a model with desired outcomes is obtained.

The most cost-effective way is to build and train the model locally so that it is ready for deployment and saved to a storage service (in this case, Google Cloud Storage).


Project System Architecture



Step 2- Creating a new Google Cloud Project

Google Cloud Platform provides 300$ worth of credit for a year for users, which can be redeemed upon activation of account after logging into the GCP Console using a valid Gmail ID.

GCP enables users to create a new project with a suitable title and asks if it is being done as part of an organization.


Creating a new Google Cloud Project



Step 3- Storing the pre-trained model in a Google Cloud Storage bucket

Google Cloud Platform provides a storage service (similar to AWS' S3) in which a bucket can be created to store the trained machine learning model.

The bucket has to be named as per the rules defined by GCP, and the user can select the region where the data needs to be stored to guarantee faster access. The user may also specify a storage class for the bucket according to the duration for which the information needs to be stored.


Creating a storage bucket to upload the pre-trained model



Step 4- Writing the Google Cloud Function for deployment

Google cloud functions allow the user to name the function, allocate memory, and add a trigger (HTTP for deployment purposes, along with selecting the option to enable unauthenticated invocations).

The function can be written in one of the nine of GCP'S supported languages (Node.js, Python, etc.).


Creating a Google Cloud Function


One of the key advantages of deploying a model using a Google cloud function is that it allows the user to list the external libraries required for the function to execute as part of 'requirements .txt' and downloads the same, thus saving the user's efforts and time both.


Note: An alternative to Google Cloud Functions is Amazon Web Services’ Lambda Function but in comparison, demands a more extensive approach as the external libraries (Sklearn, Pandas, etc.) have to be downloaded locally and uploaded as layers for the function while GCP simply asks the users to list down all the dependencies and takes care of the rest.


Writing the function in preferred language & listing the external libraries required


After writing the function, the user can deploy it to check for errors. Once no errors are found, the function URL can be tested using Postman or similar applications; the input has to be a valid JSON file for the function to execute.


Testing the function using Postman



Conclusion

Google Cloud Functions are a great way of deploying light Machine Learning models and the serverless architecture helps reduce hassles for developers and organisations both. They provide cloud infrastructure for hosting web-based applications, serverless, served on a plate and thus create many opportunities and remove even more obstacles for someone whose interests align with model deployment and cloud computing.


__________________________________________________________________________


If you're eager to know more about our Machine Learning products, take a deep dive into our Real-time Mask Detector model.


If you are a startup and willing to build an app like Uber, please read out our blog on Building apps like Uber for your business.


If you are an Idea owner and willing to build a software product, feel free to read our customer success story here - How we went from an Idea to Prototype to Product?


Do you want to hire our team of experts to develop an Artificial Intelligence backed Uber-like app or an enterprise grade web application? We have the best app development team and data scientists in India, and are experts in Amazon Web Services, Microsoft Azure, Google Cloud Platform and other modern tech stacks and frameworks.


We are happy to share with our readers that we are already a product development partner for global startups. Please feel free to read our customer reviews here. Plus we are headquartered in the silicon valley of India -- Bangalore! Feel free to shoot an email to us at info@cloudtara.com










165 views

Recent Posts

See All