Forked from TobeyQin/build_pycaffe_wheel_for_linux_cpu_py3
Created
November 16, 2018 20:34
-
-
Save nicolasrosa/f15ab3c33e2f15ce9ac59301aaeecea4 to your computer and use it in GitHub Desktop.
Build PyCaffe wheel package for python3.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Environment: | |
- Ubuntu 16.04 | |
- Python 3.5 | |
Prerequisite: | |
- clone and prepare caffe environment according to this guide: http://caffe.berkeleyvision.org/install_apt.html | |
- Steps: | |
1. General dependencies: | |
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler | |
sudo apt-get install --no-install-recommends libboost-all-dev | |
2. Blas: | |
ATLAS(**By Default**): sudo apt-get install libatlas-base-dev | |
or | |
OpenBLAS: sudo apt-get install libopenblas-dev | |
3. Python (have the Python headers for building the pycaffe interface): | |
sudo apt-get install python3-dev | |
Clone Caffe repo: | |
- git clone https://github.com/BVLC/caffe.git | |
Install python depencies | |
- for req in $(cat requirements.txt); do pip3 install $req; done | |
Edit Config Files: | |
1. Edit CMakeLists.txt | |
In line 35: set(python_version "3" CACHE STRING "Specify which Python version to use") # Change to use python3 | |
[change "2" -> "3"] | |
2. Edit Makefile.config | |
In line 8: CPU_ONLY := 1 | |
In line 68-69: comment "PYTHON_INCLUDE" (donot use python2) | |
In line 78-80: uncomment "PYTHON_LIBRARIES" and "PYTHON_INCLUDE" (use python3) | |
Build Caffe: | |
- Build with CMake | |
mkdir build | |
cd build | |
cmake .. -DCMAKE_VERBOSE_MAKEFILE=1 -DBUILD_TEST=OFF -DBUILD_SHARED_LIBS=OFF -DCPU_ONLY=ON | |
make all | |
[NOTICE:] | |
If you want to build caffe without Database: you can append -DUSE_LEVELDB=OFF -DUSE_LMDB=OFF after cmake command. | |
- Build with Make | |
1. Copy Makefile.config | |
cp Makefile.config.example Makefile.config | |
2. Edit Makefile.config | |
- add "/usr/include/hdf5/serial" to "INCLUDE_DIRS": | |
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial | |
3. build caffe and pycaffe | |
make all | |
make pycaffe | |
Generate PyCaffe Package | |
cd python | |
mkdir libs | |
cp build/lib/libcaffe.so.1.0.0 python/libs | |
vim setup_py2.py | |
[**NOTE**: You can get the setup_py2.py code from https://github.com/PaulaQin/pycaffe_packages/tree/master/setupscripts/setup_py2.py] | |
python setup_py2.py bdist_wheel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment