forked from open-mmlab/OpenPCDet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_reptile.sh
161 lines (130 loc) · 6.29 KB
/
bash_reptile.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
#!/bin/bash
################################
# README
# This .sh file is to:
# 1. Convert raw data + labelCloud format -> OpenPCDet raw format for custom data
# 2. Reptile
# 3.1 Create reptile data
# 3.2 Convert reptile data from OpenPCDet raw format to KITTI
# 3.3 Train the model via reptile
################################
################################
# Setup anaconda3
# https://stackoverflow.com/a/70293309
################################
source ~/anaconda3/bin/activate
conda init bash
echo " "
conda activate openpcdet
################################
# hyperparameters
################################
MODEL='pointpillar'
NAME="custom"
LABEL_DIR="data_raw/techpartnerfile/techpartnerfile_label"
PLY_DIR="data_raw/techpartnerfile/preprocessed_techpartnerfile-ply"
NUM_TASK=4 # predefined reptile tasks
EPOCHS=100 # training epochs
BS=4 # batch size
EPSILON=0.01 # outer learning rate of reptile
OUTER_LOOP=1 # outer loop
INNER_LOOP=$NUM_TASK # inner loop = number of tasks
PC_MF=20 # magnifying factor (MF) to scale up point clouds
DXDY_MF=0.85 # magnifying factor (MF) to scale down dx dy dimension of labels
if [ $MODEL == "pointpillar" ]; then
CFG_FILE='tools/cfgs/custom_models/pointpillar.yaml'
PRETRAINED_MODEL='../output/pretrained/pretrained_pointpillar.pth'
elif [ $MODEL == "pointrcnn" ]; then
CFG_FILE='tools/cfgs/custom_models/pointrcnn.yaml'
PRETRAINED_MODEL='../output/pretrained/pretrained_pointrcnn.pth'
elif [ $MODEL == "pv_rcnn" ]; then
CFG_FILE='tools/cfgs/custom_models/pv_rcnn.yaml'
PRETRAINED_MODEL='../output/pretrained/pretrained_pv_rcnn.pth'
else
echo "model type not implemented, please check in hyperparameters"
exit 1
fi
################################
# remove previous models, just in case
################################
if [ -d "output/custom_models" ]; then
echo -e "Directory 'output/custom_models' exist!"
echo -e "Please rename or delete the directory, because the bash_reptile.sh need to occupy this folder."
exit 1
fi
################################
# Fix the label path name in the json label, in case multiple people did the labelling -> insonsistency in root directory
################################
python3 batch_fix_label.py --ply_dir $PLY_DIR --label_dir $LABEL_DIR || exit 1
################################
# Convert raw data + labelCloud format -> OpenPCDet raw format for custom data
################################
if [ -d "data/custom" ]; then
rm -r "data/custom"
fi
python convert_raw_data.py --name $NAME --dir $LABEL_DIR --cfg_file $CFG_FILE --pc_mf $PC_MF --dxdy_mf $DXDY_MF || exit 1
echo ""
################################
# Download pretrained models as starting weight for reptile
################################
if [ -d "output/pretrained" ]; then
echo -e "Pretrained models are downloaded previously\n"
else
if [ -d "output" ]; then
echo -e "Output directory exists\n"
else
mkdir 'output'
fi
mkdir 'output/pretrained'
cd output/pretrained
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1wMxWTpU1qUoY3DsCH31WJmvJxcjFXKlm' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1wMxWTpU1qUoY3DsCH31WJmvJxcjFXKlm" -O "pretrained_pointpillar.pth" && rm -rf /tmp/cookies.txt || exit 1
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1lIOq4Hxr0W3qsX83ilQv0nk1Cls6KAr-' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1lIOq4Hxr0W3qsX83ilQv0nk1Cls6KAr-" -O "pretrained_pv_rcnn.pth" && rm -rf /tmp/cookies.txt || exit 1
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1BCX9wMn-GYAfSOPpyxf6Iv6fc0qKLSiU' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1BCX9wMn-GYAfSOPpyxf6Iv6fc0qKLSiU" -O "pretrained_pointrcnn.pth" && rm -rf /tmp/cookies.txt || exit 1
cd ../../
fi
################################
# create reptile data
################################
python3 create_reptile_data.py --val-num 20 --upsample 6 || exit 1
################################
# reptile
################################
# loop outer loop
for i in $(seq 1 $OUTER_LOOP)
do
echo -e "###############################"
echo -e "outer loop $i"
echo -e "###############################"
# loop inner loop
all_model='' # for reptile
for j in $(seq 1 $NUM_TASK)
do
echo -e "inner loop (task) $i.$j"
# set training data
cd data/custom/ImageSets
mv "reptile_train_$j.txt" "train.txt"
cd ../../../
# Convert raw data OpenPCDet raw format for custom data -> some internal format
python -m pcdet.datasets.custom.custom_dataset create_custom_infos tools/cfgs/dataset_configs/custom_dataset.yaml || exit 1
# train
cd tools
python train.py --cfg_file cfgs/custom_models/pointpillar.yaml --batch_size $BS --workers 1 --epochs $EPOCHS --pretrained_model $PRETRAINED_MODEL || exit 1
cd ../
# rename output directory
mv "output/custom_models/pointpillar" "output/custom_models/pointpillar_$j"
# model to be reptile
all_model+=' '
all_model+="../output/custom_models/pointpillar_$j/default/ckpt/checkpoint_epoch_$EPOCHS.pth"
# reset training data
cd data/custom/ImageSets
mv "train.txt" "reptile_train_$j.txt"
cd ../../../
done
echo -e "###############################"
echo -e "Reptile now"
echo -e "###############################"
cd tools
python3 reptile.py --cfg_file cfgs/custom_models/pointpillar.yaml --ckpts $all_model --epoch_id $EPOCHS --pretrained_model $PRETRAINED_MODEL --epsilon $EPSILON || exit 1
cd ../
PRETRAINED_PATH='../output/custom_models/reptile.pth' # after reptile, we have the first reptile model
done