مشاهده در TensorFlow.org | مشاهده در گیتهاب | دانلود دفترچه یادداشت | دویدن در کاگل |
این راهنما برای کمک به کاربرانی است که برای اولین بار یک حساب کاربری در پلتفرم گوگل کلود راهاندازی میکنند، به طور خاص با هدف استفاده از tensorflow_cloud برای اجرای آسان آموزش در مقیاس بزرگ در پلتفرم هوش مصنوعی گوگل کلود. TensorFlow Cloud رابطهای برنامهنویسی کاربردی (API) ارائه میدهد که به کاربران امکان میدهد به راحتی از اشکالزدایی، آموزش، تنظیم کد Keras و TensorFlow در یک محیط محلی یا kaggle به آموزش/تنظیم توزیعشده در فضای ابری بروند.
۱. در پلتفرم ابری گوگل ثبت نام کنید
To start go to https://cloud.google.com/ and click on “Get Started For Free". This is a two step sign up process where you will need to provide your name, address and a credit card. The starter account is free and it comes with $300 credit that you can use. For this step you will need to provide a Google Account ( ie your Gmail account) to sign in.
After completing the sign up process you will be redirected to Google Cloud Platform welcome page . click on the "Home" tab and make a note of your Project ID and Project number. (see Identifying projects )
GCP_PROJECT_ID = 'YOUR_PROJECT_ID'
PROJECT_NUMBER = 'YOUR_PROJECT_NUMBER'
۲. Google Cloud SDK را فعال کنید و نوتبوک خود را احراز هویت کنید
Now that you have set up your project we can continue with the rest of the configuration steps directly from this notebook. There Three types of notebook, this step (step #2) is slightly different for each notebook, the rest of the steps (step #3 to #6) are the same for all notebooks.
- ۲.۱. احراز هویت برای نوتبوکهای Kaggle
- ۲.۲. احراز هویت برای نوتبوک Colab
- ۲.۳. احراز هویت برای نوتبوکهای ابری هوش مصنوعی - پشتیبانی نمیشود.
۲.۱ راهاندازی احراز هویت برای نوتبوک کاگل
If you are using a Kaggle notebook you will need to repeat this step for any new notebook that you use with this project. In your notebook click on Add-ons -> Google Cloud SDK and follow the instructions on the prompt. Then run the following command to add your auth credentials to this notebook.
import sys
if "kaggle_secrets" in sys.modules:
from kaggle_secrets import UserSecretsClient
UserSecretsClient().set_gcloud_credentials(project=GCP_PROJECT_ID)
۲.۲ راهاندازی احراز هویت برای یک نوتبوک Colab
If you are using a Colab notebook you will need to repeat this step for any new notebook that you use with this project. Run the following command to add your auth credentials to this notebook.
import sys
if "google.colab" in sys.modules:
from google.colab import auth
auth.authenticate_user()
۳. حساب صورتحساب خود را به پروژه خود پیوند دهید
Next step is to set up the billing account for this project. Google Cloud Creates a project for you by default which is called “My First Project”. We will use this default project. Use your Project ID (from step 1) to run the following commands. This will show you your Billing Account_ID, make a note of this for the next step.
gcloud beta billing accounts listاز Billing Account_ID خود که در بالا ذکر شد استفاده کنید و دستور زیر را اجرا کنید تا حساب صورتحساب خود را به پروژهتان متصل کنید.
توجه داشته باشید که اگر از یک پروژه موجود استفاده میکنید، ممکن است Account_ID را نبینید، این بدان معناست که مجوزهای لازم برای اجرای دستورات زیر، تماس با مدیر سیستم یا ایجاد یک پروژه جدید را ندارید.
BILLING_ACCOUNT_ID = 'YOUR_BILLING_ACCOUNT_ID'
!gcloud beta billing projects link $GCP_PROJECT_ID --billing-account $BILLING_ACCOUNT_ID
۴. فعال کردن APIهای مورد نیاز برای tensorflow-cloud در پروژه شما
For tensorflow_cloud we use two specific APIs: AI Platform Training Jobs API and Cloud builder API . Note that this is a one time setup for this project, you do not need to rerun this command for every notebook.
gcloud services --project $GCP_PROJECT_ID enable ml.googleapis.com cloudbuild.googleapis.com۵. یک مخزن ذخیرهسازی ابری گوگل ایجاد کنید
We will use this storage bucket for temporary assets as well as to save the model checkpoints. Make a note of the name of the bucket for future reference. Note bucket names are unique globally.
BUCKET_NAME = 'YOUR_BUCKET_NAME'
GCS_BUCKET = f'gs://{BUCKET_NAME}'
!gsutil mb -p $GCP_PROJECT_ID $GCS_BUCKET
یک حساب کاربری سرویس برای کارهای HP Tuning ایجاد کنید
This step is required to use HP Tuning on Google Cloud using CloudTuner. To create a service account and give it project editor access run the following command and make a note of your service account name.
SERVICE_ACCOUNT_NAME ='YOUR_SERVICE_ACCOUNT_NAME'
SERVICE_ACCOUNT_EMAIL = f'{SERVICE_ACCOUNT_NAME}@{GCP_PROJECT_ID}.iam.gserviceaccount.com'
!gcloud iam --project $GCP_PROJECT_ID service-accounts create $SERVICE_ACCOUNT_NAME
!gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
--member serviceAccount:$SERVICE_ACCOUNT_EMAIL \
--role=roles/editor
The default AI Platform service account is identified by an email address with the format service-PROJECT_NUMBER@cloud-ml.google.com.iam.gserviceaccount.com . Using your Project number from step one, we construct the service account email and grant the default AI Platform service account admin role (roles/iam.serviceAccountAdmin) on your new service account.
DEFAULT_AI_PLATFORM_SERVICE_ACCOUNT = f'service-{PROJECT_NUMBER}@cloud-ml.google.com.iam.gserviceaccount.com'
!gcloud iam --project $GCP_PROJECT_ID service-accounts add-iam-policy-binding \
--role=roles/iam.serviceAccountAdmin \
--member=serviceAccount:$DEFAULT_AI_PLATFORM_SERVICE_ACCOUNT \
$SERVICE_ACCOUNT_EMAIL
تبریک میگویم!
You are now ready to run tensorflow-cloud. Note that these steps only need to be run one time. Once you have your project setup you can reuse the same project and bucket configuration for future runs. For any new notebooks you will need to repeat the step two to add your Google Cloud auth credentials.
مقادیر زیر را یادداشت کنید زیرا برای اجرای tensorflow-cloud مورد نیاز هستند.
print(f"Your GCP_PROJECT_ID is: {GCP_PROJECT_ID}")
print(f"Your SERVICE_ACCOUNT_NAME is: {SERVICE_ACCOUNT_NAME}")
print(f"Your BUCKET_NAME is: {BUCKET_NAME}")
Your GCP_PROJECT_ID is: YOUR_PROJECT_ID Your SERVICE_ACCOUNT_NAME is: YOUR_SERVICE_ACCOUNT_NAME Your BUCKET_NAME is: YOUR_BUCKET_NAME
مشاهده در TensorFlow.org
مشاهده در گیتهاب
دانلود دفترچه یادداشت
دویدن در کاگل