הגדלת הרזולוציה של תמונות באמצעות Imagen

אתם יכולים להשתמש ב-Imagen ב-Vertex AI כדי להגדיל את התמונות בלי לפגוע באיכות שלהן.

המודלים הבאים תומכים בהגדלת תמונות:

לפני שמתחילים

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  8. מגדירים אימות לסביבה.

    צריך לבחור את הכרטיסייה הרלוונטית לאופן שבו תכננתם להשתמש בדוגמאות בדף הזה:

    המסוף

    כשמשתמשים במסוף Google Cloud כדי לגשת לשירותים ולממשקי ה-API, לא צריך להגדיר אימות. Google Cloud

    REST

    כדי להשתמש בסביבת פיתוח מקומית בדוגמאות של API בארכיטקטורת REST שבדף הזה, צריך להשתמש בפרטי הכניסה שאתם נותנים ל-CLI של gcloud.

      התקינו את ה-CLI של Google Cloud.

      אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

    מידע נוסף מופיע במאמר אימות לשימוש ב-REST במסמכי האימות של Google Cloud .

הגדלת הרזולוציה של תמונה

REST

מידע נוסף על Imagen API:

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • REGION: האזור שבו נמצא הפרויקט. מידע נוסף על אזורים נתמכים זמין במאמר מיקומי AI גנרטיבי ב-Vertex AI.
  • PROJECT_ID: מזהה הפרויקט ב- Google Cloud .
  • BASE64_SUBJECT_IMAGE: תמונה של הנושא בקידוד base64.
  • ADD_WATERMARK: ערך בוליאני אופציונלי. מגדירים את הערך true כדי להפעיל תמונות עם סימן מים, או false כדי להשבית תמונות עם סימן מים. ערך ברירת המחדל הוא true.
  • GCS_IMAGE_PATH: נתיב ב-Cloud Storage לקובץ תמונה.
  • GCS_OUTPUT_PATH: הנתיב ב-Cloud Storage שבו רוצים לשמור את הפלט שנוצר.
  • OUTPUT_MIMETYPE: מחרוזת אופציונלית שמגדירה את סוג קובץ הפלט של התמונה. הערכים הבאים קבילים: "image/png" או "image/jpeg". ערך ברירת המחדל הוא "image/png".
  • COMPRESSION_QUALITY: ערך של מספר שלם אופציונלי שמציין את רמת הפירוט שהמודל שומר עבור תמונות JPEG. הטווח הבא של ערכים קבילים: 0 עד 100. הערך הגבוה יותר מציין רמת דחיסה גבוהה יותר. ערך ברירת המחדל הוא 75.
  • UPSCALE_FACTOR: גורם קנה המידה של התמונה שהוגדלה. הרזולוציה הסופית של התמונה אחרי החלת גורם ההגדלה לא יכולה להיות גבוהה מ-17 מגה פיקסל. אלה הערכים הקבילים:
    • "x2"
    • "x3"
    • "x4"

ה-method של ה-HTTP וכתובת ה-URL:

POST https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict

גוף בקשת JSON:

{
  "instances": [
    {
      "prompt": "Upscale the image",
      "image": {
        // use one of the following to specify the image to upscale
        "bytesBase64Encoded": "BASE64_SUBJECT_IMAGE"
        "gcsUri": "GCS_IMAGE_PATH"
        // end of base image input options
      },
    }
  ],
  "parameters": {
    "mode": "upscale",
    "storageUri": "GCS_OUTPUT_PATH",
    "outputOptions": {
      "mimeType": "OUTPUT_MIMETYPE",
      "compressionQuality": COMPRESSION_QUALITY
    },
    "upscaleConfig": {
      "upscaleFactor": "UPSCALE_FACTOR"
    }
  }
}

כדי לשלוח את הבקשה עליכם לבחור אחת מהאפשרויות הבאות:

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://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview: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://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict" | Select-Object -Expand Content
הבקשה מחזירה אובייקט תמונה. בדוגמה הזו, אובייקט תמונה מוחזר כאובייקט חיזוי עם תמונה בקידוד Base64.
{
  "predictions": [
    {
      "mimeType": "image/png",
      "bytesBase64Encoded": "BASE64_IMG_BYTES"
    }
  ]
}


המאמרים הבאים

כדאי לקרוא מאמרים על Imagen ועל מוצרים אחרים של AI גנרטיבי ב-Vertex AI: