Deep learning with Cuda 7, CuDNN 2 and Caffe for Digits 2 and Python on iMac with NVIDIA GeForce GT 755M/640M GPU (Mac OS X)
Install on iMac, OS X 10.10.4
This install has been tested on
- a new iMac 27” with NVIDIA GeForce GT 755M 1024 Mo
- an old iMac 21” with NVIDIA GeForce GT 640M 512 Mo
NVIDIA is great!
1. Install Mac Os Command Line Tools if not already installed :
xcode-select --install
2. Install Cuda 7 (pass this step if your Mac GPU is not CUDA capable)
Check your version and the path.
You can also install the latest version of the driver (recommended) because the driver in Cuda is not the latest one.
3. Download CuDNN (pass this step if your Mac GPU is not CUDA capable)
wget https://s3-eu-west-1.amazonaws.com/christopherbourez/public/cudnn-6.5-osx-v2.tgz
tar xvzf cudnn-6.5-osx-v2.tgz
rm cudnn-6.5-osx-v2.tgz
cd cudnn-6.5-osx-v2/
sudo cp cudnn.h /Developer/NVIDIA/CUDA-7.0/include/
sudo cp libcudnn* /usr/local/cuda/lib/
4. Install Python packages
brew install python #if not already installed
pip install --upgrade pip setuptools #or update
You can verify that Python is at the right place, installed via Homebrew :
5. Install other packages
brew tap homebrew/science
brew update
brew install snappy leveldb gflags glog szip lmdb hdf5 numpy opencv graphviz
brew install --build-from-source --with-python -vd protobuf
6. Install boost 1.57 (Caffe is not compatible with Boost 1.58 as explained here). For that reason change the /usr/local/Library/Formula/boost.rb
with the contents of boost.rb 1.57 and /usr/local/Library/Formula/boost-python.rb
with the contents of boost-python.rb 1.57.
brew install --build-from-source -vd boost boost-python
7. Clone the caffe repository
mkdir technologies
cd technologies
git clone https://github.com/BVLC/caffe.git
cd caffe
vi Makefile.config
8. Create the configuration file Makefile.config
Note the Python lib directory /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib
.
If your iMac is not CUDA capable, comment USE_CUDNN := 1
, CUDA_DIR := /usr/local/cuda
and CUDA_ARCH=...
lines and uncomment CPU_ONLY := 1
Here is the full copy of the Makefile.config.
9. Build
Here is the result of the runtest run.
10. Download DIGITS
and choose ../caffe
as Caffe path.
The server will be running at http://0.0.0.0:5000/
You can then have fun with DIGITS as we did on Ubuntu : download the MNIST dataset python tools/download_data/main.py mnist ~/data/mnist
and train a first classifier on your GPU.
R-CNN Example
Now it’s easy to try the R-CNN example from Ross Girshick :
Well done!
Troubleshooting :
A few help on common errors :
Undefined symbols for architecture x86_64: “cv::imread
=> Clean all the opencv before re-installing it
sudo make uninstall #in the opencv build repo (if you installed from source)
brew uninstall opencv
brew uninstall opencv3
rm /usr/local/lib/libopencv_*
sudo rm -r /usr/local/share/OpenCV
sudo rm -r /usr/local/include/opencv2
Be careful to brew messages, all libraries have to be linked.
Undefined symbols for architecture x86_64: “google::SetUsageMessage
=> Re-install gflags. brew install gflags
Undefined symbols for architecture x86_64: “leveldb::
=> Re-install leveldb. brew install leveldb
Undefined symbols for architecture x86_64: “google::protobuf:
=> Re-install protobuf. brew install --build-from-source --with-python -vd protobuf
./include/caffe/util/mkl_alternate.hpp:11:10: fatal error: ‘cblas.h’ file not found
#include
=> Install Mac OS command line tools xcode-select --install
.
TEXT 0000000109e08000-0000000109e0a000 [ 8K] r-x/rwx SM=COW /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 ??? 000000000000000000 0 + 0
1 org.python.python 0x0000000112c7f0dd PyEval_GetGlobals + 23
2 org.python.python 0x0000000112c8e62b PyImport_Import + 137
3 org.python.python 0x0000000112c8cd27 PyImport_ImportModule + 31
4 caffe.so 0x000000010c92bcf8 caffe::init_module__caffe() + 4328
5 libboost_python.dylib 0x0000000112ba0391 boost::python::handle_exception_impl(boost::function0
=> Add /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib
to the PYTHON lib in the Makefile.
nvcc fatal : The version (‘60100’) of the host compiler (‘Apple clang’) is not supported
=> Download XCode 6.0 to replace 6.3 Have a look at compatibilities and Clang versions.
On one of my imacs I had a Segmentation Fault 11.
=> I put the path to the correct library in the path since I used pip install numpy
instead of homebrew
PYTHON_LIB := /usr/local/Frameworks/Python.framework/Versions/2.7/lib/
PYTHON_INCLUDE := /usr/local/Frameworks/Python.framework/Versions/2.7/include/python2.7/ \
/usr/local/lib/python2.7/site-packages/numpy/core/include