-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
219 lines (186 loc) · 10.2 KB
/
install.sh
File metadata and controls
219 lines (186 loc) · 10.2 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
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
#!/bin/bash
# Development mode setup script ::::::::::::::::::::::::::::::::::::::::::::::
#
# Object Detection (YOLOv8)
#
# This script is called from the ObjectDetectionYOLOv8 directory using:
#
# bash ../../CodeProject.AI-Server/src/setup.sh
#
# The setup.sh script will find this install.sh file and execute it.
#
# For help with install scripts, notes on variables and methods available, tips,
# and explanations, see /src/modules/install_script_help.md
if [ "$1" != "install" ]; then
read -t 3 -p "This script is only called from: bash ../../CodeProject.AI-Server/src/setup.sh"
echo
exit 1
fi
# For Jetson, we need to install Torch before the other packages.
# A huge thanks to QEngineering: https://qengineering.eu/install-pytorch-on-jetson-nano.html
if [ "$moduleInstallErrors" = "" ] && [ "$edgeDevice" = "Jetson" ]; then
# NOTE: Pytorch 2.0 and above uses CUDA 11. The Jetson Nano has CUDA 10.2.
# Due to low-level GPU incompatibility, installing CUDA 11 on your Nano is
# impossible. Pytorch 2.0 can only be installed on Jetson family members using
# a JetPack 5.0 or higher, such as the Jetson Nano Orion. Unfortunately, it
# doesn't appear that this version will be available for the Jetson Nano soon.
# Dependencies (Libraries)
installAptPackages "python3-pip libjpeg-dev libopenblas-dev libopenmpi-dev libomp-dev zlib1g-dev"
# Dependencies (Python packages). Above setuptools 58.3.0 you get version issues
installPythonPackagesByName "future wheel mock testresources setuptools==58.3.0 Cython"
# Ultralytics will install everything. Usually. Sometimes...
install_torch=true
use_NVIDIA=true
if [ "$use_NVIDIA" == true ]; then
torch_version="1.11"
torchvision_version="0.12"
else
distribution=$(. /etc/os-release;echo $VERSION_ID)
if [ "$pythonVersion" == "3.6" ] || [ "$pythonVersion" == "3.7" ] || [ "$distribution" == "18.04" ]; then
torch_version="1.10"
torchvision_version="0.11"
else
torch_version="1.13"
torchvision_version="0.14"
fi
fi
if [ "$install_torch" = true ]; then
if [ "$use_NVIDIA" == true ]; then
# ------------------------------------------------------------------
# NVIDIA versions:
if [ "$torch_version" == "1.10" ]; then
# Torch 1.10: Ubuntu 18.04+ / Python 3.6
torch_location="https://nvidia.box.com/shared/static/fjtbno0vpo676a25cgvuqc1wty0fkkg6.whl"
torch_wheel="torch-1.10.0-cp36-cp36m-linux_aarch64.whl"
torch_vision="torchvision==0.11.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html"
else
# Torch 1.11: Ubuntu 18.04+ / Python 3.6
torch_location="https://developer.download.nvidia.com/compute/redist/jp/v461/pytorch/torch-1.11.0a0+17540c5+nv22.01-cp36-cp36m-linux_aarch64.whl"
torch_wheel="torch-1.11.0a0+17540c5+nv22.01-cp36-cp36m-linux_aarch64.whl"
torch_vision="torchvision==0.12.0+cu102 --extra-index-url https://download.pytorch.org/whl/cu102"
fi
else
# ------------------------------------------------------------------
# QEngineering versions (https://qengineering.eu/install-pytorch-on-jetson-nano.html)
if [ "$torch_version" == "1.10" ]; then
# Torch 1.10: Ubuntu 18.04+ / Python 3.6
torch_location="https://drive.google.com/uc?id=1TqC6_2cwqiYacjoLhLgrZoap6-sVL2sd"
torch_wheel="torch-1.10.0a0+git36449ea-cp36-cp36m-linux_aarch64.whl"
torchvision_location="https://drive.google.com/uc?id=1C7y6VSIBkmL2RQnVy8xF9cAnrrpJiJ-K"
torchvision_wheel="torchvision-0.11.0a0+fa347eb-cp36-cp36m-linux_aarch64.whl"
elif [ "$torch_version" == "1.11" ]; then
# Torch 1.11: Needs Ubuntu 20.04 / Python 3.8
torch_location="https://drive.google.com/uc?id=1AQQuBS9skNk1mgZXMp0FmTIwjuxc81WY"
torch_wheel="torch-1.11.0a0+gitbc2c6ed-cp38-cp38-linux_aarch64.whl"
torchvision_location="https://drive.google.com/uc?id=1BaBhpAizP33SV_34-l3es9MOEFhhS1i2"
torchvision_wheel="torchvision-0.12.0a0+9b5a3fe-cp38-cp38-linux_aarch64.whl"
elif [ "$torch_version" == "1.12" ]; then
# Torch 1.12: Needs Ubuntu 20.04 / Python 3.8
torch_location="https://drive.google.com/uc?id=1MnVB7I4N8iVDAkogJO76CiQ2KRbyXH_e"
torch_wheel="torch-1.12.0a0+git67ece03-cp38-cp38-linux_aarch64.whl"
torchvision_location="https://drive.google.com/uc?id=11DPKcWzLjZa5kRXRodRJ3t9md0EMydhj"
torchvision_wheel="torchvision-0.13.0a0+da3794e-cp38-cp38-linux_aarch64.whl"
elif [ "$torch_version" == "1.13" ]; then
# Torch 1.13: Needs Ubuntu 20.04 / Python 3.8
torch_location="https://drive.google.com/uc?id=1e9FDGt2zGS5C5Pms7wzHYRb0HuupngK1"
torch_wheel="torch-1.13.0a0+git7c98e70-cp38-cp38-linux_aarch64.whl"
torchvision_location="https://drive.google.com/uc?id=19UbYsKHhKnyeJ12VPUwcSvoxJaX7jQZ2"
torchvision_wheel="torchvision-0.14.0a0+5ce4506-cp38-cp38-linux_aarch64.whl"
fi
fi
"$venvPythonCmdPath" -m pip show torch >/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
writeLine "Torch aleady installed" $color_info
else
if [ ! -f "${downloadDirPath}/${platform_dir}/packages/${torch_wheel}" ]; then
if [ ! -d "${downloadDirPath}/${platform_dir}/packages" ]; then
mkdir -p "${downloadDirPath}/${platform_dir}/packages"
fi
if [ "$use_NVIDIA" == true ]; then
wget $torch_location -O "${downloadDirPath}/${platform_dir}/packages/${torch_wheel}"
else
gdown $torch_location
mv -f $torch_wheel "${downloadDirPath}/${platform_dir}/packages/"
fi
fi
# install PyTorch
cp "${downloadDirPath}/${platform_dir}/packages/${torch_wheel}" .
installPythonPackagesByName "${torch_wheel}" "PyTorch"
rm "${torch_wheel}"
fi
"$venvPythonCmdPath" -m pip show torchvision >/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
writeLine "TorchVision aleady installed" $color_info
else
# install TorchVision
if [ "$use_NVIDIA" == true ]; then
installPythonPackagesByName "${torch_vision}" "TorchVision"
else
if [ ! -f "${downloadDirPath}/${platform_dir}/packages/${torchvision_wheel}" ]; then
if [ ! -d "${downloadDirPath}/${platform_dir}/packages" ]; then
mkdir -p "${downloadDirPath}/${platform_dir}/packages"
fi
gdown $torchvision_location
mv -f $torchvision_wheel "${downloadDirPath}/${platform_dir}/packages/"
fi
cp "${downloadDirPath}/${platform_dir}/packages/${torchvision_wheel}" .
installPythonPackagesByName "${torchvision_wheel}" "TorchVision"
rm "${torchvision_wheel}"
fi
# If we wish to build from source:
if [ "$build_torchvision_from_source" == true ]; then
installAptPackages "gcc python${pythonVersion}-dev"
# Except git is occasionally broken on Jetson
# mkdir torchvision && cd torchvision
# git clone https://github.com/pytorch/vision .
# git checkout v${torchvision_version}.0
getFromServer "libraries/" "torchvision-${torchvision_version}.0.zip" "torchvision" "Downloading TorchVision to ${moduleDirPath}"
pushd "${moduleDirPath}/torchvision"
"$venvPythonCmdPath" setup.py install --user
popd
fi
fi
# This is a hammer that's sometimes needed to allow the ultralytics package to be installed
sudo apt-get install python${pythonVersion}-dev -y
# NEXT STEP: Use TensorRT to Improve Inference Speed
# https://wiki.seeedstudio.com/YOLOv8-TRT-Jetson/#use-tensorrt-to-improve-inference-speed
getFromServer "libraries/" "ultralytics-8.0.225.zip" "ultralytics" "Downloading Ultralytics..."
fi
fi
# OpenCV needs a specific version for macOS 11
# https://github.com/opencv/opencv-python/issues/777#issuecomment-1879553756
if [ "$os_name" = "Big Sur" ]; then # macOS 11.x on Intel, kernal 20.x
installPythonPackagesByName "opencv-python==4.6.0.66" "OpenCV 4.6.0.66 for macOS 11.x"
fi
# Install drivers for non Docker images
if [ "$moduleInstallErrors" = "" ] && [ "$inDocker" != true ] && [ "$os" = "linux" ] ; then
echo
# ROCm needed for linux
# if [ "$hasROCm" = true ]; then
# writeLine 'Installing ROCm driver scripts...'
# sudo apt-get update
# #Ubuntu v20.04
# #wget https://repo.radeon.com/amdgpu-install/5.4.2/ubuntu/focal/amdgpu-install_5.4.50402-1_all.deb
#
# #Ubuntu v22.04
# wget https://repo.radeon.com/amdgpu-install/5.4.2/ubuntu/jammy/amdgpu-install_5.4.50402-1_all.deb
#
# sudo apt-get install ./amdgpu-install_5.4.50402-1_all.deb
# spin $!
# writeLine "done" "$color_success"
#
# writeLine 'Installing ROCm drivers...'
# sudo amdgpu-install --usecase=dkms,graphics,multimedia,opencl,hip,hiplibsdk,rocm
# spin $!
# writeLine "done" "$color_success"
# fi
fi
# Download the models and store in /assets and /custom-models (already in place in docker)
# if [ "$moduleInstallErrors" = "" ]; then
# getFromServer "models/" "models-yolo8-pt.zip" "assets" "Downloading YOLO object detection models..."
# getFromServer "models/" "objectsegmentation-coco-yolov8-pt-m.zip" "assets" "Downloading YOLO segmentation models..."
#
# getFromServer "models/" "objectdetection-custom-yolov8-pt-m.zip" "custom-models" "Downloading Custom YOLO models..."
# fi
# TODO: Check assets created and has files
# moduleInstallErrors=...