-
Notifications
You must be signed in to change notification settings - Fork 20
/
run_demo.sh
55 lines (51 loc) · 1.61 KB
/
run_demo.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
#!/bin/bash
# command input (video file)
VIDEO_PATH=$1
GPUS=0
VIDEO_FILENAME="${VIDEO_PATH##*/}" # ./demo/000821.mp4
DIR="${VIDEO_PATH%/*}" # ./demo
VID="${VIDEO_FILENAME%.*}" # 000821
FEAT_FILE="$DIR/$VID"_feature.npz
RESULT_FILE="$DIR/$VID"_result.npz
VIS_FILE="$DIR/$VID"_vis.avi
if [ ! -f "$RESULT_FILE" ]; then
if [ ! -f "$FEAT_FILE" ]; then
# feature extraction task
echo "Run feature extraction..."
# source ~/anaconda3/etc/profile.d/conda.sh
conda activate mmlab
CUDA_VISIBLE_DEVICES=$GPUS python demo.py \
--video_file $VIDEO_PATH \
--task extract_feature \
--gpu_id $GPUS \
--mmdetection lib/mmdetection
# exit current virtual environment
# source ~/anaconda3/etc/profile.d/conda.sh
conda deactivate
echo "Saved in: $FEAT_FILE"
fi
# run inference
echo "Run accident inference..."
# source ~/anaconda3/etc/profile.d/conda.sh
conda activate py37
CUDA_VISIBLE_DEVICES=$GPUS python demo.py \
--task inference \
--feature_file $FEAT_FILE \
--ckpt_file demo/final_model_ccd.pth \
--gpu_id $GPUS
# source ~/anaconda3/etc/profile.d/conda.sh
conda deactivate
echo "Saved in: $RESULT_FILE"
fi
# visualize
echo "Run result visualization..."
# source ~/anaconda3/etc/profile.d/conda.sh
conda activate py37
CUDA_VISIBLE_DEVICES=$GPUS python demo.py \
--task visualize \
--video_file $VIDEO_PATH \
--result_file $RESULT_FILE \
--vis_file $VIS_FILE
# source ~/anaconda3/etc/profile.d/conda.sh
conda deactivate
echo "Saved in: $VIS_FILE"