CoreML development environment setup



This post records how I setup my local development environment for deep learning and convert the model to CoreML.

First of first, Let’s install python. coremltools 2.0 only supports python up to 3.6, but if you just brew install python3 , it will install python 3.7. So we need to tell homebrew that we want to install python 3.6:

$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

Ok, now you have python 3.6 installed, you can test this by running:

$ python3 --version
Python 3.6.5

Since coremltools has version restrictions on dependencies, it’s recommended to setup virtual environment for your development. I use virtualenv and use virtualenvwrapper for some convenient commands. Here we can just install these two packages with the default python comes with OSX.

First we need to make sure we use the right pip :

$ pip --version
pip 18.0 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

OK, now we are ready to install the virtual environment:

$ pip install virtualenv virtualenvwrapper

Once they are installed, we can setup our virtual environment, on my machine, I named it py3 since it’s a python3 env:

// create a virtual environment named py3, and use python3 as python // interpretor
$ mkvirtualenv py3 --python=python3
// switch to py3 environment
$ workon py3

Here, you have to make sure python3 is in PATH , if you install python using homebrew, this should already be handled for you.

Now we are in the virtual environment, let’s see if it has python 3.6:

(py3)$ python --version
Python 3.6.5

Cool. We have the right version of python. Now, let’s install packages that we need to build our deep learning model and Apple’s coremltools. The latest version that coremltools supports for Keras and Tensorflow are 2.1.6 and 1.5.0 respectively. So we have to tell pip to install the right version.

$ pip install coremltools keras==2.1.6 tensorflow==1.5.0 numpy pandas sklearn

Now, our environment is fully setup. We are ready to develop our model and convert it to CoreML. In the next post, I will write a simple CNN to classify hand written digits using MNIST dataset and convert it to CoreML.

Source: Deep Learning on Medium