-
Notifications
You must be signed in to change notification settings - Fork 28
/
finetune.sh
executable file
·169 lines (153 loc) · 9.07 KB
/
finetune.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
#!/bin/sh
# Suggested commands:
# export CUDA_VISIBLE_DEVICES="0" && ./finetune.sh -f -e -s -t row
# export CUDA_VISIBLE_DEVICES="0" && ./finetune.sh -f -e -s -t stack
# export CUDA_VISIBLE_DEVICES="0" && ./finetune.sh -f -e -s -t unstack
# export CUDA_VISIBLE_DEVICES="0" && ./finetune.sh -f -e -s -t vertical_square
# don't finetune by default (assume it hasn't been done)
finetune=0;
embed=0;
ssr=0;
task="";
gr_baseline=0;
# make sure script will print where it is and exit on errors
set -e
set -u
set -x
# help function
Help()
{
# Display Help
echo "Syntax: ./finetune.sh [-f|g|t|e|s|h]"
echo ""
echo "options:"
echo "-f Finetune policies from base_models. Other options will break if this hasn't been run at least once."
echo "-t Which task? [row|stack|unstack|vertical_square]"
echo "-e Precompute demo embeddings. If you do not already have embed.pickle files in the demo folders, this is highly recommended."
echo "-s Run SSR Simulation Experiments."
echo "-h Print help menu."
echo
echo "Suggested commands:"
echo " export CUDA_VISIBLE_DEVICES=\"0\" && ./finetune.sh -f -e -s -t row"
echo " export CUDA_VISIBLE_DEVICES=\"0\" && ./finetune.sh -f -e -s -t stack"
echo " export CUDA_VISIBLE_DEVICES=\"0\" && ./finetune.sh -f -e -s -t unstack"
echo " export CUDA_VISIBLE_DEVICES=\"0\" && ./finetune.sh -f -e -s -t vertical_square"
echo
echo "Note that running without any of the options set will result in no action."
}
# get cmd line options
while getopts "t:fgesh" flag
do
case $flag in
f) # run finetuning?
finetune=1;;
g) # good robot finetuned baseline?
gr_baseline=1;;
t) # which task?
task=${OPTARG};;
e) # compute embeddings?
embed=1;;
s) # run ssr?
ssr=1;;
h) # help
Help
exit;;
\?) # Invalid option
echo "Error: Invalid option"
exit;;
esac
done
if [ $finetune -eq 1 ]
then
echo "Running Finetuning..."
if [ "$task" = "row" ]
then
# row finetunes
python3 train_offline.py -m logs/base_models/stacking_hist_densenet/snapshot.reinforcement_action_efficiency_best_value.pth -d demos/row_demos/ -t row -o logs/finetuned_models/ --trial_reward
python3 train_offline.py -m logs/base_models/unstacking_hist_densenet/snapshot.reinforcement_action_efficiency_best_value.pth -d demos/row_demos/ -t row -o logs/finetuned_models/
python3 train_offline.py -m logs/base_models/vertical_square_hist_densenet/snapshot.reinforcement_trial_success_rate_best_value.pth -d demos/row_demos/ -t row -o logs/finetuned_models/
elif [ "$task" = "stack" ]
then
# stack finetunes
python3 train_offline.py -m logs/base_models/rows_hist_densenet/snapshot.reinforcement_action_efficiency_best_value.pth -d demos/stack_demos/ -t stack -o logs/finetuned_models/
python3 train_offline.py -m logs/base_models/unstacking_hist_densenet/snapshot.reinforcement_action_efficiency_best_value.pth -d demos/stack_demos/ -t stack -o logs/finetuned_models/
python3 train_offline.py -m logs/base_models/vertical_square_hist_densenet/snapshot.reinforcement_trial_success_rate_best_value.pth -d demos/stack_demos/ -t stack -o logs/finetuned_models/
elif [ "$task" = "unstack" ]
then
# unstack finetunes
python3 train_offline.py -m logs/base_models/rows_hist_densenet/snapshot.reinforcement_action_efficiency_best_value.pth -d demos/unstacking_demos/ -t unstack -o logs/finetuned_models/
python3 train_offline.py -m logs/base_models/stacking_hist_densenet/snapshot.reinforcement_action_efficiency_best_value.pth -d demos/unstacking_demos/ -t unstack -o logs/finetuned_models/ --trial_reward
python3 train_offline.py -m logs/base_models/vertical_square_hist_densenet/snapshot.reinforcement_trial_success_rate_best_value.pth -d demos/unstacking_demos/ -t unstack -o logs/finetuned_models/
elif [ "$task" = "vertical_square" ]
then
# vertical square finetunes
python3 train_offline.py -m logs/base_models/rows_hist_densenet/snapshot.reinforcement_action_efficiency_best_value.pth -d demos/vertical_square_demos/ -t vertical_square -o logs/finetuned_models/
python3 train_offline.py -m logs/base_models/stacking_hist_densenet/snapshot.reinforcement_action_efficiency_best_value.pth -d demos/vertical_square_demos/ -t vertical_square -o logs/finetuned_models/ --trial_reward
python3 train_offline.py -m logs/base_models/unstacking_hist_densenet/snapshot.reinforcement_action_efficiency_best_value.pth -d demos/vertical_square_demos/ -t vertical_square -o logs/finetuned_models/
else
echo "Must pass one of [row | stack | unstack | vertical_square] to -t."
fi
fi
if [ $gr_baseline -eq 1 ]
then
echo "Running Good Robot Few-Shot Finetuning Baseline..."
if [ "$task" = "row" ]
then
python3 main.py --is_sim --obj_mesh_dir objects/blocks --num_obj 4 --explore_rate_decay --common_sense --place --future_reward_discount 0.65 --tcp_port 19998 --max_test_trials 50 \
--random_seed 1238 --is_testing --task_type row --depth_channels_history --snapshot_file logs/finetuned_models/base_vertical_square_finetune_row.pth
elif [ "$task" = "stack" ]
then
python3 main.py --is_sim --obj_mesh_dir objects/blocks --num_obj 4 --explore_rate_decay --common_sense --place --future_reward_discount 0.65 --tcp_port 19999 --max_test_trials 50 \
--random_seed 1238 --is_testing --task_type stack --depth_channels_history --snapshot_file logs/finetuned_models/base_vertical_square_finetune_stack.pth
elif [ "$task" = "unstack" ]
then
# python3 main.py --is_sim --obj_mesh_dir objects/blocks --num_obj 4 --explore_rate_decay --common_sense --place --future_reward_discount 0.65 --tcp_port 20000 --max_test_trials 50 \
# --random_seed 1238 --is_testing --task_type unstack --depth_channels_history --snapshot_file logs/finetuned_models/base_row_finetune_unstack.pth
python3 main.py --is_sim --obj_mesh_dir objects/blocks --num_obj 4 --explore_rate_decay --common_sense --place --future_reward_discount 0.65 --tcp_port 20000 --max_test_trials 50 \
--random_seed 1238 --is_testing --task_type unstack --depth_channels_history --snapshot_file logs/finetuned_models/base_stack_finetune_unstack.pth
elif [ "$task" = "vertical_square" ]
then
python3 main.py --is_sim --obj_mesh_dir objects/blocks --num_obj 4 --explore_rate_decay --trial_reward --common_sense --place --future_reward_discount 0.65 --tcp_port 20002 --max_test_trials 50 \
--random_seed 1238 --is_testing --task_type vertical_square --depth_channels_history --snapshot_file logs/finetuned_models/base_stack_finetune_vertical_square.pth
else
echo "Must pass one of [row | stack | unstack | vertical_square] to -t."
fi
fi
# regenerate embedding pickles
if [ $embed -eq 1 ]
then
echo "Computing and Saving Embeddings..."
if [ "$task" = "row" ]
then
# row
python3 evaluate_demo_correspondence.py -e demos/row_demos -d demos/row_demos -t row --stack_snapshot_file logs/finetuned_models/base_stack_finetune_row.pth \
--vertical_square_snapshot_file logs/finetuned_models/base_vertical_square_finetune_row.pth --unstack_snapshot_file logs/finetuned_models/base_unstack_finetune_row.pth \
--write_embed --depth_channels_history --cycle_consistency
elif [ "$task" = "stack" ]
then
# stack
python3 evaluate_demo_correspondence.py -e demos/stack_demos -d demos/stack_demos -t stack --row_snapshot_file logs/finetuned_models/base_row_finetune_stack.pth \
--vertical_square_snapshot_file logs/finetuned_models/base_vertical_square_finetune_stack.pth \
--unstack_snapshot_file logs/finetuned_models/base_unstack_finetune_stack.pth --write_embed --depth_channels_history --cycle_consistency
elif [ "$task" = "unstack" ]
then
# unstack
python3 evaluate_demo_correspondence.py -e demos/unstacking_demos -d demos/unstacking_demos -t unstack --stack_snapshot_file \
logs/finetuned_models/base_stack_finetune_unstack.pth --vertical_square_snapshot_file logs/finetuned_models/base_vertical_square_finetune_unstack.pth \
--row_snapshot_file logs/finetuned_models/base_row_finetune_unstack.pth \
--write_embed --depth_channels_history --cycle_consistency
elif [ "$task" = "vertical_square" ]
then
# vertical_square
python3 evaluate_demo_correspondence.py -e demos/vertical_square_demos -d demos/vertical_square_demos -t vertical_square --row_snapshot_file \
logs/finetuned_models/base_row_finetune_vertical_square.pth --stack_snapshot_file logs/finetuned_models/base_stack_finetune_vertical_square.pth \
--unstack_snapshot_file logs/finetuned_models/base_unstack_finetune_vertical_square.pth --write_embed --depth_channels_history --cycle_consistency
else
echo "Must pass one of [row | stack | unstack | vertical_square] to -t."
fi
fi
# Run SSR
if [ $ssr -eq 1 ]
then
./ssr.sh -t $task
fi