Quickstart Using Datalab

This page shows you how to run a basic Python program in TensorFlow using Google Cloud Datalab, which provides an interactive notebook environment for working with data and machine learning.

Before you begin

Run Cloud Datalab

It can take several minutes for Datalab to start the first time. When Datalab starts, a browser window opens to http://localhost:8081/ and the following output appears in the terminal window:

The connection to Datalab is now open and will remain until this command is killed.
You can connect to Datalab at http://localhost:8081/
  1. If this is your first time running Datalab, you might see an Accept button for the Terms of Service. If you agree to the terms, click Accept.

  2. Click on the Notebook icon (notebook-icon) to create a new notebook.

  3. Copy the following import statement and paste it into the notebook.

    import tensorflow as tf
  4. Click the menu icon and select Run.

    datalab run icon

    After the code successfully runs, a vertical blue line appears to the left of the code cell.

    Running the TensorFlow import statement in a separate code cell ensures that TensorFlow is always available to other code cells in the notebook. If you include other code with the import statement and the other code doesn't run, TensorFlow wouldn't be available to other cells unless you import TensorFlow again in those other cells.

  5. Click Add Code to append a new code cell.

    datalab add code icon

  6. Create a new TensorFlow interactive session by pasting the following code into the new code cell.

    session = tf.InteractiveSession()
  7. Click the menu icon for the new code cell and select Run.

  8. Click Add Code again to append a third code cell.

  9. Copy the following Python code and paste it into the third code cell.

    x = tf.constant(21)
    y = tf.constant(21)
    z = x + y
    print session.run(z)
  10. Click the menu icon and select Run.

    datalab run icon

    The system outputs:


Clean up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:

  • Follow the instructions in the Clean up section of the Cloud Datalab Quickstart.

What's next

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud Machine Learning Engine (Cloud ML Engine)