-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrostiniMLSetup
executable file
·291 lines (240 loc) · 8.95 KB
/
CrostiniMLSetup
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/usr/bin/env bash
##########################################################
# Disallow running with sudo or su
##########################################################
if [[ "$EUID" -eq 0 ]]
then printf "\033[1;101mPlease do not run this script as root (no su or sudo)! \033[0m \n";
exit;
fi
MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} == 'aarch64' ];
then printf "\033[1;101mThis application currently only supports x86_64 Chromebooks \033[0m \n";
exit;
fi
###############################################################
## HELPERS
###############################################################
title() {
printf "\033[1;42m";
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' ' ';
printf '%-*s\n' "${COLUMNS:-$(tput cols)}" " # $1" | tr ' ' ' ';
printf '%*s' "${COLUMNS:-$(tput cols)}" '' | tr ' ' ' ';
printf "\033[0m";
printf "\n\n";
}
breakLine() {
printf "\n";
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -;
printf "\n\n";
sleep .5;
}
notify() {
printf "\n";
printf "\033[1;46m $1 \033[0m \n";
}
curlToFile() {
notify "Downloading: $1 ----> $2";
sudo curl -fSL "$1" -o "$2";
}
###############################################################
## REGISTERED VARIABLES
###############################################################
installedTensorflow=0;
###############################################################
## INSTALLATION
###############################################################
#INSTALL MINICONDA WITH TENSORFLOW
installConda() {
title "Installing Conda with Tensorflow and Keras and PyTorch";
cd /tmp;
curl -O https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh;
bash Anaconda3-2019.10-Linux-x86_64.sh -b -u -p $HOME/miniconda;
rm Anaconda3-2019.10-Linux-x86_64.sh;
cd ~;
sudo apt install jupyter-core
~/miniconda/bin/conda install -y -c conda-forge tensorflow keras;
~/miniconda/bin/conda install -y pytorch-cpu torchvision-cpu -c pytorch
~/miniconda/bin/conda install -c conda-forge jupyterlab
~/miniconda/bin/conda config --set auto_activate_base false
~/miniconda/bin/conda create -y -n tensorflow_env tensorflow jupyter keras pytorch-cpu torchvision-cpu -c pytorch;
#conda config --set auto_activate_base true
~/miniconda/bin/conda init bash
echo "conda activate tensorflow_env" > StartTFenv.sh
chmod +x StartTFenv.sh
source ~/.bashrc;
}
installCondaCUDA() {
title "Installing Conda with Tensorflow-GPU and Keras and PyTorch";
cd /tmp;
curl -O https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh;
bash Anaconda3-2019.10-Linux-x86_64.sh -b -u -p $HOME/miniconda;
rm Anaconda3-2019.10-Linux-x86_64.sh;
cd ~;
sudo apt install jupyter-core
~/miniconda/bin/conda install -y -c conda-forge tensorflow keras;
~/miniconda/bin/conda install -y pytorch-cpu torchvision-cpu -c pytorch
~/miniconda/bin/conda install -c conda-forge jupyterlab
~/miniconda/bin/conda config --set auto_activate_base false
~/miniconda/bin/conda create -y -n tensorflow_env tensorflow-gpu jupyter keras pytorch-cpu torchvision-cpu -c pytorch;
#conda config --set auto_activate_base true
~/miniconda/bin/conda init bash
echo "conda activate tensorflow_env" > StartTFenv.sh
chmod +x StartTFenv.sh
source ~/.bashrc;
}
#INSTALL OPENCV
installOpenCV() {
title "Building and installing OpenCV";
OPENCV_VERSION='4.2.0'
# 2. INSTALL THE DEPENDENCIES
# Build tools:
sudo apt-get install -y build-essential cmake
sudo apt-get install -y libgtkglext1-dev libvtk6-dev
# Media I/O:
sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev
# Video I/O:
sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev
# Parallelism and linear algebra libraries:
sudo apt-get install -y libtbb-dev libeigen3-dev
# Python:
sudo apt-get install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy
# Java:
sudo apt-get install -y ant default-jdk
# Documentation:
sudo apt-get install -y doxygen
# 3. INSTALL THE LIBRARY
wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip
unzip ${OPENCV_VERSION}.zip
rm ${OPENCV_VERSION}.zip
mv opencv-${OPENCV_VERSION} OpenCV
cd OpenCV
mkdir build
cd build
cmake -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_XINE=ON DBUILD_EXAMPLES=ON -DENABLE_PRECOMPILED_HEADERS=OFF ..
make -j4
sudo make install
sudo ldconfig
}
installNCSudev() {
title "Setting udev Rules";
sudo apt-get -y install udev cpio;
sudo mkdir /etc/udev/rules.d/
cd ~/
cat <<EOF > 97-usbboot.rules
SUBSYSTEM=="usb", ATTRS{idProduct}=="2150", ATTRS{idVendor}=="03e7", GROUP="users", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"
SUBSYSTEM=="usb", ATTRS{idProduct}=="2485", ATTRS{idVendor}=="03e7", GROUP="users", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"
SUBSYSTEM=="usb", ATTRS{idProduct}=="f63b", ATTRS{idVendor}=="03e7", GROUP="users", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"
EOF
sudo cp 97-usbboot.rules /etc/udev/rules.d/
#sudo echo "ChromeOS" > /etc/lsb-release
sudo udevadm control --reload-rules
sudo udevadm trigger
sudo ldconfig
}
installCoralEdgeTPU() {
title "Setting up Coral Edge TPU ";
sudo rm -rf /etc/apt/sources.list.d/coral-edgetpu.*
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 8B57C5C2836F4BEB
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install libedgetpu1-std
}
installCoralEdgeTPUMAX() {
title "Setting up Coral Edge TPU Max ";
sudo rm -rf /etc/apt/sources.list.d/coral-edgetpu.*
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install libedgetpu1-max
}
installTFSampleCode(){
title "Writing Sample - Tensorflow Hello World ";
cd ~/
cat <<EOF > SampleTFHelloWorld.py
import tensorflow as tf
# Simple hello world using TensorFlow by Keith I Myers
# https://KMyers.me | Keith@KMyers.me
print(hwinfo)
hello = tf.constant('Hello World, from TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
hwinfo = tf.config.experimental.list_physical_devices(device_type=None)
EOF
}
###############################################################
## MAIN PROGRAM
###############################################################
sudo apt install -y dialog;
cmd=(dialog --backtitle "Crostini Machine Learning Setup Utility v00.1" \
--ascii-lines \
--clear \
--nocancel
--separate-output \
--checklist "Select installable packages:" 42 50 50);
options=(
01 "Install Conda with TensorFlow and Keras" on
02 "Install Conda with TensorFlow-GPU, CUDA and Keras(EXPERIMENTAL/Nvidia Only)" off
03 "Build and Install OpenCV" on
04 "Setup udev rules for Intel Movidius Neural Compute Stick 1/2" off
05 "Setup Google Coral Edge TPU (Experimental)" off
06 "Setup Google Coral Edge TPU High Powered Mode (Experimental)" off
07 "Create Tensorflow Hello Sample Script" on
);
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty);
#clear;
# Preparation
##########################################################
title "Installing Pre-Requisite Packages";
cd ~/;
sudo chown -R $(whoami) ~/
sudo apt update;
sudo apt dist-upgrade -y;
sudo apt autoremove -y --purge;
sudo apt install -y ca-certificates \
apt-transport-https \
software-properties-common \
wget \
git \
curl \
htop \
mlocate \
gnupg2 \
cmake \
libssh2-1-dev \
libssl-dev \
nano \
vim \
unzip;
sudo updatedb;
breakLine;
title "Updating apt";
sudo apt update;
notify "The apt package manager is fully updated...";
breakLine;
for choice in ${choices}
do
case ${choice} in
01) installConda ;;
02) installCondaCUDA ;;
03) installOpenCV ;;
04) installNCSudev ;;
05) installCoralEdgeTPU ;;
06) installCoralEdgeTPUMAX ;;
07) installTFSampleCode ;;
esac
done
# Clean
##########################################################
title "Finalising & Cleaning Up...";
sudo chown -R $(whoami) ~/;
sudo apt --fix-broken install -y;
sudo apt dist-upgrade -y;
sudo apt autoremove -y --purge;
breakLine;
notify "Installation Complete";
###############################################################
## POST INSTALLATION ACTIONS
###############################################################
xdg-open 'https://kmyers.me/help/chromeos-crostini-ml/'
echo "";