-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall_caffe.sh
More file actions
executable file
·122 lines (89 loc) · 3.27 KB
/
install_caffe.sh
File metadata and controls
executable file
·122 lines (89 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
#
# Install caffe for distro's which do not provide it.
#
# You should totally switch to Debian, but this script is provided for the more
# stubborn.
# Exit on first error.
set -e
CAFFE_REPO="https://github.com/BVLC/caffe"
# Pin the repo to a fixed repo, so that we do not encounted breaking changes.
CAFFE_COMMIT="864520713a4c5ffae7382ced5d34e4cadc608473"
function install_system_deps() {
sudo apt update
# General Dependencies
sudo apt install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev protobuf-compiler
sudo apt install -y --no-install-recommends libboost-all-dev libhdf5-serial-dev libhdf5-dev
# BLAS -- for better CPU performance
sudo apt install -y libatlas-base-dev libblas-dev libopenblas-dev
# Required if you want to use Python wrappers for Caffe
sudo apt install -y python-dev libpython2.7-dev python3.6-dev libpython3.6-dev
# Remaining dependencies
sudo apt install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
# Build essentials.
sudo apt install -y build-essential cmake git pkg-config
}
# Because caffe by default does not build, we need to manually adjust the
# Makefile and Makefile.config files in order to fix them.
#
# This script should be run when the cwd is the caffe repo (i.e. caffe/).
function adjust_makefiles() {
# Use CPU only.
sed -i "/CPU_ONLY/s/^# //g" Makefile.config
# Enable the python layer.
sed -i "/WITH_PYTHON_LAYER/s/^# //g" Makefile.config
# Enable python3.
sed -i "/python3/s/^# //g" Makefile.config
# Use python3.6, not 3.5.
sed -i "s/python3.5/python3.6/g" Makefile.config
# Use python3.6, not 3.5.
sed -i "s/boost_python3/boost_python-py36/g" Makefile.config
# Disable python2.
sed -i "/python2/s/^/# /g" Makefile.config
# Add /usr/include/hdf5/serial to INCLUDE_DIRS.
sed -i "/INCLUDE_DIRS/s/$/ \/usr\/include\/hdf5\/serial/g" Makefile.config
# Replace hdf5 with hdf5_serial in linked libraries.
sed -i "s/hdf5/hdf5_serial/g" Makefile
# Add opencv_imgproc as a library dep.
sed -i "/opencv_imgproc/s/$/ opencv_imgcodecs/g" Makefile
}
function build_caffe() {
echo "Building caffe..."
if [ ! -e "caffe" ]; then
git clone "$CAFFE_REPO" caffe
fi
pushd caffe
git reset --hard 864520713a4c5ffae7382ced5d34e4cadc608473
git clean -f -
sudo pip3 install -r python/requirements.txt
cp Makefile.config.example Makefile.config
adjust_makefiles
# Finally, build the library with all processors.
# The computer will have all its resources hogged during this process.
make all
# Also build the python extensions.
make pycaffe
make distribute
popd
}
function install_caffe() {
echo "Installing caffe..."
pushd caffe
# Since no install target is provided, we have to copy the files manually.
sudo cp -r distribute/python/caffe/ /usr/local/lib/python3.6/dist-packages/
sudo cp build/lib/libcaffe.so* /usr/lib
popd
}
function main() {
# First, try to install it from the repo, since this is the easiest way.
sudo apt update
if sudo apt install -y python3-caffe-cpu caffe-cpu libcaffe-cpu1 libcaffe-cpu-dev ; then
exit 0
fi
pushd extern
install_system_deps
build_caffe
install_caffe
popd
}
main