Skip to content

Instantly share code, notes, and snippets.

@TobeyQin
Last active September 10, 2018 09:30
Show Gist options
  • Save TobeyQin/6d32bf3d864376c5f4351f8b80928d22 to your computer and use it in GitHub Desktop.
Save TobeyQin/6d32bf3d864376c5f4351f8b80928d22 to your computer and use it in GitHub Desktop.
Build PyCaffe Wheel Package
Environment:
- Ubuntu 16.04
- Python 2.7.12
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 python-dev
Clone Caffe repo:
- git clone https://github.com/BVLC/caffe.git
Install python depencies
- for req in $(cat requirements.txt); do pip install $req; done
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