I have different Python on my Mac (Anaconda) and Ubuntu. The output I see on them are,
Either Python within Anaconda or otherwise will work.
If your version is not 3.4+, install it as follows.
- Homebrew in Mac OS (install homebrew from here, if unavailable).
b. Install virtualenv
virtualenv
is required to create a virtual environment. Download old mac os image. Its requirement is explained in the next section.
Mac OS
Ubuntu
Note: pip
(instead of pip3
) is also used sometimes. If unsure between the two, use pip3
. You will not go wrong with pip3
. If you want to know whether you could use pip
, run the following
In my system, the versions are the same for both pip
and pip3
. Therefore, I can use either of them.
Option 2: Python through Anaconda
Anaconda with Jupyter provides a simpler approach for installing Python and working on it.
Installing Anaconda is relatively straightforward. Follow this link with the latest Python3.x: https://jupyter.org/install
Similar to pip3
above, with Anaconda we have conda
for creating virtual environments and installing packages. In the following, we will look at the installations steps with both.
Step 1. Create a virtual environment in Python.
Why we want a virtual environment?
A virtual environment is an isolated environment for Python projects. Inside a virtual environment we can have a completely independent set of packages (dependencies) and settings that will not conflict with anything in other virtual environment or with the default local Python environment.
This means we can keep different versions of the same package, e.g. we can use scikit-learn 0.1 for one project, and scikit-learn 0.22 for another project on the same system but in different virtual environments.
Instantiate a virtual environment
Ubuntu/Mac (Python without Anaconda)
Snipping tool download free mac. The above command will create a virtual environment tf_2
. Understanding the command,
virtualenv
will create a virtual environment.--system-site-packages
allows the projects within the virtual environment tf_2
access the global site-packages. The default setting does not allow this access (--no-site-packages
was used before for this default setting but now deprecated.)-p python3
is used to set the Python interpreter for tf_2
. This argument can be skipped if the virtualenv
was installed with Python3. By default, that is the python interpreter for the virtual environment. Another option for setting Python3.x as interpreter is $ virtualenv --system-site-packages --python=python3.7 tf_2
. This gives more control.tf_2
is the name of the virtual environment we created. This creates a physical directory at the location of the virtual environments. This /tf_2
directory contains a copy of the Python compiler and all the packages we will install later.
Conda on Ubuntu/Mac (Python from Anaconda)
If you are using Conda, you can create the virtual environment as,
The above command will also create a virtual environment tf_2
. Unlike before, we do not require to install a different package for creating a virtual environment. The in-built conda
command provides this.
Understanding the command,
conda
can be used to create virtual environments, install packages, list the installed packages in the environment, and so on. In short, conda
performs operations that pip
and virtualenv
does. However, conda
does not replace pip
as some packages are available on pip
but not on conda
.create
is used to create a virtual environment.-n
is an argument specific to create
. -n
is used to name the virtual environment. The value of n
, i.e. the environment name, here is tf_2
.- Additional useful arguments: similar to
--system-site-packages
in virtualenv
, --use-local
can be used.
Step 2. Activate the virtual environment.
Activate the virtual environment.
Ubuntu/Mac (Python without Anaconda)
Conda on Ubuntu/Mac (Python from Anaconda)
After the activation, the terminal will change to this (tf_2) $
.
Step 3. Install TensorFlow 2.0.
Before starting the TensorFlow installation, we will update pip
.
Now, let’s install TensorFlow.
The tensorflow
argument above installs a CPU-only version. This is recommended for beginners. You can change the argument to one of the following based on your requirement.
tensorflow2.0.0-beta0
—Preview TF 2.0 Beta build for CPU-only (recommended).tensorflow-gpu2.0.0-beta0
—Preview TF 2.0 Beta build with GPU support.tensorflow
—Latest stable release for CPU-only.tensorflow-gpu
—Latest stable release with GPU support.tf-nightly
—Preview nightly build for CPU-only.tf-nightly-gpu
—Preview nightly build with GPU support.
Note: we will use pip install
for conda as well. TensorFlow is not available with conda
.
Tensorflow Download Mac
Step 4. Test the installation.
To quickly test the installation through the terminal, use
The output will be (ignoring the system messages), https://yellowez642.weebly.com/download-seamonkey-for-mac-free.html.
Pay attention on the TensorFlow version output. If it is not the version you installed (2.0.0-beta0, in this case), then something went wrong. Most likely, there is a prior installed TensorFlow and/or the current installation failed.
TensorFlow 2.0 Example
We will test and learn the TensorFlow 2.0 with MNIST (fashion_mnist) image classification example. Imagemagick download mac os x.
Make sure the tf.__version__
outputs 2.x. If the version is older, check your installation or the virtual environment.
Tensorflow Download Ans Setup Macro
Download the fashion_mnist data from the tf
open datasets and pre-process it.
To get familiarized with the data, we will plot a few examples from it.
Now we will build the model layer-by-layer.
Note that this model is only for demonstration and, therefore, trained on only five epochs.
We will now test the model accuracy on the test data.
We will visualize one of the predictions. We will use some UDFs from [3].
We will now get the prediction, i.e. the probability of each image belonging to each of the 10 classes, for the test images.
As we can see in the plot above, the prediction probability of ‘Ankle boot’ is the highest. To further confirm, we output the predicted label as,
Tensorflow Download Ans Setup Mac Os
Step 5. Deactivate the virtual environment
Before closing, we will deactivate the virtual environment.
Tensorflow Install On Mac
For virtualenv
use,
For conda
use,
Tensorflow Download Ans Setup Mac Download
Github repository
The GitHub repository with the MNIST example on TensorFlow 2.0 is here.
Conclusion
References