forked from dusty-nv/jetson-inference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·174 lines (153 loc) · 5.63 KB
/
run.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env bash
#
# Start an instance of the jetson-inference docker container.
# See below or run this script with -h or --help to see usage options.
#
# This script should be run from the root dir of the jetson-inference project:
#
# $ cd /path/to/your/jetson-inference
# $ docker/run.sh
#
show_help() {
echo " "
echo "usage: Starts the Docker container and runs a user-specified command"
echo " "
echo " ./docker/run.sh --container DOCKER_IMAGE"
echo " --volume HOST_DIR:MOUNT_DIR"
echo " --run RUN_COMMAND"
echo " "
echo "args:"
echo " "
echo " --help Show this help text and quit"
echo " "
echo " -c, --container DOCKER_IMAGE Specifies the name of the Docker container"
echo " image to use (default: 'nvidia-l4t-base')"
echo " "
echo " -v, --volume HOST_DIR:MOUNT_DIR Mount a path from the host system into"
echo " the container. Should be specified as:"
echo " "
echo " -v /my/host/path:/my/container/path"
echo " "
echo " (these should be absolute paths)"
echo " "
echo " -r, --run RUN_COMMAND Command to run once the container is started."
echo " Note that this argument must be invoked last,"
echo " as all further arguments will form the command."
echo " If no run command is specified, an interactive"
echo " terminal into the container will be provided."
echo " "
}
die() {
printf '%s\n' "$1"
show_help
exit 1
}
# find container tag from L4T version
source docker/tag.sh
# paths to some project directories
NETWORKS_DIR="data/networks"
CLASSIFY_DIR="python/training/classification"
DETECTION_DIR="python/training/detection/ssd"
DOCKER_ROOT="/jetson-inference" # where the project resides inside docker
# check if we need to download models
SIZE_MODELS=$(du -sb $NETWORKS_DIR | cut -f 1)
echo "size of $NETWORKS_DIR: $SIZE_MODELS bytes"
if [[ $SIZE_MODELS -lt 204800 ]]; then # some text files come with the repo (~78KB), so check for a bit more than that
sudo apt-get update
sudo apt-get install dialog
echo "Models have not yet been downloaded, running model downloader tool now..."
cd tools
./download-models.sh
cd ../
fi
# check for pytorch-ssd base model
SSD_BASE_MODEL="$DETECTION_DIR/models/mobilenet-v1-ssd-mp-0_675.pth"
if [ ! -f "$SSD_BASE_MODEL" ]; then
echo "Downloading pytorch-ssd base model..."
wget --quiet --show-progress --progress=bar:force:noscroll --no-check-certificate https://nvidia.box.com/shared/static/djf5w54rjvpqocsiztzaandq1m3avr7c.pth -O $SSD_BASE_MODEL
fi
# generate mount commands
DATA_VOLUME="\
--volume $PWD/data:$DOCKER_ROOT/data \
--volume $PWD/$CLASSIFY_DIR/data:$DOCKER_ROOT/$CLASSIFY_DIR/data \
--volume $PWD/$CLASSIFY_DIR/models:$DOCKER_ROOT/$CLASSIFY_DIR/models \
--volume $PWD/$DETECTION_DIR/data:$DOCKER_ROOT/$DETECTION_DIR/data \
--volume $PWD/$DETECTION_DIR/models:$DOCKER_ROOT/$DETECTION_DIR/models"
# parse user arguments
USER_VOLUME=""
USER_COMMAND=""
while :; do
case $1 in
-h|-\?|--help)
show_help # Display a usage synopsis.
exit
;;
-c|--container) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
CONTAINER_IMAGE=$2
shift
else
die 'ERROR: "--container" requires a non-empty option argument.'
fi
;;
--container=?*)
CONTAINER_IMAGE=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--container=) # Handle the case of an empty --image=
die 'ERROR: "--container" requires a non-empty option argument.'
;;
-v|--volume)
if [ "$2" ]; then
USER_VOLUME=" -v $2 "
shift
else
die 'ERROR: "--volume" requires a non-empty option argument.'
fi
;;
--volume=?*)
USER_VOLUME=" -v ${1#*=} " # Delete everything up to "=" and assign the remainder.
;;
--volume=) # Handle the case of an empty --image=
die 'ERROR: "--volume" requires a non-empty option argument.'
;;
-r|--run)
if [ "$2" ]; then
shift
USER_COMMAND=" $@ "
else
die 'ERROR: "--run" requires a non-empty option argument.'
fi
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
echo "CONTAINER: $CONTAINER_IMAGE"
echo "DATA_VOLUME: $DATA_VOLUME"
echo "USER_VOLUME: $USER_VOLUME"
echo "USER_COMMAND: $USER_COMMAND"
# check for V4L2 devices
V4L2_DEVICES=" "
for i in {0..9}
do
if [ -a "/dev/video$i" ]; then
V4L2_DEVICES="$V4L2_DEVICES --device /dev/video$i "
fi
done
echo "V4L2_DEVICES: $V4L2_DEVICES"
# run the container
sudo xhost +si:localuser:root
sudo docker run --runtime nvidia -it --rm --network host -e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix/:/tmp/.X11-unix \
-v /tmp/argus_socket:/tmp/argus_socket \
-v /etc/enctune.conf:/etc/enctune.conf \
$V4L2_DEVICES $DATA_VOLUME $USER_VOLUME \
$CONTAINER_IMAGE $USER_COMMAND