Pelatihan kustom Hello: Menyiapkan project dan lingkungan Anda

Halaman ini berisi penjelasan mengenai penyiapan project Google Cloud untuk menggunakan Agent Platform dan mendownload beberapa kode TensorFlow untuk pelatihan. Anda juga akan mendownload kode untuk aplikasi web yang mendapatkan prediksi.

Tutorial ini memiliki beberapa halaman:

  1. Menyiapkan project dan lingkungan Anda.

  2. Melatih model klasifikasi gambar kustom.

  3. Menyajikan prediksi dari model klasifikasi gambar kustom.

  4. Membersihkan project Anda.

Setiap halaman mengasumsikan bahwa Anda telah menjalankan petunjuk dari halaman sebelumnya dalam tutorial ini.

Sebelum memulai

Dalam tutorial ini, gunakan konsol Google Cloud dan Cloud Shell untuk berinteraksi dengan Google Cloud. Atau, bukan Cloud Shell, Anda dapat menggunakan shell Bash lain dengan Google Cloud CLI yang sudah terinstal.

  1. 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.
  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 Agent Platform and Cloud Run functions APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  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 Agent Platform and Cloud Run functions APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  8. Di konsol Google Cloud , aktifkan Cloud Shell.

    Aktifkan Cloud Shell

    Di bagian bawah konsol Google Cloud , sesi Cloud Shell akan dimulai dan menampilkan perintah command line. Cloud Shell adalah lingkungan shell dengan Google Cloud CLI yang sudah terinstal, dan dengan nilai yang sudah ditetapkan untuk project Anda saat ini. Diperlukan waktu beberapa detik untuk melakukan inisialisasi pada sesi.

  9. Jika Cloud Shell tidak menampilkan (PROJECT_ID)$ dalam perintahnya (dalam hal ini PROJECT_ID diganti dengan Google Cloud project ID), jalankan perintah berikut untuk mengonfigurasi Cloud Shell dan menggunakan project Anda:

    gcloud config set project PROJECT_ID
    

Membuat bucket Cloud Storage

Buat bucket Cloud Storage regional di region us-central1 untuk digunakan selama tutorial ini. Saat mengikuti tutorial, gunakan bucket untuk beberapa tujuan:

  • Menyimpan kode pelatihan untuk Agent Platform yang akan digunakan dalam tugas pelatihan kustom.
  • Menyimpan artefak model yang dihasilkan tugas pelatihan kustom Anda.
  • Menghosting aplikasi web yang mendapatkan prediksi dari endpoint Platform Agen Anda.

Untuk membuat bucket Cloud Storage, jalankan perintah berikut di sesi Cloud Shell:

gcloud storage buckets create gs://BUCKET_NAME --project=PROJECT_ID --location=us-central1

Ganti kode berikut:

  • PROJECT_ID: ID Google Cloud project Anda.
  • BUCKET_NAME: Nama yang Anda pilih untuk bucket. Contoh, hello_custom_PROJECT_ID. Pelajari persyaratan untuk nama bucket.

Mendownload kode contoh

Download kode contoh untuk digunakan selama tutorial ini.

gcloud storage cp gs://cloud-samples-data/ai-platform/hello-custom/hello-custom-sample-v1.tar.gz - | tar -xzv

Untuk melihat file kode contoh secara opsional, jalankan perintah berikut:

ls -lpR hello-custom-sample

Direktori hello-custom-sample memiliki empat item:

  • trainer/: Direktori kode TensorFlow Keras untuk melatih model klasifikasi bunga.

  • setup.py: File konfigurasi untuk memaketkan direktori trainer/ ke dalam distribusi sumber Python yang dapat digunakan Platform Agen.

  • function/: Direktori kode Python untuk fungsi Cloud Run yang dapat menerima dan melakukan prapemrosesan permintaan prediksi dari browser web, mengirimkannya ke Platform Agen, memproses respons prediksi, dan mengirimkannya kembali ke browser.

  • webapp/: Direktori dengan kode dan markup untuk aplikasi web yang mendapatkan prediksi klasifikasi bunga dari Agent Platform.

Langkah berikutnya

Ikuti halaman berikutnya dalam tutorial ini untuk menjalankan tugas pelatihan kustom di Platform Agen.