-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathrun_pipeline.sh
More file actions
executable file
·341 lines (285 loc) · 9.2 KB
/
Copy pathrun_pipeline.sh
File metadata and controls
executable file
·341 lines (285 loc) · 9.2 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/bin/bash
# Function to check if a command was successful
check_command() {
if [ $? -ne 0 ]; then
echo "Error: $1"
exit 1
fi
}
# Add GPU IDs to the global scope
GPU_IDS=""
# Phase 0
phase0() {
echo "Starting Phase 0..."
# Delete RallyClipper/outputs if it exists
if [ -d "RallyClipper/outputs" ]; then
rm -rf RallyClipper/outputs
check_command "Failed to delete RallyClipper/outputs"
fi
# Prepare BallTracker/matches folder
if [ -d "BallTracker/matches" ]; then
rm -rf BallTracker/matches
fi
mkdir -p BallTracker/matches
check_command "Failed to create BallTracker/matches"
# Prepare BallTracker/outputs folder
if [ -d "BallTracker/outputs" ]; then
rm -rf BallTracker/outputs
fi
mkdir -p BallTracker/outputs
check_command "Failed to create BallTracker/outputs"
# Prepare TableTracker/outputs folder
if [ -d "TableTracker/outputs" ]; then
rm -rf TableTracker/outputs
fi
mkdir -p TableTracker/outputs
check_command "Failed to create TableTracker/outputs"
# Prepare PaddleTracker/outputs folder
if [ -d "PaddleTracker/outputs" ]; then
rm -rf PaddleTracker/outputs
fi
mkdir -p PaddleTracker/outputs
check_command "Failed to create PaddleTracker/outputs"
# Prepare HumanPoseTracker/outputs folder
if [ -d "HumanPoseTracker/outputs" ]; then
rm -rf HumanPoseTracker/outputs
fi
mkdir -p HumanPoseTracker/outputs
check_command "Failed to create HumanPoseTracker/outputs"
}
# Modified phase1 function
phase1() {
echo "Starting Phase 1..."
# Activate conda environment
conda activate general
check_command "Failed to activate general environment"
# Run inference with GPU IDs
cd RallyClipper
python main.py matches outputs --gpu_ids $GPU_IDS
check_command "Failed to run RallyClipper/main.py"
cd ..
# Deactivate conda environment
conda deactivate
echo "Phase 1 completed successfully."
}
# Modified phase2 function
phase2() {
echo "Starting Ball Tracking..."
# Copy outputs
cp -R RallyClipper/outputs/* BallTracker/matches/
check_command "Failed to copy outputs to BallTracker/matches"
# Activate conda environment
conda activate ball
check_command "Failed to activate ball environment"
# Run commands with GPU IDs
cd BallTracker
python main.py matches --gpu_ids $GPU_IDS
check_command "Failed to run main.py in BallTracker"
python clip.py matches outputs
check_command "Failed to run clip.py in BallTracker"
cd ..
# Deactivate conda environment
conda deactivate
echo "Phase 2 completed successfully."
}
# Modified phase3 function
phase3() {
echo "Starting Table Tracking..."
# Activate conda environment
conda activate yolo
check_command "Failed to activate table environment"
# Run command with GPU IDs
cd TableTracker
python main.py ../BallTracker/matches --gpu_ids $GPU_IDS
check_command "Failed to run main.py in TableTracker"
cd ..
# Deactivate conda environment
conda deactivate
echo "Phase 3 completed successfully."
}
# Modified phase4 function
phase4() {
echo "Starting Paddle Tracking..."
# Activate conda environment
conda activate yolo
check_command "Failed to activate paddle environment"
# Run command with GPU IDs
cd PaddleTracker
python main.py ../BallTracker/matches --gpu_ids $GPU_IDS
check_command "Failed to run main.py in PaddleTracker"
cd ..
# Deactivate conda environment
conda deactivate
echo "Phase 4 completed successfully."
}
# Modified phase5 function
phase5() {
echo "Starting Phase 5..."
# Activate conda environment
conda activate pose
check_command "Failed to activate pose environment"
# Run command with GPU IDs
cd HumanPoseTracker
python main.py ../BallTracker/matches --gpu_ids $GPU_IDS
check_command "Failed to run main.py in HumanPoseTracker"
cd ..
# Deactivate conda environment
conda deactivate
echo "Phase 5 completed successfully."
}
# Phase 6
phase6() {
echo "Starting Phase 6..."
# Create or clear the final outputs folder
if [ -d "outputs" ]; then
rm -rf outputs
fi
mkdir -p outputs
check_command "Failed to create outputs folder"
# Process each match folder
for match_folder in HumanPoseTracker/outputs/*/; do
match_name=$(basename "$match_folder")
echo "Processing match: $match_name"
# Create match folder in the final outputs
mkdir -p "outputs/$match_name"
# Process each name folder within the match
for name_folder in "$match_folder"*/; do
name=$(basename "$name_folder")
echo " Processing name: $name"
# Create name folder in the final outputs
mkdir -p "outputs/$match_name/$name"
# Copy files from HumanPoseTracker/outputs
pose_files="$name_folder"*
if ls $pose_files 1> /dev/null 2>&1; then
cp -R $pose_files "outputs/$match_name/$name/"
check_command "Failed to copy HumanPoseTracker files for $match_name/$name"
else
echo " Warning: HumanPoseTracker files not found for $match_name/$name"
fi
# Copy table CSV if it exists
table_csv="TableTracker/outputs/$match_name/${name}_table.csv"
if [ -f "$table_csv" ]; then
cp "$table_csv" "outputs/$match_name/$name/"
check_command "Failed to copy table CSV for $match_name/$name"
else
echo " Warning: TableTracker CSV not found for $match_name/$name"
fi
# Copy paddle CSV if it exists
paddle_csv="PaddleTracker/outputs/$match_name/${name}_paddle.csv"
if [ -f "$paddle_csv" ]; then
cp "$paddle_csv" "outputs/$match_name/$name/"
check_command "Failed to copy paddle CSV for $match_name/$name"
else
echo " Warning: PaddleTracker CSV not found for $match_name/$name"
fi
# Copy ball CSV if it exists
ball_csv="BallTracker/outputs/$match_name/${name}_ball.csv"
if [ -f "$ball_csv" ]; then
cp "$ball_csv" "outputs/$match_name/$name/"
check_command "Failed to copy ball CSV for $match_name/$name"
else
echo " Warning: Ball CSV not found for $match_name/$name"
fi
# Copy mp4 if it exists
mp4="BallTracker/matches/$match_name/${name}.mp4"
if [ -f "$mp4" ]; then
cp "$mp4" "outputs/$match_name/$name/"
check_command "Failed to copy mp4 for $match_name/$name"
else
echo " Warning: mp4 not found for $match_name/$name"
fi
done
done
echo "Phase 6 completed successfully. Final outputs organized in 'outputs' folder."
}
# Modified phase7 function
phase7() {
echo "Starting Phase 7..."
# Activate conda environment
conda activate general
check_command "Failed to activate general environment"
# Run command with GPU IDs
cd RallyReconstructor
python main.py ../outputs
check_command "Failed to run main.py in RallyReconstructor"
cd ..
# Create the zip file with timestamp
timestamp=$(date +"%Y%m%d_%H%M%S")
zip_file="outputs_${timestamp}.zip"
zip -r "$zip_file" "outputs"
check_command "Failed to create zip file"
echo "Phase 7 completed successfully. Final outputs organized in 'outputs' folder."
}
# Check if matches folder exists in RallyClipper
check_RallyClipper_matches() {
if [ ! -d "RallyClipper/matches" ]; then
echo "Error: RallyClipper/matches folder not found"
exit 1
fi
}
# Modified main function to accept GPU IDs
main() {
eval "$(conda shell.bash hook)"
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--gpu_ids)
GPU_IDS="$2"
shift 2
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done
# Check if GPU IDs are provided
if [ -z "$GPU_IDS" ]; then
echo "Error: GPU IDs not provided. Use --gpu_ids flag."
exit 1
fi
case "${POSITIONAL_ARGS[0]}" in
phase0)
phase0
;;
phase1)
check_RallyClipper_matches
phase1
;;
phase2)
phase2
;;
phase3)
phase3
;;
phase4)
phase4
;;
phase5)
phase5
;;
phase6)
phase6
;;
phase7)
phase7
;;
all)
check_RallyClipper_matches
phase0
phase1
phase2
phase3
phase4
phase5
phase6
phase7
;;
*)
echo "Usage: $0 --gpu_ids 'GPU_IDS' {phase1|phase2|phase3|phase4|phase5|phase6|all}"
exit 1
;;
esac
}
# Run the main function with command-line arguments
main "$@"