|
1 | 1 |
|
2 |
| -**Note**: you do not need to follow these instructions for the [Strata workshop](https://conferences.oreilly.com/strata/strata-ny/public/schedule/detail/60847) or the [Strange Loop](https://www.thestrangeloop.com) workshop. For those workshops, you just need [TensorFlow](https://www.tensorflow.org/install/) and [Jupyter notebook](http://jupyter.org/install.html) installed on your laptop. |
| 2 | +# Installation |
3 | 3 |
|
4 |
| -# Installation instructions for the TensorFlow/Cloud ML workshop |
| 4 | +We suggest installing the necessary libraries locally on your laptop as described below in "__Local Installation__", as that will let you run TensorBoard as part of the workshop, and let you run python scripts as well as notebooks. |
5 | 5 |
|
6 |
| - - [Project and Cloud ML setup](#project-and-cloud-ml-setup) |
7 |
| - - [Docker-based installation](#docker-based-installation) |
8 |
| - - [Download the container image](#download-the-container-image) |
9 |
| - - [Create a directory to hold data files needed by the workshop](#create-a-directory-to-hold-data-files-needed-by-the-workshop) |
10 |
| - - [Run the container](#run-the-container) |
11 |
| - - [Authorize gcloud in the running container](#authorize-gcloud-in-the-running-container) |
12 |
| - - [Restarting the container later](#restarting-the-container-later) |
13 |
| - - [Running the Docker container on a VM](#running-the-docker-container-on-a-vm) |
14 |
| - - [Virtual environment-based installation](#virtual-environment-based-installation) |
15 |
| - - [Install Conda + Python 2.7 to use as your local virtual environment](#install-conda--python-27-to-use-as-your-local-virtual-environment) |
16 |
| - - [Install TensorFlow into a virtual environment](#install-tensorflow-into-a-virtual-environment) |
17 |
| - - [Install some Python packages](#install-some-python-packages) |
18 |
| - - [Install the Google Cloud SDK](#install-the-google-cloud-sdk) |
19 |
| - - [Cloud ML SDK installation (for 'transfer learning' preprocessing)](#cloud-ml-sdk-installation-for-transfer-learning-preprocessing) |
20 |
| - - [Set up some data files used in the examples](#set-up-some-data-files-used-in-the-examples) |
21 |
| - - [Transfer learning example](#transfer-learning-example) |
22 |
| - - [Optional: Clone/Download the TensorFlow repo from GitHub](#optional-clonedownload-the-tensorflow-repo-from-github) |
| 6 | +But if you have trouble with your installation, you will be able to run everything but TensorBoard in [Colab notebooks instead](https://colab.research.google.com/). |
23 | 7 |
|
24 |
| -* * * |
| 8 | +## Local Installation |
25 | 9 |
|
26 |
| -You can set up for the workshop in two different, mutually-exclusive ways: |
| 10 | +It's highly recommended to use a Python virtual environment for this workshop, either [Virtualenv](https://virtualenv.pypa.io/en/stable) or [Conda](http://conda.pydata.org/miniconda.html). Either Python 2.7 or Python 3 will work. |
27 | 11 |
|
28 |
| -- [Running in a docker container](#docker-based-installation). |
29 |
| -- [Installing the necessary packages into a virtual environment](#virtual-environment-based-installation). |
| 12 | +Then install the following into your virtual environment: |
30 | 13 |
|
31 |
| -You will need to do the [Cloud Project and Cloud ML setup](#project-and-cloud-ml-setup) in either case. |
| 14 | +- Install [TensorFlow](https://www.tensorflow.org/install). Your TensorFlow version must be >=1.7 to run all the labs. Note that even if you're running a conda virtual environment, use `pip install tensorflow` to install TensorFlow (*not* the `conda install` version, which may not be up to date.) |
32 | 15 |
|
33 |
| -## Project and Cloud ML setup |
| 16 | +- Install [Jupyter](https://jupyter.org/install.html). |
34 | 17 |
|
35 |
| -Follow the instructions below to create a project, initialize it for Cloud ML, and set up a storage bucket to use for the workshop examples. |
| 18 | +- Optionally, install `matplotlib`. (If you're using a conda virtual environment, use `conda install matplotlib`.) |
36 | 19 |
|
37 |
| -**Note: Skip the "Setting up your environment" section** of the linked-to page at this step. (If you run in a docker container, it is already done for you). |
| 20 | +### Test your installation |
38 | 21 |
|
39 |
| -* [Setting Up Your GCP Project](https://cloud.google.com/ml/docs/how-tos/getting-set-up#setting_up_your_google_cloud_project ) |
40 |
| -* [Initializing Cloud ML for your project](https://cloud.google.com/ml/docs/how-tos/getting-set-up#initializing_your_product_name_short_project) |
41 |
| -* [Setting up your Cloud Storage Bucket](https://cloud.google.com/ml/docs/how-tos/getting-set-up#setting_up_your_cloud_storage_bucket) |
42 |
| - |
43 |
| -## Docker-based installation |
44 |
| - |
45 |
| -We're providing a [Docker](https://www.docker.com/) container image with all the necessary libraries included, for you to download. |
46 |
| - |
47 |
| -To use it, you'll need to have [Docker installed](https://docs.docker.com/engine/installation/). |
48 |
| -To run some of the examples, you'll likely need to configure it with at least 4GB of memory. |
49 |
| - |
50 |
| -If you like, you can start up a Google Compute Engine (GCE) VM with docker installed, and run the container there. This is a good option if you don't want to install Docker locally. See the instructions at the end of this section for how to do that. |
51 |
| - |
52 |
| -### Download the container image |
53 |
| - |
54 |
| -Once Docker is installed and running, download the workshop image: |
55 |
| - |
56 |
| -```sh |
57 |
| -$ docker pull gcr.io/google-samples/tf-workshop:v7 |
58 |
| -``` |
59 |
| - |
60 |
| -[Here's the Dockerfile](https://github.com/amygdala/tensorflow-workshop/tree/master/workshop_image) used to build this image. |
61 |
| - |
62 |
| -### Create a directory to hold data files needed by the workshop |
63 |
| - |
64 |
| -Create a directory (called, say, `workshop-data`) to mount as a volume when you start up the docker container. You can put data/output in this directory so that it is accessible both within and outside the running container. |
65 |
| - |
66 |
| -### Run the container |
67 |
| - |
68 |
| -Once you've downloaded the container image, you can run it like this: |
| 22 | +Start up a jupyter notebooks server from the command line: |
69 | 23 |
|
70 | 24 | ```sh
|
71 |
| -docker run -v `pwd`/workshop-data:/root/tensorflow-workshop-master/workshop-data -it \ |
72 |
| - -p 6006:6006 -p 8888:8888 -p 5000:5000 gcr.io/google-samples/tf-workshop:v7 |
| 25 | +jupyter notebook . |
73 | 26 | ```
|
74 | 27 |
|
75 |
| -Edit the path to the directory you're mounting as appropriate. The first component of the `-v` arg is the local directory, and the second component is where you want to mount it in your running container. |
| 28 | +Create a new notebook and paste the following python code into a notebook cell: |
76 | 29 |
|
77 |
| -### Authorize gcloud in the running container |
| 30 | +```python |
| 31 | +import tensorflow as tf |
78 | 32 |
|
79 |
| -In the docker container, run the following commands, replacing `<your-project-name` with your project name. |
80 |
| -For the second two, you will get a URL to paste in your browser, to obtain an auth code. In the browser, allow access, then copy the resulting code and paste it at the prompt in your running docker container. |
81 |
| - |
82 |
| -```shell |
83 |
| -gcloud config set project <your-project-name> |
84 |
| -gcloud auth login |
85 |
| -gcloud auth application-default login |
86 |
| -``` |
87 |
| - |
88 |
| -### Restarting the container later |
89 |
| - |
90 |
| -If you later exit your container and then want to restart it again, you can find the container ID by running: |
91 |
| - |
92 |
| -```sh |
93 |
| -$ docker ps -a |
94 |
| -``` |
95 |
| - |
96 |
| -Then, run: |
97 |
| - |
98 |
| -```sh |
99 |
| -$ docker start <container_id> |
| 33 | +print(tf.__version__) |
100 | 34 | ```
|
101 | 35 |
|
102 |
| -(`docker ps` should then show it running). Once the workshop container is running again, you can exec back into it like this: |
| 36 | +'Run' the cell. Ensure that there are no import errors and that the TensorFlow version is as expected. |
103 | 37 |
|
104 |
| -```sh |
105 |
| -$ docker exec -it <container_id> bash |
106 |
| -``` |
| 38 | +## Using Colaboratory |
107 | 39 |
|
108 |
| -### Running the Docker container on a VM |
| 40 | +Instead of running in a local installation, all of the jupyter notebooks in this workshop can also be run on [Colab](https://colab.research.google.com/), with the exception of the lab sections that use TensorBoard. |
109 | 41 |
|
110 |
| -It is easy to set up a Google Compute Engine (GCE) VM on which to run the Docker container. We sketch the steps below. |
| 42 | +The lab section READMEs include links to launch the workshop notebooks in colab. |
111 | 43 |
|
112 |
| -First, make sure that your project has the GCE API enabled. An easy way to do this is to go to the [Cloud Console](https://console.cloud.google.com/), and visit the Compute Engine panel. It should display a button to enable the API. |
113 | 44 |
|
114 |
| -- Connect to your project's [Cloud Shell](https://cloud.google.com/shell/). |
| 45 | +## Google Cloud Platform |
115 | 46 |
|
116 |
| -- From the Cloud Shell, create a container-optimized image as described [here](https://cloud.google.com/container-optimized-os/docs/how-to/create-configure-instance). E.g.: |
117 |
| - |
118 |
| -``` |
119 |
| -gcloud compute instances create mlworkshop \ |
120 |
| - --image-family gci-stable \ |
121 |
| - --image-project google-containers \ |
122 |
| - --zone us-central1-b --boot-disk-size=100GB \ |
123 |
| - --machine-type n1-standard-1 |
124 |
| -``` |
125 |
| - |
126 |
| -- Set up a default network firewall rule for: tcp:8888, tcp:6006, and tcp:5000. (This opens the ports we'll use for jupyter, Tensorboard, and Flask.) E.g: |
127 |
| - |
128 |
| -```shell |
129 |
| -gcloud compute firewall-rules create mlworkshop --allow tcp:8888,tcp:6006,tcp:5000 |
130 |
| -``` |
| 47 | +Some of the labs include instructions for optionally running training and prediction on Google Cloud Platform (GCP) [Cloud ML Engine](https://cloud.google.com/ml-engine). |
131 | 48 |
|
132 |
| -- SSH to your image. You can do this from the Cloud Console by visiting the Compute Engine panel, and clicking on the 'SSH' pulldown to the right of your instance. |
| 49 | +If you want to play along, set up a GCP account: click the **Try it free** button at the top of this page: |
| 50 | +[cloud.google.com](https://cloud.google.com/). |
133 | 51 |
|
134 |
| -Then, once you've ssh'd to the VM, follow the instructions above to download and run the Docker container there. |
135 |
| -Note: **Docker is already installed** on the 'container-optimized' VMs. |
136 | 52 |
|
137 |
| -When you're done with the workshop, you may want to *stop* or *delete* your VM instance. |
| 53 | +## Docker image |
138 | 54 |
|
139 |
| -You can also delete your firewall rule: |
| 55 | +A Docker image is also available. |
140 | 56 |
|
141 |
| -```shell |
142 |
| -gcloud compute firewall-rules delete mlworkshop |
143 |
| -``` |
144 |
| - |
145 |
| -* * * |
146 |
| -## Virtual environment-based installation |
147 |
| - |
148 |
| -(These steps are not necessary if you have already completed the instructions for running the Docker image.) |
149 |
| - |
150 |
| -We highly recommend that you use a virtual environment for your TensorFlow installation rather than a direct install onto your machine. The instructions below walk you through a `conda` install, but a `virtualenv` environment will work as well. |
151 |
| - |
152 |
| -### Install Conda + Python 2.7 to use as your local virtual environment |
153 |
| - |
154 |
| -Anaconda is a Python distribution that includes a large number of standard numeric and scientific computing packages. Anaconda uses a package manager called "conda" that has its own environment system similar to Virtualenv. |
155 |
| - |
156 |
| -Follow the instructions [here](https://www.continuum.io/downloads). The [miniconda version](http://conda.pydata.org/miniconda.html) should suffice. |
157 |
| - |
158 |
| -### Install TensorFlow into a virtual environment |
159 |
| - |
160 |
| -Follow the instructions [on the TensorFlow site](https://www.tensorflow.org/get_started/os_setup#anaconda_installation) to create a Conda environment with Python 2.7, *activate* it, and then install TensorFlow within it. |
161 |
| - |
162 |
| -**Note**: Install TensorFlow version 0.12, by using the [**pip install steps**](https://www.tensorflow.org/get_started/os_setup#anaconda_installation#using_pip) for conda rather than conda-forge. |
163 |
| - |
164 |
| -If you'd prefer to use virtualenv, see [these instructions](https://www.tensorflow.org/get_started/os_setup#virtualenv_installation) instead. |
165 |
| - |
166 |
| -Remember to activate your environment in all the terminal windows you use during this workshop. |
167 |
| - |
168 |
| -### Install some Python packages |
| 57 | +### Download the container image |
169 | 58 |
|
170 |
| -With your conda environment activated, install the following packages: |
| 59 | +Once Docker is installed and running, download the workshop image: |
171 | 60 |
|
172 | 61 | ```sh
|
173 |
| -$ conda install numpy |
174 |
| -$ conda install scipy |
175 |
| -$ pip install sklearn pillow |
176 |
| -$ conda install matplotlib |
177 |
| -$ conda install jupyter |
| 62 | +docker pull gcr.io/google-samples/tf-workshop:v8 |
178 | 63 | ```
|
179 | 64 |
|
180 |
| -(If you are using `virtualenv` instead of `conda`, install the packages using the equivalent `pip` commands instead). |
181 |
| - |
182 |
| - |
183 |
| -### Install the Google Cloud (gcloud) SDK |
184 |
| - |
185 |
| -Follow the installation instructions [here](https://cloud.google.com/sdk/downloads), then run: |
186 |
| - |
187 |
| -``` |
188 |
| -gcloud components install beta |
189 |
| -``` |
190 |
| - |
191 |
| -To get the `gcloud beta ml` commands. |
192 |
| - |
193 |
| -### Cloud ML SDK installation (for 'transfer learning' preprocessing) |
194 |
| - |
195 |
| -The Cloud ML SDK is needed to run the 'preprocessing' stage in the [Cloud ML transfer |
196 |
| -learning](workshop_sections/transfer_learning/cloudml) example. It requires Python 2.7 to install. It's possible to |
197 |
| -skip this part of setup for most of the exercises. |
198 |
| - |
199 |
| -To install the SDK, follow the setup instructions |
200 |
| -[on this page](https://cloud.google.com/ml/docs/how-tos/getting-set-up). |
201 |
| -(Assuming you've followed the instructions above, you will have already done some of these steps. **Install TensorFlow version 0.12** as described in [this section](#install-tensorflow-into-a-virtual-environment), not 0.11) |
202 |
| - |
203 |
| -**Note**: if you have issues with the pip install of `python-snappy`, and are running in a conda virtual environment, try `conda install python-snappy` instead. |
204 |
| - |
205 |
| -You don't need to download the Cloud ML samples or docs for this workshop, though you may find it useful to grab them |
206 |
| -anyway. |
207 |
| - |
208 |
| - |
209 |
| -## Set up some data files used in the examples |
210 |
| - |
211 |
| -### Transfer learning example |
| 65 | +[Here's the Dockerfile](https://github.com/amygdala/tensorflow-workshop/tree/master/workshop_image) used to build this image. |
212 | 66 |
|
213 |
| -Because we have limited workshop time, we've saved a set of |
214 |
| -[TFRecords]([TFRecords](https://www.tensorflow.org/api_docs/python/python_io/)) |
215 |
| -generated as part of the [Cloud ML transfer learning](workshop_sections/transfer_learning/cloudml) |
216 |
| -example. To save time, copy them now to your own bucket as follows. |
| 67 | +### Run the container |
217 | 68 |
|
218 |
| -Set the `BUCKET` variable to point to your GCS bucket (replacing `your-bucket-name` with the actual name), then copy the records to your bucket. Then, set the GCS_PATH variable to the newly copied subdir. |
| 69 | +Once you've downloaded the container image, run it like this: |
219 | 70 |
|
220 |
| -```shell |
221 |
| -BUCKET=gs://your-bucket-name |
222 |
| -gsutil cp -r gs://tf-ml-workshop/transfer_learning/hugs_preproc_tfrecords $BUCKET |
223 |
| -GCS_PATH=$BUCKET/hugs_preproc_tfrecords |
| 71 | +```sh |
| 72 | +docker run -it \ |
| 73 | + -p 6006:6006 -p 8888:8888 -p 5000:5000 gcr.io/google-samples/tf-workshop:v8 |
224 | 74 | ```
|
225 | 75 |
|
226 | 76 |
|
227 |
| -## Optional: Clone/Download the TensorFlow repo from GitHub |
228 |
| - |
229 |
| -We'll be looking at some examples based on code in the tensorflow repo. While it's not necessary, you might want to clone or download it [here](https://github.com/tensorflow/tensorflow), or grab the latest release [here](https://github.com/tensorflow/tensorflow/releases). |
230 |
| - |
0 commit comments