-
Notifications
You must be signed in to change notification settings - Fork 37
/
generate.sh
58 lines (48 loc) · 1.47 KB
/
generate.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
#!/bin/bash
# Function to display usage
usage() {
echo "Usage: $0 --method <method> --task <task> --tag <tag> [--checkpoint <checkpoint>]"
exit 1
}
# Initialize parameters
method=""
task=""
tag=""
checkpoint=""
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--method) method="$2"; shift ;;
--task) task="$2"; shift ;;
--tag) tag="$2"; shift ;;
--checkpoint) checkpoint="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; usage ;;
esac
shift
done
# Check if all required arguments are provided
if [ -z "$method" ] || [ -z "$task" ] || [ -z "$tag" ]; then
usage
fi
checkpoint_path=./logs/${task}/${method}/${tag}/checkpoints
# If no checkpoint is provided, find the latest checkpoint
if [ -z "$checkpoint" ]; then
pt_files=($(ls ${checkpoint_path}/*.pt 2>/dev/null))
if [ ${#pt_files[@]} -eq 0 ]; then
echo "No .pt files found in the checkpoints directory."
exit 1
fi
max_checkpoint=$(for f in "${pt_files[@]}"; do
basename "$f" | grep -o -E '[0-9]+' | sort -n | tail -1
done | sort -n | tail -1)
echo "max_checkpoint is ${max_checkpoint}"
checkpoint=$max_checkpoint
fi
# If checkpoint is found or provided, run the sample.py script
if [ -n "$checkpoint" ]; then
python sample.py --config ./configs/${task}/test/${method}.yml --out_root ./results/${task}/ --tag ${tag} --checkpoint ${checkpoint}
else
echo "No valid checkpoint found."
exit 1
fi
##