Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 277 lines (248 sloc) 8.12 KB
#!/bin/bash
#
# Copyright 2017 DT42
#
# This file is part of BerryNet.
#
# BerryNet is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BerryNet is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BerryNet. If not, see <http://www.gnu.org/licenses/>.
# One-click IoT gateway deployment script.
set -e
LOG="$PWD/berrynet.log"
DISTRIBUTIONID=`lsb_release -i -s`
INSTALL_CAFFE2="N"
INSTALL_DARKFLOW="N"
INSTALL_DARKNET="Y"
INSTALL_TENSORFLOW="N"
install_system_dependencies() {
sudo apt-get update
sudo apt-get install -y \
curl \
fswebcam \
git \
imagemagick \
libkrb5-dev \
libopencv-dev \
libyaml-dev \
libzmq3-dev \
lsb-release \
mongodb \
mosquitto-clients \
python-dev \
python-pip \
wget
sudo service mongodb start
sudo -H pip install \
cython \
watchdog
}
install_berrynet_repository() {
sudo apt-get update
sudo apt-get install -y dirmngr
sudo cp config/berrynet.list /etc/apt/sources.list.d
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv C0C4CC4C
sudo apt update
}
install_nodejs() {
# v8.x is LTS, if you want the latest feature, change to "setup_11.x".
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
}
install_tensorflow() {
if [ x"$DISTRIBUTIONID" = x"Ubuntu" ]; then
sudo -H pip install tensorflow
elif [ x"$DISTRIBUTIONID" = x"Raspbian" ]; then
TENSORFLOW_VERSION="1.0.1"
TENSORFLOW_PKGNAME="tensorflow-${TENSORFLOW_VERSION}-cp27-none-linux_armv7l.whl"
if [ ! -e "$TENSORFLOW_PKGNAME" ]; then
wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v${TENSORFLOW_VERSION}/$TENSORFLOW_PKGNAME
else
echo "$TENSORFLOW_PKGNAME has existed, skip to download it."
fi
sudo -H pip install $TENSORFLOW_PKGNAME
fi
}
# TODO: Retire Darkflow
#install_darkflow() {
# git submodule init
# git submodule update
#
# # build cython-implemented library
# pushd inference/darkflow > /dev/null
# python setup.py build_ext --inplace
# # add color index in the inference result for drawing bounding boxes
# patch -p 1 < ../../patch/darkflow/darkflow-app-example.patch
# cp ../detection_server.py .
# # install darkflow system-wide
# sudo pip install .
#
# popd > /dev/null
#}
install_darknet_nnpack() {
# To understand how these packages are built, please refer to
# https://github.com/DT42/BerryNet/blob/master/doc/darknet-nnpack.md
sudo apt install -y darknet libdarknet
}
install_darknet() {
local peachpy_version="0.0.1"
local confu_version="cc90068"
local ninja_version="v1.8.2"
local nnpack_darknet_version="1ecda10"
local darknet_nnpack_version="fa5bddc"
# build dependencies
pip install --user PeachPy==$peachpy_version
pip install --user git+https://github.com/Maratyszcza/confu@$confu_version
pushd /tmp > /dev/null
git clone https://github.com/ninja-build/ninja.git
pushd ninja > /dev/null
git reset --hard $ninja_version
./configure.py --bootstrap
popd > /dev/null
popd > /dev/null
sudo apt-get install -y clang
pushd /tmp > /dev/null
git clone https://github.com/thomaspark-pkj/NNPACK-darknet.git
pushd NNPACK-darknet > /dev/null
git reset --hard $nnpack_darknet_version
$HOME/.local/bin/confu setup
python ./configure.py --backend auto
/tmp/ninja/ninja
sudo cp lib/{libgoogletest-core.a,libnnpack.a,libpthreadpool.a} /usr/lib/
sudo cp include/nnpack.h /usr/include/
sudo cp deps/pthreadpool/include/pthreadpool.h /usr/include/
popd > /dev/null
popd > /dev/null
# build detection backend (darknet)
pushd inference > /dev/null
git clone https://github.com/thomaspark-pkj/darknet-nnpack.git darknet
pushd darknet > /dev/null
git reset --hard $darknet_nnpack_version
patch -p 1 < ../../patch/01-detection-backend.patch
make -j
popd > /dev/null
popd > /dev/null
cp utils/darknet/detectord.py inference/darknet
mkdir inference/darknet/utils
cp utils/darknet/utils/localrun.sh inference/darknet/utils
}
download_classifier_model() {
# Inception v3 is default classifier model
INCEPTION_PKGNAME=inception_dec_2015.zip
pushd inference > /dev/null
mkdir -p image
if [ ! -e model ]; then
mkdir model
pushd model > /dev/null
wget https://storage.googleapis.com/download.tensorflow.org/models/$INCEPTION_PKGNAME
unzip $INCEPTION_PKGNAME
mv imagenet_comp_graph_label_strings.txt output_labels.txt
mv tensorflow_inception_graph.pb output_graph.pb
popd > /dev/null
fi
popd > /dev/null
}
download_detector_model() {
pushd inference/darkflow > /dev/null
mkdir bin
popd > /dev/null
wget -O /tmp/tinyyolo_20170816_all.deb https://s3.amazonaws.com/berrynet/models/tinyyolo/tinyyolo_20170816_all.deb
sudo dpkg -i /tmp/tinyyolo_20170816_all.deb
}
install_dashboard() {
local dashboard_version="8f24074"
if [ ! -e "dashboard" ]; then
git clone https://github.com/v-i-s-h/PiIoT-dashboard.git dashboard
pushd dashboard > /dev/null
git reset --hard $dashboard_version
patch -p 1 < ../patch/ui-dt42-theme.patch
cp ../patch/www/freeboard/img/dt42-logo.png www/freeboard/img
cp ../patch/www/freeboard/css/dt42.css www/freeboard/css
cp ../config/dashboard.json www/freeboard/
popd > /dev/null
fi
}
install_systemd_configs() {
sudo cp systemd/* /etc/systemd/system
sudo cp config/bcm2835-v4l2.conf /etc/modules-load.d
# enable ramfs to speedup I/O
echo -e "tmpfs /var/ramfs tmpfs nodev,nosuid,size=50M 0 0" \
| sudo tee -a /etc/fstab
sudo mount -a
}
install_gateway() {
local working_dir="/usr/local/berrynet"
sudo mkdir -p $working_dir
sudo cp -a \
broker.js \
camera.js \
config.js \
dashboard \
data_collector.js \
inference \
journal.js \
localimg.js \
mail.js \
line.js \
package.json \
$working_dir
sudo cp berrynet-manager /usr/local/bin
# FIXME: image dir should be created by program
mkdir -p /usr/local/berrynet/inference/image
# install npm dependencies
pushd $working_dir > /dev/null
sudo npm install --unsafe-perm
popd > /dev/null
}
install_caffe2() {
if [ x"$DISTRIBUTIONID" = x"Ubuntu" ]; then
sh ./utils/install-caffe2-ubuntu.sh
elif [ x"$DISTRIBUTIONID" = x"Raspbian" ]; then
sh ./utils/install-caffe2-raspbian.sh
fi
}
download_classifier_model_caffe2() {
sh ./utils/install-caffe2-models.sh
}
install_system_dependencies 2>&1 | tee -a $LOG
install_berrynet_repository 2>&1 | tee -a $LOG
install_nodejs 2>&1 | tee -a $LOG
#install_darknet 2>&1 | tee -a $LOG
install_darknet_nnpack 2>&1 | tee -a $LOG
download_detector_model 2>&1 | tee -a $LOG
install_dashboard 2>&1 | tee -a $LOG
install_systemd_configs 2>&1 | tee -a $LOG
install_gateway 2>&1 | tee -a $LOG
if [ "$INSTALL_TENSORFLOW" = "Y" ]; then
install_tensorflow 2>&1 | tee -a $LOG
download_classifier_model 2>&1 | tee -a $LOG
else
echo "Not install TensorFlow" >> $LOG
fi
if [ "$INSTALL_DARKFLOW" = "Y" ]; then
install_darkflow 2>&1 | tee -a $LOG
else
echo "Not install Darkflow" >> $LOG
fi
if [ "$INSTALL_CAFFE2" = "Y" ]; then
install_caffe2 2>&1 | tee -a $LOG
download_classifier_model_caffe2 2>&1 | tee -a $LOG
else
echo "Not install Caffe2" >> $LOG
fi
{
echo "Installation is completed successfully!"
echo ""
echo "Please send $LOG and /usr/local/berrynet/npm-debug.log"
echo "to https://groups.google.com/a/dt42.io/d/forum/berrynet"
echo "if there is any issue."
} | tee -a $LOG