|
a |
|
b/utils/aws/userdata.sh |
|
|
1 |
#!/bin/bash |
|
|
2 |
# AWS EC2 instance startup script https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html |
|
|
3 |
# This script will run only once on first instance start (for a re-start script see mime.sh) |
|
|
4 |
# /home/ubuntu (ubuntu) or /home/ec2-user (amazon-linux) is working dir |
|
|
5 |
# Use >300 GB SSD |
|
|
6 |
|
|
|
7 |
cd home/ubuntu |
|
|
8 |
if [ ! -d yolov5 ]; then |
|
|
9 |
echo "Running first-time script." # install dependencies, download COCO, pull Docker |
|
|
10 |
git clone https://github.com/ultralytics/yolov5 -b master && sudo chmod -R 777 yolov5 |
|
|
11 |
cd yolov5 |
|
|
12 |
bash data/scripts/get_coco.sh && echo "COCO done." & |
|
|
13 |
sudo docker pull ultralytics/yolov5:latest && echo "Docker done." & |
|
|
14 |
python -m pip install --upgrade pip && pip install -r requirements.txt && python detect.py && echo "Requirements done." & |
|
|
15 |
wait && echo "All tasks done." # finish background tasks |
|
|
16 |
else |
|
|
17 |
echo "Running re-start script." # resume interrupted runs |
|
|
18 |
i=0 |
|
|
19 |
list=$(sudo docker ps -qa) # container list i.e. $'one\ntwo\nthree\nfour' |
|
|
20 |
while IFS= read -r id; do |
|
|
21 |
((i++)) |
|
|
22 |
echo "restarting container $i: $id" |
|
|
23 |
sudo docker start $id |
|
|
24 |
# sudo docker exec -it $id python train.py --resume # single-GPU |
|
|
25 |
sudo docker exec -d $id python utils/aws/resume.py # multi-scenario |
|
|
26 |
done <<<"$list" |
|
|
27 |
fi |