Deploying Computer Vision Models on Google Cloud Platform with Ikomia SCALE

Allan Kouidri
-
5/16/2024
Face inpainting GCP

When embarking on a computer vision project, one of the initial steps involves setting up your models and organizing them into workflows. However, a significant hurdle often arises when it's time to deploy these models efficiently.


Deploying on GPUs can be a real headache. The setup is tricky, and the documentation? Even trickier, especially if you’re dealing with platforms like Google Cloud Platform (GCP). You've got to get a grip on all kinds of GPU configurations, sort out dependencies, and if things go sideways, you’re in for some serious troubleshooting. It can really drain your time and energy.

This is where Ikomia SCALE comes into play. It offers a streamlined platform that greatly simplifies the deployment process for computer vision models, eliminating the need for extensive coding and adaptation across different devices. Whether you're considering a GPU architectures like Google Cloud Platform or other prominent provider, SCALE ensures a smoother transition.

In this blog post, we provide a detailed guide on how to leverage the Ikomia ecosystem to your advantage:

  1. Workflow creation: We begin by demonstrating how to utilize the Ikomia API to construct a workflow, setting the stage for deploying your computer vision model.
  2. Deployment: We then take you through the steps of deploying your model using the Gloud Cloud Platform as an example. These steps remain consistent across various platforms such as AWS or Scaleway, and regardless of the infrastructure, whether it's CPU or GPU.
  3. Accessing your REST API Endpoint: Lastly, we explain how to access your REST API endpoint. This endpoint facilitates a seamless connection between your applications and the deployed model, ensuring efficient communication through standard HTTP methods.

For an in-depth look at what Ikomia SCALE has to offer, feel free to visit the official page [1]. Let's get started and simplify the process of deploying Computer Vision models!

Step 1: Creating your workflow: Face inpainting

I'm working on developing a face inpainting algorithm tailored for small clothing companies on a tight budget or for my personal projects, like selling clothes on Vinted (this isn't a sponsored ad! 😄).

Below, I'll detail how I used the Ikomia Ecosystem to streamline the process from creating a workflow to deploying the solution.

Use Case

My algorithm incorporates two models from Hugging Face:

  • Face segmentation: Using ‘matei-dorian/segformer-b5-finetuned-human-parsing’ to segment various parts of the human body, specifically isolating the face and hairs.
  • Face replacement (inpainting): Employing ‘SG161222/RealVisXL_V4.0’, known for generating realistic face portraits.

Setup

Start by installing the Ikomia Command Line Interface (CLI) in a virtual environment [2]:


pip install "ikomia-cli[full]"

The Ikomia CLI allows for seamless interaction with Ikomia SCALE via command line, simplifying project management.

Create, test and export your workflow

This JSON file will outline the structure of the workflow, including input and output types, along with the parameters used.


from ikomia.dataprocess.workflow import Workflow
from ikomia.utils.displayIO import display


# Init your workflow
wf = Workflow()

# Add algorithm
algo = wf.add_task(name="infer_face_inpainting", auto_connect=True)

algo.set_parameters({
        "model_name_seg":"matei-dorian/segformer-b5-finetuned-human-parsing",
        "dilatation_percent_face":"0.0",
        "dilatation_percent_hair":"0.03",
        "crop_percent_bottom_face":"0.22",
        "mask_only":"False",
        "model_name_diff": "SG161222/RealVisXL_V4.0",
        "prompt":"high quality, portrait photo, blond hair, detailed face, skin pores, no makeup",
        "negative_prompt":"(face asymmetry, eyes asymmetry, deformed eyes, open mouth)",
        "guidance_scale":"7.5",
        "num_inference_steps":"50",
        "strength":"0.75",
        "seed":"-1",
})

# Run on your image  
wf.run_on(url="https://images.pexels.com/photos/774909/pexels-photo-774909.jpeg?cs=srgb&dl=pexels-andrea-piacquadio-774909.jpg&fm=jpg&w=640&h=960")

# Inpect your result
display(algo.get_image_with_mask()) # Semantic segmentation mask
display(algo.get_output(2).get_image()) # Face and hair mask
display(algo.get_output(3).get_image()) # Inpainted image


# Save the workflow as a JSON file in your current folder
wf.save("./face_inpainting_workflow.json")

Face inpainting step outputs
Original image source [3]

We obtain various outputs at different stages of the inpainting algorithm. Initially, we generate a semantic segmentation mask using the Segformer model. We then refine this mask to isolate only the face and hair. This mask is further fine-tuned by cropping around the neck and using dilation to smooth any imprecisions along the mask's edges.

For detailed information on the adjustable parameters that help select the models and optimize the segmentation masks, be sure to visit the HUB model card.

Below are additional results obtained by tweaking the input prompt.

Face inpainting outputs

Step 2: Push your workflow

Before deploying, we need to push our workflow on the SCALE.

Pre-requisites

Begin by either creating an Ikomia account or logging in. You can sign up using your email, Google, or GitHub account.

Create a Project

In Ikomia SCALE, a project acts as a central hub for your workflows, helping you organize them effectively. To create a new project, simply follow these steps:

     1. Go to the dashboard and click on the "New Project" button.

     2. You'll need to fill out a form with the following information:

  • Workspace: Choose where to store your project. If it’s for your eyes only, select your personal workspace.
  • Project Name: Give your project a descriptive name that reflects its purpose.
Ikomia SCALE create new project

Generate your access tokens

Option 1: Token generation using Ikomia CLI

To authenticate with Ikomia SCALE, you need to generate an access token. Use the command below, replacing < your_login > and < your_password > with your Ikomia SCALE credentials.


ikcli login --token-ttl “< token_duration_in_seconds >” --username "< your_login >" --password "< your_password >"

Option 2: Token Generation via the SCALE platform

1. Access token management: On the top right corner, find the section for API token management which is located under settings or the account section.

2. Create new token: Click on the option to create a new token. Fill in the required details such as the name of the token and its expiration date.

3. Generate and save the token

4. Copy the token: We are are ready to set the token as an environment variable.

You can then set this token as an environment variable by entering:

  • On Windows (or notebooks)

%env IKOMIA_TOKEN= < your_token >

  • On Linux

export IKOMIA_TOKEN= < your_token >

This ensures that your token is securely stored and readily accessible for your sessions with Ikomia SCALE.

Push the workflow to SCALE

Once you've set your access token, you're ready to upload your workflow to the Ikomia SCALE platform. Use the following command to push your workflow:


ikcli project push < project_name > face_inpainting_workflow.json

Make sure to replace < project_name > with the actual name of your project on Ikomia SCALE, like ‘Face_inpainting’ for example. This command will upload your workflow JSON file directly to the designated project in SCALE, making it available for management and deployment as required.

Step 3: Deploy you workflow

Now that your workflow is integrated into your project on Ikomia SCALE, the next step is to deploy it and establish a live endpoint for practical use.

  1. Navigate to Your Project: Access your project page on Ikomia SCALE. This page will give you an overview of all the workflows that are part of your project.
  2. Deploy Your Workflow: From the list, select the workflow you want to deploy. Ikomia SCALE offers the flexibility to choose from various cloud providers and regions, allowing you to deploy your workflow in an environment that best suits your needs.
Project interface Ikomia SCALE

Ikomia SCALE provides three main types of compute infrastructures for deploying your workflows, each designed to meet different computational needs and budget considerations:

  • Serverless: This CPU-only environment is cost-effective as you are billed only for the execution time of your workflow. It's ideal for workloads that have irregular usage patterns. For this specific use case, the serverless option is the best fit.
  • CPU Instances (Coming Soon): Opt for dedicated CPU-only instances where you are billed based on the actual usage time, calculated to the second. This option will soon be available for those needing consistent CPU resources.
  • GPU Instances (Coming Soon): For more demanding computational tasks, like our current use case, it is best to choose dedicated instances with GPU acceleration, also billed per second.

Example: GCP provider deployment Ikomia SCALE

Here’s how to deploy your workflow on Ikomia SCALE:

    1. Create a Deployment: On the right-hand side of the project interface, you'll find the deployment settings where you can configure and initiate the deployment of your selected workflow.

    2. Select the Provider: Choose your preferred cloud provider, like AWS, Google Cloud, or Scaleway, based on their capabilities and your requirements.

    3. Choose Deployment Type: Select the type of deployment that fits your needs—serverless for flexible billing on CPU-only environments, CPU instance for dedicated CPU power, or GPU instance for intensive compute tasks.

    4. Pick a Region: Choose a geographical region that aligns with your latency needs and data residency requirements. This helps optimize the performance of your application by reducing delay and complying with local data laws.

    5. Determine the Size: Based on your computational and memory needs, select the appropriate size for your deployment, ranging from XS (Nvidia L4) to XL (Nvidia A100).

    6. Launch Your Deployment: Click the 'Add deployment' button to start the deployment process of your workflow.

Once initiated, the new deployment will appear on the left-hand side of the page under the deployments section. The time it takes for your deployment to become operational can vary, depending on the complexity of the workflow and the specifics of your chosen configuration.

A running GCP deployment Ikomia SCALE

Step 4: Test your deployment 

SCALE offers a convenient Test Interface to verify that your deployed workflow is functioning as expected.

Accessing the Test interface: To access the Test Interface, navigate to the page of your deployed workflow and click on the ‘Test me’ button associated with your deployment. You can also access the Test Interface by directly visiting the endpoint’s URL.

Executing your workflow: Here’s how to test your workflow:

  1. Upload an image: You have the option to upload an image file directly from your computer. This allows you to see how your workflow processes your specific images.
  2. Choose a sample image: SCALE provides a variety of sample images for testing. These are useful for quickly checking how your workflow handles different types of content without having to upload your own.

Once you've run the workflow, the Test Interface will display the results, allowing you to evaluate the performance and output of your workflow directly.

Illustration of the Ikomia SCALE test interface, face inpainting

Step 5: Integrating a deployment

After successfully deploying your workflow on Ikomia SCALE, you'll receive a REST API endpoint for each deployment. This endpoint is crucial for integrating your computer vision model into your existing applications or systems. It allows your applications to send images to the model and retrieve the processed results seamlessly.

For comprehensive guidance on how to utilize these REST API endpoints effectively, check out our detailed documentation. It provides step-by-step instructions on integration techniques and best practices to ensure smooth and efficient incorporation of your model into your workflow. You can find this valuable resource here. This will help you maximize the functionality and impact of your deployment.

References

[1] Ikomia SCALE

[2] How to create a virtual environment in Python

[3] Andrea Piacquadio - Woman In Collared Shirt - pexels.com/photo/woman-in-collared-shirt-774909/

Arrow
Arrow
No items found.
#API

Build with Python API

#STUDIO

Create with STUDIO app

#SCALE

Deploy with SCALE