The Liberation Pledge

The historical campaign against foot binding in China struggled for 1000 years. Education, lobbying, and countless other methods made no traction in stopping what was (like eating animals today)…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Setting up deep learning environment the easy way on macOS High Sierra

Source: Google Images

This is from a long time Ubuntu user who recently picked up a MacBook Air for all the portability it has to offer.

I am completely new to macOS. I had to look around and experiment to install all the packages I was enjoying on Ubuntu. I decided to put together a simple setup guide to get the deep learning environment (particularly for Computer Vision) up and running on macOS the easy way.

I am documenting the process I followed to get things working. Some of the process may not be the efficient / optimized way but the goal here is to get the job done with minimal efforts / frustration.

Someone coming from Ubuntu background, completely new to macOS, just want to set things up for deep learning and doesn’t want to feel “I wish I didn’t pick up a MacBook”.

Following are the basic softwares/packages you need for deep learning. This is not an exhaustive list by any means. These are the basic things I work with for Computer Vision. Depending on your area of interest the list may vary.

On Ubuntu, we all know that we can just go to the terminal and sudo apt-get install <whatever-we-want>. But what’s the play here on macOS?

It turns out that macOS is also a Unix based Operating System. So, luckily we have the same terminal we are all familiar with. But with some changes in the way we interact through commands.

For example, instead of apt-get package manager we have brew (HomeBrew) here.

I have seen people recommending to install Xcode (an IDE for developers from Apple) as the first thing to do. But I don’t think it’s absolutely necessary. I was running Python scripts fine without actually installing Xcode and also Xcode is a heavy piece of software to run.

So, the bottom line is you will be pretty much fine without Xcode.

Open up Terminal and enter the above command. It will install brew and only the necessary xcode command line tools.

brew install python3

This will install latest version of Python for you. You can check whether it’s correctly installed by typing python3 on the terminal.

brew install pip3

This will install the package manager for Python3. You can check whether it’s correctly linked to Python3 by typing

pip3 -V

This should tell the version of pip and the version of Python it’s linked to. (Should be 3.x not 2.x)

Virtual environment is a super useful tool to keep things clean and separate. All the Python packages you install will be virtually contained within a particular virtual environment you create and will not mess with the things outside. Trust me, this will save you a lot of frustration in future.

pip3 install virtualenv virtualenvwrapper

Add the following few lines and save the file.

In Ubuntu, Python location used to be /usr/bin/python3

Now you are all set to create your first virtual environment.

You can create as many virtual environments you want with any name you wish.

mkvirtualenv cv -p python3

The above line creates a virtual environment named cv

Now you are inside the virtual environment cv . You can look for (cv) sign at the beginning of shell prompt.

Inside the virtual environment cv

You can come out of the environment by typing deactivate and enter the environment by typing workon <env-name>.

Before we start pip installing Python packages, let’s take care of some of the dependencies these packages have.

Come out of the virtual environment by typing deactivate.

brew install cmake

This installs cmake which is needed for dlib.

So, that’s it. Let’s get pip installing.

Go into the virtual environment by typing

workon cv

Make sure the (cv) sign appears in the command line.

Let’s install some of the pre-requisite/other useful packages.

pip install numpy h5py pillow scikit-image

Install OpenCV for Python by typing

pip install opencv-python

Note: opencv-python is a community supported package, not officially from OpenCV. It may be a bit slow since we are not compiling from source on our system. But this is the easiest way to get going.

pip install dlib

This might take a while. Please be patient till it completes the installation. (No, it’s not hung)

pip install tensorflow

This installs the cpu version of tensorflow. Again, we are not compiling from source. So, it’s not optimized for our system. But we will be fine with this. (Ignore the messages it prints about how it can be optimized for your system while importing tensorflow on the code)

pip install keras

Keras is a very beginner-friendly deep learning library. It runs on top of tensorflow. You can build models very quickly using keras.

Test all the packages installed by importing them. Type python on Terminal. It should give you the python shell. Import the packages one by one and check their version. Make sure you don’t face any error. If you are seeing any error, installation was not complete.

import packages and check their version

We installed the basic packages/software needed for deep learning (particularly for computer vision) on macOS High Sierra the easiest way possible without dealing with much frustration.

Peace.

Add a comment

Related posts:

What is Sales Engineering?

At the beginning of this year, I was doing some research on taking my data science career to the next level. As I was doing my research on possible opportunities, I sat down and made a mind-map of…

Mushroom Leather Can Change the Fashion Industry Completely

The leather situation in fashion is quite struggling. While genuine leather raises ethical and environmental issues; fake leather varieties often cause negative impacts on the environment, too…

The Gardyn Hydroponic System

July is the one anniversary of setting up my Gardyn brand indoor hydroponic system and it seemed appropriate to do an update. When the pandemic first hit and the store shelves emptied due to panic, I…