-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_kinface.sh
executable file
·114 lines (102 loc) · 2.79 KB
/
run_kinface.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
#!/bin/bash
# Default values
METRIC=""
OPERATION="kinface-ft"
RUN_ID=""
LABEL="vX"
MODEL="scl"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--metric)
METRIC="$2"
shift 2
;;
--operation)
OPERATION="$2"
shift 2
;;
--run-id)
RUN_ID="$2"
shift 2
;;
--label)
LABEL="$2"
shift 2
;;
--model)
MODEL="$2"
shift 2
;;
*)
echo "Unknown parameter: $1"
exit 1
;;
esac
done
# Validate operation
if [[ ! "$OPERATION" =~ ^(kinface-ft|kinface-ce)$ ]]; then
echo "Error: operation must be either 'kinface-ft' or 'kinface-ce'"
exit 1
fi
# Validate model
if [[ ! "$MODEL" =~ ^(scl|facornet)$ ]]; then
echo "Error: model must be either 'scl' or 'facornet'"
exit 1
fi
# Get best run based on run-id or metric
if [ -n "$RUN_ID" ]; then
echo "Finding run matching ID substring: $RUN_ID..."
BEST_RUN=$(guild select "$RUN_ID")
USE_CKPT=true
elif [ "$METRIC" = "auc" ] || [ "$METRIC" = "accuracy" ]; then
echo "Exporting best model based on $METRIC..."
BEST_RUN=$(guild select -Fo scl:train --max "$METRIC" -n1)
USE_CKPT=true
else
USE_CKPT=false
fi
if [ "$USE_CKPT" = true ]; then
if [ -z "$BEST_RUN" ]; then
echo "Error: No matching runs found"
exit 1
fi
echo "Best run found: $BEST_RUN"
# Check if run is already exported
if [ -d "weights/$BEST_RUN" ]; then
echo "Run already exported to weights directory, skipping export..."
else
# Export the run to weights/
echo "Exporting run to weights directory..."
guild export weights "$BEST_RUN" -y
fi
# Find the checkpoint file
CKPT_PATH=$(find "weights/$BEST_RUN/exp/checkpoints" -name "*.ckpt" -not -name "last.ckpt")
if [ -z "$CKPT_PATH" ]; then
echo "Error: No checkpoint file found"
exit 1
fi
echo "Found checkpoint: $CKPT_PATH"
fi
# Run the specified KinFace operation
echo "Running $OPERATION with $MODEL model..."
if [ "$OPERATION" = "kinface-ft" ]; then
if [ "$USE_CKPT" = true ]; then
# Run with checkpoint
guild run $MODEL:$OPERATION \
-l "$LABEL" \
model.init_args.lr=[1e-3,1e-4,1e-5] \
model.init_args.weights="$CKPT_PATH" \
data.init_args.dataset=[I,II] \
data.init_args.fold=[1,2,3,4,5] -y
else
# Run without checkpoint
guild run $MODEL:$OPERATION \
-l "$LABEL" \
model.init_args.lr=[1e-4,1e-5] \
data.init_args.dataset=[I,II] \
data.init_args.fold=[1,2,3,4,5] -y
fi
else
guild run $MODEL:$OPERATION -y
fi