Skip to content
This repository has been archived by the owner on Apr 2, 2022. It is now read-only.

Latest commit

 

History

History
118 lines (83 loc) · 4.49 KB

README.md

File metadata and controls

118 lines (83 loc) · 4.49 KB

Setup your Environment

Setup your GCP Environment

Before you can run any of the samples in this repository, you'll need to setup your GCP account and environment. The main steps are:

1- Have a GCP account and create/select a GCP project on GCP Console.

2- Enable the billing for your GCP project. Click here for more information.

3- Download and install Google Cloud SDK.

4- Configure the SDK by running the following command from your terminal:

gcloud init

and follow the instructions.

5- Enable the API for the following services:

From your terminal, run:

gcloud services enable compute.googleapis.com
gcloud services enable storage-component.googleapis.com
gcloud services enable ml.googleapis.com

6- Set and export the required environment variables. The samples in this repository rely on a number of environment variables to run properly, namely:

  • RUNTIME_VERSION: Which AI Platform runtime version to choose
  • PYTHON_VERSION: Which Python version to use for training
  • REGION: Which region should be used for training
  • PROJECT_ID: Your GCP project ID
  • BUCKET_NAME: The GCS bucket name for exporting models
  • GOOGLE_APPLICATION_CREDENTIALS: Full path to your service account key

You may set these variables yourself in your console, or you may just use variables.sh which sets up the first three variables with reasonable values, and enables you to set the other three variables based on your configuration.

In your terminal, and from the root directory of the repository, run:

source ./setup/variables.sh

Note: The service account key is a json file. If you do not yet have a service account key downloaded, please follow the instructions in the next step to create and download one.

7- Create and download a service account key. A service account is a special Google account that belongs to your application or a virtual machine (VM), instead of to an individual end user.

In order to create a service account key, you may follow the instructions here. Alternatively, you may run this in your terminal, after setting the values for the 3 environment variables:

# A name for the service account you are about to create:
export SERVICE_ACCOUNT_NAME=your-service-account-name

# Create service account:
gcloud iam service-accounts create ${SERVICE_ACCOUNT_NAME} --display-name="Service Account for ai-platform-samples repo"

# Grant the required roles:
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com --role roles/ml.developer
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com --role roles/storage.objectAdmin

# Download the service account key and store it in a file specified by GOOGLE_APPLICATION_CREDENTIALS:
gcloud iam service-accounts keys create ${GOOGLE_APPLICATION_CREDENTIALS} --iam-account ${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com

Setup your Python Virtual Environment

Virtual environments are strongly suggested, but not required. Installing this sample's dependencies in a new virtual environment allows you to run the sample locally without changing global python packages on your system.

There are two options for the virtual environments:

  • Install Virtualenv

    • Create virtual environment:
    virtualenv -p `which python3` myvirtualenv
    
    • Activate env:
    source myvirtualenv/bin/activate
    
  • Install Miniconda

    • Create conda environment:
    conda create --name myvirtualenv python=3.5
    
    • Activate env:
    source activate myvirtualenv
    

Install Dependencies

Each sample folder has a setup.py file, containing all the dependencies. To run each sample, install the python dependencies using the following command:

python setup.py install