-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
executable file
·152 lines (137 loc) · 3.6 KB
/
install.sh
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash -e
J="-j2"
if [[ -z $CI ]]; then
J="-j6"
fi
# Install and build OpenCV from source
function install_opencv {
git clone --branch '3.3.0' git@github.com:Itseez/opencv.git
pushd opencv
mkdir build && cd build
cmake -Wno-dev \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTS=false \
-DWITH_TIFF=false \
-DWITH_CUDA=false \
-DBUILD_ANDROID_EXAMPLES=false \
-DWITH_OPENEXR=false \
-DBUILD_PERF_TESTS=false \
-DBUILD_opencv_java=false \
-DWITH_IPP=ON \
-DCMAKE_INSTALL_PREFIX=/usr/local/ \
..
make -j4
popd
}
function install_package_osx {
local problem
problem=$(brew ls --versions $1 | grep $1 || true)
echo Checking for $1: $problem
if [ "" == "$problem" ]; then
echo "Not $1 found; setting it up"
set -x
brew install -vd $1
fi
}
function install_package_linux {
local problem
problem=$(dpkg -s $1 | grep installed || true)
echo Checking for $1: $problem
if [ "" == "$problem" ]; then
echo "Not $1 found; setting it up"
set -x
sudo apt-get --force-yes --yes install $1
fi
}
function install_dependencies {
if [[ "$(uname)" == "Darwin" ]]; then
(
install_package_osx snappy
install_package_osx gflags
install_package_osx szip
install_package_osx libtool
install_package_osx protobuf
install_package_osx glog
install_package_osx hdf5
install_package_osx openblas
brew link --force --overwrite openblas
install_package_osx boost
install_package_osx webp # OpenCV3 wants libwebp
)
elif [[ "$(uname)" == "Linux" ]]; then
install_package_linux libsnappy-dev
install_package_linux libatlas-base-dev
install_package_linux libboost-all-dev
install_package_linux libgflags-dev
install_package_linux libprotobuf-dev
install_package_linux protobuf-compiler
install_package_linux libgoogle-glog-dev
install_package_linux libhdf5-serial-dev
fi
# Install OpenCV from source as opencv PPA on Linux doesn't seem to have
# IPP libraries that caffe needs and on OSX the default headers have issues
# with FaceRecognizer class
if [[ ! -d "opencv" ]]; then
echo "Building OpenCV"
install_opencv
fi
}
# Install and build Caffe
if [ -z "$CAFFE_ROOT" ]; then
pushd $(dirname $0)
echo "Installing dependencies"
install_dependencies
# Download caffe
SHA=24d2f67173db3344141dce24b1008efffbfe1c7d
if [[ ! -d caffe ]]; then
echo Downloading caffe
git clone git@github.com:BVLC/caffe.git
git -C caffe checkout $SHA
pushd caffe
git am ../patch/0001-Fix-veclib-path-for-OSX-sierra.patch
popd
fi
# Check for NVIDIA GPU. If NVIDIA GPU is unavailable
# `nvidia-smi` command returns with an empty string.
# Given that scenario revert back to CPU mode, else
# compile with GPU support
if which nvidia-smi; then
hasGPU=true
else
hasGPU=false
fi
# Install caffe
if [[ ! -f caffe/build/lib/libcaffe.dylib && ! -f caffe/build/lib/libcaffe.so ]]; then
echo "Compiling caffe"
pushd caffe
mkdir -p build
pushd build
# Enable CPU/GPU
if $hasGPU; then
cpu_mode=OFF
cudnn_mode=ON
else
cpu_mode=ON
cudnn_mode=OFF
fi
cmake \
-DCPU_ONLY=$cpu_mode \
-DUSE_CUDNN=$cudnn_mode \
-DBUILD_python=OFF \
-DBUILD_matlab=OFF \
-DUSE_LEVELDB=OFF \
-DUSE_LMDB=OFF \
-DBUILD_docs=OFF \
-DOpenCV_DIR=$(pwd)/../../opencv/build \
..
make all $J
popd
popd
popd
else
echo "Caffe already compiled; skipping compilation"
fi
else
echo "Using caffe from $CAFFE_ROOT"
fi
JOBS=max npm run rebuild