| |
| |
|
|
| |
| |
| |
|
|
| import time, pdb, argparse, subprocess, os, glob, json |
|
|
| from SyncNetInstance import * |
|
|
| |
|
|
| parser = argparse.ArgumentParser(description = "SyncNet Batch Processing"); |
|
|
| parser.add_argument('--initial_model', type=str, default="data/syncnet_v2.model", help='Path to SyncNet model'); |
| parser.add_argument('--batch_size', type=int, default=20, help='Batch size for processing'); |
| parser.add_argument('--vshift', type=int, default=15, help='Video shift for evaluation'); |
| parser.add_argument('--video_dir', type=str, required=True, help='Directory containing video files'); |
| parser.add_argument('--tmp_dir', type=str, default="data/work/pytmp", help='Temporary directory'); |
| parser.add_argument('--output_file', type=str, default="syncnet_scores.json", help='Output JSON file for results'); |
| parser.add_argument('--video_ext', type=str, default="mp4,avi,mov,mkv", help='Video extensions to process (comma-separated)'); |
|
|
| opt = parser.parse_args(); |
|
|
| |
|
|
| s = SyncNetInstance(); |
| s.loadParameters(opt.initial_model); |
| print("Model %s loaded." % opt.initial_model); |
|
|
| |
|
|
| video_extensions = opt.video_ext.split(',') |
| video_files = [] |
| for ext in video_extensions: |
| video_files.extend(glob.glob(os.path.join(opt.video_dir, f'*.{ext.strip()}'))) |
| video_files.extend(glob.glob(os.path.join(opt.video_dir, f'*.{ext.strip().upper()}'))) |
|
|
| video_files = sorted(list(set(video_files))) |
| print(f"Found {len(video_files)} video files to process.") |
|
|
| |
|
|
| results = {} |
|
|
| for idx, videofile in enumerate(video_files): |
| video_name = os.path.basename(videofile) |
| print(f"\n[{idx+1}/{len(video_files)}] Processing: {video_name}") |
|
|
| |
| opt.reference = os.path.splitext(video_name)[0] |
|
|
| try: |
| offset, conf, dists = s.evaluate(opt, videofile=videofile) |
|
|
| results[video_name] = { |
| 'offset': int(offset), |
| 'confidence': float(conf), |
| 'min_dist': float(dists.min()) if dists is not None else None, |
| 'status': 'success' |
| } |
| print(f" -> Offset: {offset}, Confidence: {conf:.3f}") |
|
|
| except Exception as e: |
| results[video_name] = { |
| 'offset': None, |
| 'confidence': None, |
| 'min_dist': None, |
| 'status': 'error', |
| 'error_message': str(e) |
| } |
| print(f" -> Error: {str(e)}") |
|
|
| |
|
|
| with open(opt.output_file, 'w') as f: |
| json.dump(results, f, indent=2) |
|
|
| print(f"\nResults saved to {opt.output_file}") |
|
|
| |
| successful = sum(1 for r in results.values() if r['status'] == 'success') |
| print(f"Processed {successful}/{len(video_files)} videos successfully.") |
|
|