איך יוצרים תמונות (Vertex AI Studio)
כדאי לנסות את Imagen ב-Colab Imagen ב-Vertex AI כולל כלי לשכתוב פרומפטים שמבוסס על LLM, שנקרא גם כלי לשכתוב פרומפטים. הכלי לשכתוב פרומפטים עוזר לכם לקבל תמונות באיכות גבוהה יותר על ידי הוספת פרטים נוספים לפרומפט.
אם משביתים את הכלי לשכתוב הנחיות, יכול להיות שהאיכות של התמונות תיפגע, וגם הדמיון בין התוצאה לבין ההנחיה שסיפקתם. התכונה הזו מופעלת כברירת מחדל בגרסאות המודל הבאות:
-
imagen-3.0-generate-002 -
imagen-4.0-generate-001 -
imagen-4.0-fast-generate-001 -
imagen-4.0-ultra-generate-001
ההנחיה שנכתבה מחדש מועברת בתגובת ה-API רק אם ההנחיה המקורית כוללת פחות מ-30 מילים.
שימוש בכלי לשכתוב פרומפטים
כדי להשתמש בכלי לשינוי ההנחיות:
המסוף
במסוף Google Cloud , עוברים לדף Vertex AI > Media Studio.
לוחצים על Imagen. מוצג הדף ליצירת תמונות ב-Imagen Media Studio.
בחלונית Settings, משנים את האפשרויות הבאות:
מודל: בוחרים מודל מבין האפשרויות הזמינות.
מידע נוסף על המודלים הזמינים זמין במאמר מודלים של Imagen
מספר התוצאות: מזיזים את פס ההזזה או מזינים ערך בין 1 ל-4.
בתיבה הנחיה שלילית, כותבים הנחיה שמתארת את מה שלא רוצים שיופיע בתמונה.
בתיבה כתיבת ההנחיה, לוחצים על עזרה בכתיבה.
מוצג החלון Enhance my prompt (שיפור ההנחיה).
בתיבה הנחיה נוכחית, כותבים את ההנחיה ולוחצים על שיפור.
ההנחיה ששכתבתם מוצגת בתיבה הנחיה משופרת. אפשר לערוך את ההנחיה המשופרת או להשתמש בה כמו שהיא.
לוחצים על הוספה כדי להשתמש בפרומפט שמוצג.
ההנחיה מוזנת בתיבה כתיבת ההנחיה.
לוחצים על יצירה.
REST
למידע נוסף על Imagen API, אפשר לעיין במקורות הבאים:
- Method:
endpoints.predict VisionGenerativeModelInstanceVisionGenerativeModelParamsVisionGenerativeModelResult
לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:
- 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"
}
]
}
המאמרים הבאים
- הגדרת השפה של פרומפט טקסטואלי
- הגדרת יחס גובה-רוחב
- השמטת תוכן באמצעות הנחיה שלילית
- יצירת תמונות דטרמיניסטיות