Generate Custom Product Marketing Images using Vertex AI on Google Cloud Platform

Powerful solution giving you the ability to seamlessly generate custom product images that are designed to convert.

Bhushan Garware
Google Cloud - Community
6 min readJan 15, 2024

--

In the age of personalized recommendations, custom product marketing images are no longer a luxury — they are a necessity. Generic, one-size-fits-all imagery is unlikely to cut through the visual noise and resonate with today’s discerning consumers. To personalize the shopping experience, and capture customer attention, businesses must tailor their product visuals directly to individual interests and preferences. This is where Vertex AI on Google Cloud Platform offers a powerful solution, giving you the ability to seamlessly generate custom product images that are designed to convert.

In this blog we will cover following -

  • What is Subject Fine-tuning
  • Steps for Subject Fine-tuning on Vertex AI
  • Consuming Fine-tuned model using APIs

1. Subject Fine-tuning

Subject fine-tuning empowers you to create highly customized images by using “few-shot learning.” This feature lets you inject your own unique subjects — like your brand imagery, products, designs, or artwork — right into the training data. By providing just a few examples, you can fine-tune the image generation process to produce visuals that perfectly align with your brand’s identity and aesthetic, making them more compelling and effective in capturing attention.

At this moment, Vertex AI supports two types of Subject fine-tuning processes

  1. Standard Tuning (Generally Available) : Recommended for less common products or logos. You can use up to 8 training images (max size of 10MB) and it may take around 2 hours to complete the tuning process.
  2. Instant tuning (Preview feature) : Recommended for general subjects like pets, cars etc. Training time is usually very short i.e. approx. 5 to 7 mins but you can’t use more than 3 training images.

2. Steps for Subject Fine-tuning on Vertex AI

Before we start actual subject tuning process, make sure you complete the following configurations of your GCP project for running Vertex AI pipelines -

  1. Create Google Cloud Project
  2. Configure your Service Account
  3. Create Cloud Storage bucket to save output artifacts

2.1 Identify the training images

Let’s get ready to kick your handbag marketing up a notch with some AI-generated magic! But wait — before you dive in, you’ve got to get your “ducks” (or should we say, “handbags”!) in a row. We’re talking about product images. High-quality, focused-on-the-product, less-clutter kind of images. Why? Well, your AI image generator is like a fashion student — you want to feed it the best, most inspiring visuals. So, gather those stunning handbag images (under 10MB each, please) that put the spotlight squarely on the star of the show: your handbag. No distractions, just pure handbag perfection as shown in Fig 1. below.

Fig 1. Sample training Images for subject tuning

Image Credits : MoMu — Fashion Museum Antwerp

2.2 Training via UI on Vertex Studio

Let’s start by clicking the ‘Vision’ tab under Vertex AI studio. Then click on ‘SELECT SUBJECT’ under the subject tab from the right hand side panel. Then click on ‘+SELECT SUBJECT’. It opens up the page for fine tuning, then follow the steps given below -

  1. Select the Type as Subject
  2. Write a Display Name, it is a unique identifier for your product model. For example, ‘woman_handbag_001’
  3. Write a Class Name, it is a name that you would use in your prompt while generating images. Make sure the name is unique and not generic. For example, ‘mybrownhandbag
  4. Select Reference Images as ‘upload from local computer’

Click on the SELECT button to upload the the training images and write their detailed descriptions as shown in the Fig.2 below

Fig 2. Uploading training images from local computer

5. Select training speed as Standard or Instant as per your need

6. Choose the training & serving location as per your requirements e.g. us-central1(Iowa)

7. Provide the path of the cloud storage bucket where training and serving images would be saved. Note that the bucket must be in the same region as mentioned in the training and serving e.g. us-central1(Iowa)

8. Keep rest with default settings and click on ‘FINE-TUNE MODEL’ it will start the Vertex AI training pipeline.

9. Now go back to the Vision tab on the home page of Vertex AI studio, then click on the SELECT SUBJECT tab on the right side panel and find Manage Models, choose region in the drop down to see the status of your model tuning process.

10. If you have chosen an Instant Tuning then the pipeline would look like as shown in the Fig 3. In may case, Instant Tuning took 7mins 4 Sec to complete while Standard tuning
took 1 hrs 27 mins to finish.

Fig.3 Fine-tunig using Vertex AI pipeline

2.3 Testing via Vertex Studio User Interface

It’s time to test our fine tuned-models. Click on the Vision tab on Vertex AI studio then click on the Select Subject tab on the right panel. You would see the list of the models available. Select the one you have fine-tuned and copy the class name, in my case it’s “mybrownhandbag”. Make sure you have chosen the Generate tab and Model option under setting is chosen as ‘imagegen’ and not imagegen2. Write a prompt something like this — “4K photo of [mybrownhandbag] kept on wooden table during Sunset clicked by professional photographer” replace your class name inside the [ ]. Put some conditions in the negative prompt that you don’t want to see like ‘blur’. Fig.4 shows the outcome of the above prompt. Experiment with different prompts and observe the outcomes.

Fig 4. Outcome of standard subject fine-tuning

3. Consuming Tuned Models using APIs

Vertex AI studio UI helps for quick prototyping. Let’s now understand how to use Vertex AI APIs to consume the fine-tuned model into an application. Create Vertex AI managed notebook instance and follow below steps-

  1. Open a new notebook start with imports
import vertexai
import json
import subprocess
import requests
import base64
from io import BytesIO
from PIL import Image
from IPython.display import display

2. From Vertex AI studio, click on Online Prediction and copy your Endpoint ID

LOCATION = "your-project-location" #e.g: 'us-central1'
PROJECT_ID="your-prject-name"
ENDPOINT_ID="your-endpoint-id"

vertexai.init(project=PROJECT_ID, location=LOCATION)
url =f'https://{LOCATION}-aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/{LOCATION}/endpoints/{ENDPOINT_ID}:predict'

3. Write a function to send a request to the endpoint

# Function to Generate Images from the Input Prompt
def image_generation(prompt,negative_prompt):
finetuned_model_payload = {
"instances": [{"prompt": prompt}],
"parameters": {"sampleCount":4,"negativePrompt": negative_prompt}
}
json_finetuned_model_payload = json.dumps(finetuned_model_payload)
token = subprocess.run("gcloud auth print-access-token", shell=True, capture_output=True, text=True).stdout.strip()
headers = { "Authorization": "Bearer " + token,"Content-Type": "application/json; charset=utf-8"}
r_generated_images = requests.post(url, data=json_finetuned_model_payload, headers=headers)
predict_list = r_generated_images.json()['predictions']
c=0
for image in predict_list:
imgdata = base64.b64decode(image['bytesBase64Encoded'])
display(Image.open(BytesIO(imgdata)))
c=c+1

4. Generating the images using the class name in square brackets [ ]

prompt='4K photo of [mybrownhandbag] kept on wooden table during Sunset clicked by professional photographer'
negative_prompt='blur'
image_generation(prompt, negative_prompt)

As a next step, you can up-scale the images that you like, add your logo, attach a catchy tag line to it and start your marketing campaign. Looking forward to see what you have generated.

--

--