π Try it in Colab: Google Colab Notebook π Source Code: image_generation.py
Generate professional, studio-quality product images using Google Vertex AI Imagen 3 β entirely from text prompts. Whether you're building an e-commerce store, a marketing campaign, or a product catalog, this tool lets you produce high-resolution AI-powered visuals at scale.
You can generate images of any product (sneakers, jewelry, clothing, electronics, and more), showcasing them from multiple angles while highlighting key details like materials, textures, branding, and lighting.
| Feature | Details |
|---|---|
| πΌοΈ High Resolution | 1024Γ1024 studio-quality output |
| π Multi-angle Generation | Show products from different views |
| βοΈ Colab Integration | Cloud-based, no local GPU needed |
| π« Watermark-Free | Commercial-ready images |
| ποΈ Advanced Controls | Guidance scale, temperature, negative prompts |
| π‘οΈ Safety Filters | Configurable content safety settings |
Run the notebook instantly in Google Colab β no setup required:
Or clone and run locally (see Installation below).
Before you begin, make sure you have:
- A Google Cloud account with billing enabled
- Vertex AI API enabled
- IAM role:
Vertex AI User - Python 3.8+
git clone https://github.com/RobinaMirbahar/vertex-ai-imagen3.git
cd vertex-ai-imagen3-colab
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # Linux / macOS
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txtfrom google.colab import auth
auth.authenticate_user()
import vertexai
vertexai.init(project="YOUR-PROJECT-ID", location="us-central1")export GOOGLE_APPLICATION_CREDENTIALS="path/to/service-account-key.json"from vertexai.preview import vision_models
from IPython.display import display
# Initialize the model
generator = vision_models.ImageGenerationModel.from_pretrained("imagegeneration-002")
# Generate product images
response = generator.generate_images(
prompt="Professional studio photo of luxury sneakers, 360 view, 4K resolution",
number_of_images=4,
aspect_ratio="1:1",
guidance_scale=15,
seed=1234
)
# Display results
for idx, image in enumerate(response.images):
print(f"Image {idx + 1}")
display(image._pil_image)Use negative prompts, custom aspect ratios, and fine-tuned parameters for more control:
response = generator.generate_images(
prompt="Modern office chair with leather upholstery, studio lighting",
number_of_images=3,
negative_prompt="low quality, blurry, distorted, watermark, shadow artifacts",
aspect_ratio="16:9", # Supported: "1:1", "4:3", "16:9"
guidance_scale=20, # Higher = more prompt-adherent (range: 1β30)
temperature=0.7, # Controls creativity (range: 0.0β1.0)
person_generation="avoid" # Options: "allow", "avoid"
)| Parameter | Type | Description |
|---|---|---|
prompt |
str |
Text description of the image to generate |
number_of_images |
int |
Number of images to generate (1β8) |
negative_prompt |
str |
Elements to exclude from the image |
aspect_ratio |
str |
Output dimensions: "1:1", "4:3", "16:9" |
guidance_scale |
float |
Prompt adherence strength (1β30) |
temperature |
float |
Creativity level (0.0β1.0) |
seed |
int |
Random seed for reproducibility |
person_generation |
str |
Controls human appearance in output |
Writing better prompts leads to significantly better results. Here are some best practices:
- Be specific about lighting:
"soft diffused lighting","dramatic side lighting","golden hour sunlight" - Specify background:
"plain white background","black satin surface","blurred outdoor setting" - Include view angles:
"front view","360-degree view","top-down flat lay" - Add quality modifiers:
"4K resolution","ultra-realistic","studio quality","sharp focus" - Use negative prompts to exclude unwanted artifacts:
"no watermark, no blurring, no distortion"
π See the full Prompt Engineering Guide for more.
| Error | Cause | Solution |
|---|---|---|
PermissionDenied: 403 |
Missing IAM permissions | Verify Vertex AI User role is assigned |
InvalidModelName: 404 |
Wrong model name or region | Check spelling & regional availability |
InvalidAspectRatio |
Unsupported ratio used | Use "1:1", "4:3", or "16:9" only |
QuotaExceeded |
API quota limit hit | Request quota increase in Cloud Console |
BillingNotEnabled |
GCP billing inactive | Enable billing at console.cloud.google.com |
# Update the Vertex AI SDK
pip install --upgrade google-cloud-aiplatform
# Enable required GCP services
gcloud services enable aiplatform.googleapis.com
# Verify authentication
gcloud auth application-default print-access-tokenvertex-ai-imagen3-colab/
βββ image_generation.py # Core image generation script
βββ requirements.txt # Python dependencies
βββ Images/ # Sample output images
β βββ img0.png # Sneakers example
β βββ img1.png # Smartwatch example
β βββ ...
βββ README.md # This file
| Resource | Link |
|---|---|
| π Imagen 3 Technical Docs | cloud.google.com/vertex-ai/docs |
| π Python SDK Reference | googleapis.dev/python/aiplatform |
| π Prompt Engineering Guide | Image Prompting Best Practices |
| π Safety Filter Settings | Content Safety Docs |
| π° Pricing | Vertex AI Pricing |
Contributions are welcome! Here's how to get started:
- Fork the repository π
- Clone your fork:
git clone https://github.com/your-username/vertex-ai-imagen3-colab.git cd vertex-ai-imagen3-colab - Create a feature branch:
git checkout -b feature/your-feature-name
- Commit your changes:
git commit -m "Add: description of your change" - Push and open a Pull Request π
Please follow existing code style and include comments where appropriate.
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
All generated images must comply with Google's Generative AI Prohibited Use Policy. Please ensure responsible and ethical use of AI-generated content.
Built with β€οΈ using Google Vertex AI Imagen 3.
If you find this project helpful:
- β Star the repository
- π Fork it to build your own version
- π£ Share it with others who might benefit
Happy generating! π
| Repository | Architecture & Focus | Live Status |
|---|---|---|
| gemma4-multilora-adk-eval | Dynamic Multi-LoRA Hot-Swapping & CI/CD Agent Evaluation (adk eval) on Cloud Run GPUs with Gemma 4 & vLLM |
|
| slothsre-napops | SlothSRE ("NapOps") β Overnight Gemma 4 & Google ADK Incident Digest Agent with OpenTelemetry & Sentry AI Monitoring | |
| streamforge-event-adk | Real-Time Event-Driven Multi-Agent Pipelines on Google Cloud with ADK (ParallelAgent & LoopAgent), Eventarc & Pub/Sub |
|
| a2a-mcp-mesh-cloudrun | Agent-to-Agent (A2A) & Multi-MCP Mesh on Cloud Run with Gemma 4, Google ADK, Spanner Graph & AlloyDB | |
| cloudguard-gemma-agent | 6-Part Production Gemma Enterprise Agent Series (ADK, Cloud Run L4 GPU, Firestore, Model Armor, Vertex AI QLoRA) | |
| Comic-Studio-Ai | Multi-Agent Comic Generator powered by Google Gemini API & FastAPI deployed on Google Cloud Run | |
| vertex-ai-imagen3 | Generate AI-powered product & editorial images using Google Vertex AI Imagen 3 in Google Colab | |
| Python-Learning-Assistant | AI-powered Python tutor covering 50+ interactive exercises with real-time feedback built with Streamlit + Gemini API | |
| cozy-ai-agent-cafe-game | Prompt Paws: 60 FPS Cozy AI Agent Bakery Simulation Game teaching RAG, Guardrails, Context Caching & Multi-Agent Loops |
If this project is helpful to your work:
- Star this Repository: Star
RobinaMirbahar/vertex-ai-imagen3on GitHub to bookmark it and help others discover it. - Fork & Customize: Fork
RobinaMirbahar/vertex-ai-imagen3to build and experiment with your own workflows. - Sponsor on GitHub: Sponsor
@RobinaMirbaharon GitHub Sponsors (github.com/sponsors/RobinaMirbahar) to support future open-source Google (@google), Google Gemini (@google-gemini), Google DeepMind (@google-deepmind), and Google Cloud (@GoogleCloudPlatform) cookbooks!