Appendix. Installation

You can install TensorFlow in a couple of ways. This book assumes you’ll be using Python 3 for every chapter unless otherwise stated. The code listings abide by TensorFlow v1.0, but the accompanying source code on GitHub will always be up to date with the latest version (https://github.com/BinRoot/TensorFlow-Book/). This appendix covers one of these installation methods that works on all platforms, including Windows. If you’re familiar with UNIX-based systems (such as Linux or macOS), feel free to use one of the installation approaches in the official documentation: www.tensorflow.org/get_started/os_setup.html.

Without further ado, let’s install TensorFlow by using a Docker container.

A.1. Installing TensorFlow by using Docker

Docker is a system for packaging software dependencies to keep everyone’s installation environment identical. This standardization helps limit inconsistencies between computers. It’s a relatively recent technology, so let’s go through how to use it.

Tip

You can install TensorFlow in many ways other than using a Docker container. Visit the official documentation for more details on installing TensorFlow: www.tensorflow.org/get_started/os_setup.html.

A.1.1. Installing Docker on Windows

Docker works only on 64-bit Windows (7 or above) with virtualization enabled. Fortunately, most consumer laptops and desktops easily satisfy this requirement. To check whether your computer supports Docker, open Control Panel, click System and Security, and then click System. Here, you can see the details about your Windows machine, including processor and system type. If the system is 64-bit, you’re almost good to go.

The next step is to check whether your processor can support virtualization. On Windows 8 or higher, you can open the Task Manager (Ctrl-Shift-Esc) and click the Performance tab. If Virtualization shows up as Enabled, you’re all set. (See figure A.1.) For Windows 7, you should use the Microsoft Hardware-Assisted Virtualization Detection Tool (http://mng.bz/cBlu).

Figure A.1. Ensure that your 64-bit computer has virtualization enabled.

Now that you know whether your computer can support Docker, let’s install the Docker Toolbox located at www.docker.com/products/docker-toolbox. Run the downloaded setup executable, and accept all the defaults by clicking Next in the dialog boxes. After the toolbox is installed, run the Docker Quickstart Terminal.

A.1.2. Installing Docker on Linux

Docker is officially supported on several Linux distributions. The official Docker documentation (https://docs.docker.com/engine/installation/linux/) contains tutorials for Arch Linux, CentOS, CRUX Linux, Debian, Fedora, Frugalware, Gentoo, Oracle Linux, Red Hat Enterprise Linux, openSUSE, and Ubuntu. Docker is native to Linux, so there’s typically no problem installing it.

A.1.3. Installing Docker on macOS

Docker works on macOS 10.8 Mountain Lion or newer. Install the Docker Toolbox from www.docker.com/products/docker-toolbox. After installation, open the Docker Quickstart Terminal from the Applications folder or the Launchpad.

A.1.4. How to use Docker

Run the Docker Quickstart Terminal. Next, launch the TensorFlow binary image by using the following command in the Docker terminal, as shown in figure A.2:

$ docker run -p 8888:8888 -p 6006:6006 b.gcr.io/tensorflow/tensorflow
Figure A.2. Running the official TensorFlow container

TensorFlow will now be accessible from a Jupyter Notebook via a local IP address. The IP can be found by using the docker-machine ip command, as shown in figure A.3.

Figure A.3. Docker’s IP address can be found using the docker-machine ip command or can be found in the intro text under the ASCII whale.

Open a browser and navigate to http://<YOUR_IP_ADDRESS>:8888 to start using TensorFlow. In our case, the URL was http://192.168.99.100:8888. Figure A.4 shows the Jupyter Notebook accessed through a browser.

Figure A.4. You can interact with TensorFlow through a Python interface called Jupyter.

You can press Ctrl-C or close the terminal window to stop running the Jupyter Notebook. To rerun it, follow the steps in this section again.

If you run into the error message shown in figure A.5, Docker is already using an application on that port.

Figure A.5. A possible error message from running the TensorFlow container

To resolve this issue, you can either switch the port or quit the intruding Docker containers. Figure A.6 shows how to list all containers by using docker ps and then kill the container by using docker kill.

Figure A.6. Listing and killing a Docker container to get rid of the error message in figure A.5

A.2. Installing Matplotlib

Matplotlib is a cross-platform Python library for plotting 2D visualizations of data. Generally, if your computer can successfully run TensorFlow, it’ll have no trouble installing Matplotlib. Install it by following the official documentation at http://matplotlib.org/users/installing.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.241.250