Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

批处理:simple bash file for video folder batch processing #357

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions models/.placeholder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

52 changes: 52 additions & 0 deletions run_tracking.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
# usage:
# 0. modify the path parameter and check every step carefully
# 1. chmod+x run_tracking.sh
# 2. ./run_tracking.sh
# Set the path to the videos and the tracking script
VIDEOS_PATH="./videos/bdd/"
SCRIPT_PATH="./tools/demo_track.py"
# Set this to the directory where the .txt files are saved
OUTPUT_PATH="./YOLOX_outputs/yolox_s_mix_det/track_vis/"

# Iterate through all .mov videos in the directory
for video in $VIDEOS_PATH/*.mov; do
video_name=$(basename "$video" .mov)
output_file="${OUTPUT_PATH}/${video_name}.txt"

# Check if the output file already exists
if [[ -f "$output_file" ]]; then
echo "Output for $video_name already exists. Skipping..."
continue
fi

# Run the tracking script for the current video
python $SCRIPT_PATH video -f exps/example/mot/yolox_s_mix_det.py --path "$video" --ckpt './models/bytetrack_s_mot17.pth.tar' --fp16 --fuse --save_result
echo "Processed video: $video_name"

#python tools/demo_track.py video -f exps/example/mot/yolox_s_mix_det.py -c ./models/bytetrack_s_mot17.pth.tar --path ./videos/BDD/b1f4491b-9958bd99.mov --fp16 --fuse --save_result

# Optionally, rename the output (assuming the original script produces a timestamped output)
# mv "path_to_original_output" "${video_name}.txt"
done

# Post-process renaming
python tools/post_rename.py

# store txt
zip -r txt_archive.zip $OUTPUT_PATH/*.txt
# Create archives of .mov videos using zip

DATE=$(date +"%Y_%m_%d")
NEW_FOLDER="$OUTPUT_PATH/$DATE"

mkdir -p "$NEW_FOLDER"
find "$OUTPUT_PATH" -type f -name "*.mp4" -exec mv {} "$NEW_FOLDER/" \;

# zip -r video_archive.zip $OUTPUT_PATH/*/*.mp4
zip -r video_archive.zip "$NEW_FOLDER"

echo "Archiving completed!"



28 changes: 28 additions & 0 deletions tools/post_rename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os

def rename_txt_files(output_folder):
# Traverse the ByteTrack output directory
for subdir in os.listdir(output_folder):
subdir_path = os.path.join(output_folder, subdir)

# Ensure it's a directory
if os.path.isdir(subdir_path):
# Get the BDD video name from the .mov file
mov_files = [f for f in os.listdir(subdir_path) if f.endswith('.mov')]
if mov_files:
bdd_video_name = mov_files[0].replace('.mov', '')

# Construct old and new txt file paths
old_txt_path = os.path.join(output_folder, f"{subdir}.txt")
new_txt_path = os.path.join(output_folder, f"{bdd_video_name}.txt")

# Rename the txt file
if os.path.exists(old_txt_path):
os.rename(old_txt_path, new_txt_path)
print(f"Renamed {old_txt_path} to {new_txt_path}")
else:
print(f"File {old_txt_path} does not exist!")

# Example usage
output_folder = 'YOLOX_outputs/yolox_s_mix_det/track_vis'
rename_txt_files(output_folder)