Quickstart Using the Command-Line

This page shows you how to set up your macOS or Cloud Shell environment for working with Cloud Machine Learning Engine and run a simple program in TensorFlow.

Before you begin

  1. Sign in to your Google account.

    If you don't already have one, sign up for a new account.

  2. Select or create a Cloud Platform project.

    Go to the Projects page

  3. Enable billing for your project.

    Enable billing

  4. Enable the Cloud Machine Learning Engine and Compute Engine APIs.

    Enable the APIs

Set up your environment

For macOS users, we recommend that you set up your environment using the MACOS tab. Cloud Shell — which is available on macOS, Linux, and Windows — provides a quick way to try the Getting Started guide, but isn't suitable for ongoing development work. Another option you can use is Google Cloud Datalab.

macOS

  1. Confirm that you have Python 2.7 installed and, if necessary, install it.

    python -V
    
  2. Install the Google Cloud SDK for macOS by following the instructions in the Before you begin section of the Cloud SDK Quickstart.

  3. Initialize the Cloud SDK.

    gcloud init
    

    For more information about the initialization process, see initialize the Cloud SDK in the Cloud SDK documentation.

  4. Ensure that you have the latest version of pip, and if not, upgrade it.

    pip install -U pip
    
  5. Install TensorFlow.

    pip install -U --user tensorflow
    

    For more information about installing TensorFlow, go to the TensorFlow documentation

  6. Create Application Default Credentials.

    gcloud auth application-default login
    

Windows


You can use Cloud Shell to complete the Getting Started Guide, but Cloud Shell's resource limitations make it unsuitable for ongoing development work. Another option you can use is Google Cloud Datalab.

The following steps show you how to set up Cloud Shell for working with Cloud ML Engine.

  1. Open the Google Cloud Platform Console.

    Google Cloud Platform Console

  2. Click the Activate Google Cloud Shell button at the top of the console window.

    Activate Google Cloud Shell

    A Cloud Shell session opens inside a new frame at the bottom of the console and displays a command-line prompt. It can take a few seconds for the shell session to be initialized.

    Cloud Shell session

    Your Cloud Shell session is ready to use.

  3. Configure the gcloud command-line tool to use your selected project.

    gcloud config set project [selected-project-id]
    

    Where [selected-project-id] is your project id, without the enclosing brackets.

  4. Download and install TensorFlow.

    pip download tensorflow
    pip install --user -U tensorflow*.whl
    

Cloud Shell

  1. Open the Google Cloud Platform Console.

    Google Cloud Platform Console

  2. Click the Activate Google Cloud Shell button at the top of the console window.

    Activate Google Cloud Shell

    A Cloud Shell session opens inside a new frame at the bottom of the console and displays a command-line prompt. It can take a few seconds for the shell session to be initialized.

    Cloud Shell session

    Your Cloud Shell session is ready to use.

  3. Configure the gcloud command-line tool to use your selected project.

    gcloud config set project [selected-project-id]
    

    Where [selected-project-id] is your project id, without the enclosing brackets.

  4. Download and install TensorFlow.

    pip download tensorflow
    pip install --user -U tensorflow*.whl
    

Verify the Google Cloud SDK components

To verify that the Google Cloud SDK components are installed:

  1. List the models to verify that the command returns an empty list

    gcloud ml-engine models list
    
  2. Verify that the command returns an empty list:

    Listed 0 items.

    After you start creating models, you can see them listed by using this command.

Run a simple TensorFlow Python program

Run a simple TensorFlow Python program described on the TensorFlow installation page.

  1. Start a Python interactive shell.

    python
  2. Import TensorFlow.

    >>> import tensorflow as tf
  3. Create a constant that contains a string.

    >>> hello = tf.constant('Hello, TensorFlow!')
  4. Create a TensorFlow session.

    >>> sess = tf.Session()

    You can ignore the warnings that the TensorFlow library wasn't compiled to use certain instructions.

  5. Display the value of hello.

    >>> print(sess.run(hello))

    If successful, the system outputs:

    Hello, TensorFlow!
  6. Stop the Python interactive shell.

    >>> exit()

For more information about installing TensorFlow, go to Installing TensorFlow on the TensorFlow site.

What's next

Send feedback about...

Cloud Machine Learning Engine (Cloud ML Engine)