איך יוצרים תמונות (Vertex AI Studio)
Imagen ב-Vertex AI מציע כלי לשכתוב הנחיות שמבוסס על LLM, שנקרא גם כלי לשכתוב הנחיות. הכלי לשכתוב הנחיות עוזר לכם לקבל תמונות באיכות גבוהה יותר על ידי הוספת פרטים להנחיה.
אם משביתים את הכלי לשכתוב הנחיות, יכול להיות שאיכות התמונות תיפגע ושהפלט לא יהיה דומה להנחיה שסיפקתם. התכונה הזו מופעלת כברירת מחדל בגרסאות המודל הבאות:
imagen-4.0-generate-001imagen-4.0-fast-generate-001imagen-4.0-ultra-generate-001imagen-3.0-generate-002
ההנחיה שנכתבה מחדש מועברת בתגובת ה-API רק אם ההנחיה המקורית כוללת פחות מ-30 מילים.
שימוש בכלי לשכתוב הנחיות
כדי להשתמש בכלי לשכתוב הנחיות:
המסוף
במסוף Google Cloud , עוברים לדף Vertex AI > Media Studio.
לוחצים על Imagen. מוצג הדף ליצירת תמונות ב-Imagen Media Studio.
בחלונית הגדרות, משנים את האפשרויות הבאות:
מודל: בוחרים מודל מבין האפשרויות הזמינות.
מידע נוסף על המודלים הזמינים מופיע במאמר מודלים של Imagen
מספר התוצאות: מזיזים את פס ההזזה או מזינים ערך בין 1 ל-4.
בתיבה הנחיה שלילית, כותבים הנחיה שמתארת מה לא רוצים שיופיע בתמונה.
בתיבה כתיבת ההנחיה, לוחצים על עזרה בכתיבה.
יוצג החלון שיפור ההנחיה שלי.
בתיבה הנחיה נוכחית, כותבים את ההנחיה ולוחצים על שיפור.
ההנחיה ששכתבתם מוצגת בתיבה הנחיה משופרת. אפשר לערוך את ההנחיה המשופרת או להשתמש בה כמו שהיא.
לוחצים על הוספה כדי להשתמש בהנחיה שמוצגת.
ההנחיה מוזנת בתיבה כתיבת ההנחיה.
לוחצים על יצירה.
REST
לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:
- PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
- MODEL_VERSION: גרסת המודל ליצירת תמונות שבה ייעשה שימוש.
מידע נוסף על גרסאות המודלים והתכונות שלהן זמין במאמר גרסאות המודלים.
- LOCATION: האזור של הפרויקט. לדוגמה,
us-central1,europe-west2אוasia-northeast3. רשימת האזורים הזמינים מופיעה במאמר מיקומים של AI גנרטיבי ב-Vertex AI. כשמשתמשים בנקודת קצה ל-API אזורית, האזור מכתובת ה-URL של נקודת הקצה קובע איפה הבקשה תעובד, והערךLOCATIONבנתיב המשאב מתעלם אם יש התנגשות. - TEXT_PROMPT: הנחיית טקסט שמנחה את המודל לגבי התמונות שהוא יוצר. לפני יצירת התמונות, ההנחיה הבסיסית הזו משופרת באמצעות כלי לשכתוב הנחיות שמבוסס על LLM, ומוסיפים לה פרטים נוספים ושפה תיאורית.
-
IMAGE_COUNT: מספר שלם שמתאר את מספר התמונות שרוצים ליצור. הערכים הקבילים הם
1עד4. ערך ברירת המחדל הוא4. -
PROMPT_SETTING: ערך בוליאני. הערך
trueמפעיל הנחיות משופרות, והערךfalseמשבית אותן. ערך ברירת המחדל הואtrue.
ה-method של ה-HTTP וכתובת ה-URL:
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict
גוף בקשת JSON:
{
"instances": [
{
"prompt": "TEXT_PROMPT"
}
],
"parameters": {
"sampleCount": IMAGE_COUNT,
"enhancePrompt": PROMPT_SETTING
}
}
כדי לשלוח את הבקשה עליכם לבחור אחת מהאפשרויות הבאות:
curl
שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict"
PowerShell
שומרים את גוף הבקשה בקובץ בשם request.json ומריצים את הפקודה הבאה:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict" | Select-Object -Expand Content
prompt נוסף שמציג את ההנחיה המשופרת ואת התמונה שנוצרה שמשויכת אליה:
{ "predictions": [ { "mimeType": "MIME_TYPE", "prompt": "ENHANCED_PROMPT_1", "bytesBase64Encoded": "BASE64_IMG_BYTES_1" }, { "mimeType": "MIME_TYPE", "prompt": "ENHANCED_PROMPT_2", "bytesBase64Encoded": "BASE64_IMG_BYTES_2" } ] }
לדוגמה, התגובה הבאה לדוגמה היא לבקשה עם "sampleCount": 2 ו-"prompt": "A raccoon wearing formal
clothes, wearing a top hat. Oil painting in the style of Vincent Van
Gogh.". התשובה מחזירה שני אובייקטים של חיזוי, כל אחד עם ההנחיה המשופרת שלו והבייטים של התמונה שנוצרה בקידוד base64.
{
"predictions": [
{
"mimeType": "image/png",
"prompt": "An oil painting in the style of Vincent van Gogh,
depicting a raccoon adorned in a finely tailored tuxedo, complete with a
crisp white shirt and a bow tie. The raccoon also sports a classic top
hat, perched jauntily on its head. The painting uses thick, swirling
brushstrokes characteristic of van Gogh, with vibrant hues of blue,
yellow, and green in the background, contrasting with the dark tones of
the raccoon's attire. The light source is subtly placed, casting a
dramatic shadow of the raccoon's attire onto the surface it sits upon,
further enhancing the depth and dimensionality of the composition. The
overall impression is one of a whimsical and sophisticated character, a
raccoon elevated to a higher class through its formal attire, rendered
in van Gogh's iconic style.",
"bytesBase64Encoded": "BASE64_IMG_BYTES"
},
{
"mimeType": "image/png",
"prompt": "An oil painting in the style of Vincent van Gogh featuring
a raccoon in a dapper suit, complete with a black jacket, crisp white
shirt, and a black bow tie. The raccoon is wearing a black top hat,
adding a touch of elegance to its ensemble. The painting is rendered
with characteristic van Gogh brushwork, utilizing thick, impasto strokes
of color. The background is a swirl of blues, greens, and yellows,
creating a vibrant yet slightly chaotic atmosphere that contrasts with
the raccoon's formal attire. The lighting is dramatic, casting sharp
shadows and highlighting the textures of the fabric and the raccoon's
fur, enhancing the sense of realism within the fantastical scene. The
composition focuses on the raccoon's proud posture, highlighting the
whimsical contrast of a wild animal dressed in formal attire, captured
in the unique artistic language of van Gogh. ",
"bytesBase64Encoded": "BASE64_IMG_BYTES"
}
]
}
המאמרים הבאים
- הגדרת השפה של הנחיות טקסט
- הגדרת יחס גובה-רוחב
- השמטת תוכן באמצעות הנחיה שלילית
- יצירת תמונות דטרמיניסטיות