TL;DR: paste all the commands in your terminal in order of appearance; skip packages you already have (but update them).
Before we begin: make sure you have at least 50GB of free disk space and that your device isn’t running on battery power. We are going to run neural networks; just like the giant network in your brain it eats everything. Power, memory, time and even hard drives. It’s also good practice to make sure that your computer is properly cooled (all the vents have room to breathe). Your ambient room temperature shouldn’t be exceptionally high either (38C or 100F).
One day we might see a new software package or technology that you can install without dependancies and just a single command. Today is not that day, as TensorFlow has a spiderweb of used frameworks and libraries. But no matter, we simply install them one by one. For each library we install, you should check if you have it installed already. If you’re not sure it’s installed normally, you can opt to reinstall it or change the installation. In either case you should make sure you upgrade the package (get the latest version).
Some of the following commands require sudo (which means super do). After entering a command with sudo, your beloved computer will ask you kindly for your password. At this point, it is required to actually have a password, so if yours is blank right now, change it. You may consider temporarily shortening your password if your current password’s length is measured in megameters.
First we install Homebrew (brew). Brew makes it really easy to install a very, very large amount of different packages. Installing brew is really simple:
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
Next, we install python through brew. Please note that at as of the time of writing, you really really should install python 2, not 3. While python 3 is slightly faster (and arguably better), most TensorFlow demos are written in python 2. For future versions, replace python with python3 and (!!!) pip with pip3 if you want to use a python 3 installation.
brew install python
To install pip, we use easy install. If you don’t have easy install, run the following command:
sudo apt-get install python-setuptools
(Then) Install pip:
sudo easy_install pip
Next up is making a virtual environment. This makes sure that the TensorFlow code bulk won’t affect any of the other python projects you’re cooking up.
sudo pip install –upgrade virtualenv
Now go to Finder and create a folder in which you wish to install everything. A few folders should appear inside your folder as soon as you create your virtual environment:
virtualenv –system-site-packages SOME_PATH/SOME_FOLDER
A useful trick not to have to enter the whole folder path every time is to change the current directory with the “cd” command. In macOS, you can simply type “cd ” (make sure to include the space at the end). Before you hit enter, go to Finder, and drag the folder to your terminal window. This will paste the absolute folder path to the end of your input. The command should look something like this:
Once you do this, your prompt should change a little bit (your prompt is the thingy on the left in front of your commands. To make sure you really are in the right folder, you can enter this cute command:
This will list all of the files and folders inside the current directory. This list should match whatever you see in finder.
Note that we installed a virtual environment on the folder, but we haven’t yet activated it. To activate it; run
Once you do this, your prompt should change again. So how do you change it back? How do you deactivate this scary virtual environment?
Note that for now, we do want to be inside the virtual environment, so turn it back on for now. Once you’re done playing with TensorFlow, you should deactivate it.
Now the part we have been preparing for: TensorFlow itself. First we download the binaries from Google:
And then we install them:
sudo pip install –upgrade $TF_BINARY_URL
And that should be it. You now have TensorFlow installed. But that’s not very exciting yet now is it? How about we create some new works of Shakespeare. And I don’t mean start writing, I mean start training.
First we download or clone (whichever you prefer) the following Tensorflow port of Andrej Karpathy’s char-rnn:
If it came zipped, unzip it first. Now place this folder inside the folder you created for TensorFlow stuff (yes there’s already some stuff in that folder, at least there really should be at this point). Now using the same trick as before, go into the new folder and make sure the virtual environment is still active.
Now we are ready to start training. Note that this process may take hours, but you can safely prematurely end the process by hitting CTRL + C. Note that this will not like immediately terminate the program, give it a few seconds.
You can see how well it’s doing (don’t expect much within a few hundred iterations) by opening a new Terminal window and run the sample generator:
Once you’re done playing around with it and the network isn’t training anymore, you should make sure everything is back to normal again. Here are a few things you can check:
– Open Activity Monitor and make sure there are no more python programs running.
– Look for abnormalities in allocated memory in the memory tab.
– Trash the hidden space if desired