Anda dapat menggunakan Imagen di Vertex AI untuk meningkatkan skala gambar, yang akan meningkatkan ukurannya tanpa mengurangi kualitas gambar.
Model berikut mendukung peningkatan kualitas gambar:
Sebelum memulai
- Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Siapkan autentikasi untuk lingkungan Anda.
Pilih tab untuk melihat bagaimana Anda berencana menggunakan contoh di halaman ini:
Konsol
Saat menggunakan konsol Google Cloud untuk mengakses layanan Google Cloud dan API, Anda tidak perlu menyiapkan autentikasi.
REST
Untuk menggunakan contoh REST API di halaman ini dalam lingkungan pengembangan lokal, gunakan kredensial yang Anda berikan ke gcloud CLI.
Instal Google Cloud CLI.
Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.
Untuk mengetahui informasi selengkapnya, lihat Melakukan autentikasi untuk menggunakan REST dalam dokumentasi autentikasi Google Cloud .
Meningkatkan skala gambar
REST
Untuk mengetahui informasi selengkapnya tentang Imagen API, lihat bagian berikut:
- Metode:
endpoints.predict VisionGenerativeModelInstanceVisionGenerativeModelParamsVisionGenerativeModelResult
Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:
-
REGION: Region tempat project Anda berada. Untuk mengetahui informasi selengkapnya tentang region yang didukung, lihat Lokasi AI Generatif di Vertex AI. -
PROJECT_ID: Google Cloud Project ID Anda. -
BASE64_SUBJECT_IMAGE: Gambar subjek yang dienkode base64. -
ADD_WATERMARK: Nilai Boolean opsional. Setel ketrueuntuk mengaktifkan gambar dengan watermark, ataufalseuntuk menonaktifkan gambar dengan watermark. Nilai default-nya adalahtrue. -
GCS_IMAGE_PATH: Jalur Cloud Storage ke file gambar. -
GCS_OUTPUT_PATH: jalur Cloud Storage untuk menyimpan output yang dihasilkan. -
OUTPUT_MIMETYPE: String opsional yang menentukan jenis file output gambar. Nilai berikut diterima:"image/png"atau"image/jpeg". Defaultnya adalah"image/png". -
COMPRESSION_QUALITY: Nilai bilangan bulat opsional yang menentukan tingkat detail yang dipertahankan model untuk gambar JPEG. Rentang nilai berikut diterima:0-100. Nilai yang lebih tinggi menentukan tingkat kompresi yang lebih tinggi. Defaultnya adalah75. -
UPSCALE_FACTOR: Faktor penskalaan untuk gambar yang di-upscale. Resolusi output akhir gambar setelah menerapkan faktor peningkatan kualitas tidak boleh melebihi 17 megapiksel. Nilai berikut diterima:"x2""x3""x4"
Metode HTTP dan URL:
POST https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict
Meminta isi 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"
}
}
}
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Simpan isi permintaan dalam file bernama request.json,
dan jalankan perintah berikut:
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
Simpan isi permintaan dalam file bernama request.json,
dan jalankan perintah berikut:
$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
{
"predictions": [
{
"mimeType": "image/png",
"bytesBase64Encoded": "BASE64_IMG_BYTES"
}
]
}
Langkah berikutnya
Baca artikel tentang Imagen dan produk AI Generatif lainnya di Vertex AI:
- Panduan developer untuk mulai menggunakan Imagen 3 di Vertex AI
- Model dan alat media generatif baru, dibuat dengan dan untuk kreator
- Baru di Gemini: Gem kustom dan peningkatan pembuatan gambar dengan Imagen 3
- Google DeepMind: Imagen 3 - Model text-to-image berkualitas tertinggi kami