| |
|
| | import json |
| | import os |
| | import shutil |
| | import random |
| | from pathlib import Path |
| |
|
| | |
| | train = json.load(open('/home/jisoo/demo/VidChain/VTimeLLM/data/activitynet/mdpo-train.json')) |
| | val = json.load(open('/home/jisoo/demo/VidChain/VTimeLLM/data/activitynet/val_2.json')) |
| |
|
| | |
| | source_dir = Path('/hub_data2/jisoo/data/ActivityNet/videos') |
| |
|
| | |
| | train_dir = Path('/home/jisoo/demo/VidChain/VTimeLLM/data/activitynet/videos/train') |
| | val_dir = Path('/home/jisoo/demo/VidChain/VTimeLLM/data/activitynet/videos/val') |
| | train_dir.mkdir(exist_ok=True) |
| | val_dir.mkdir(exist_ok=True) |
| |
|
| | def copy_video(video_id, output_dir): |
| | """Copy a video from the source directory to the target directory""" |
| | |
| | possible_extensions = ['.mp4', '.mkv', '.avi', '.mov'] |
| | |
| | for ext in possible_extensions: |
| | source_path = source_dir / f"{video_id}{ext}" |
| | if source_path.exists(): |
| | output_path = output_dir / f"{video_id}.mp4" |
| | |
| | |
| | if output_path.exists(): |
| | print(f"Video {video_id} already exists in {output_dir}, skipping...") |
| | return True |
| | |
| | try: |
| | print(f"Copying {video_id} to {output_dir}...") |
| | shutil.copy2(source_path, output_path) |
| | print(f"Successfully copied {video_id}") |
| | return True |
| | except Exception as e: |
| | print(f"Error copying {video_id}: {e}") |
| | return False |
| | |
| | print(f"Video {video_id} not found in source directory") |
| | return False |
| |
|
| | def copy_sample_videos_from_list(video_ids, output_dir, num_samples=25): |
| | """Copy a sample of videos from a list of video IDs""" |
| | |
| | if len(video_ids) > num_samples: |
| | sampled_ids = random.sample(video_ids, num_samples) |
| | else: |
| | sampled_ids = video_ids |
| | |
| | print(f"Copying {len(sampled_ids)} videos to {output_dir}...") |
| | |
| | successful_copies = 0 |
| | for video_id in sampled_ids: |
| | if copy_video(video_id, output_dir): |
| | successful_copies += 1 |
| | |
| | print(f"Successfully copied {successful_copies}/{len(sampled_ids)} videos") |
| | return successful_copies |
| |
|
| | |
| | random.seed(42) |
| |
|
| | |
| | if not source_dir.exists(): |
| | print(f"Error: Source directory {source_dir} does not exist!") |
| | exit(1) |
| |
|
| | print(f"Source directory: {source_dir}") |
| | print(f"Train directory: {train_dir}") |
| | print(f"Validation directory: {val_dir}") |
| |
|
| | |
| | train_video_ids = train['vid'] if 'vid' in train else [] |
| | print(f"Found {len(train_video_ids)} video IDs in train dataset") |
| |
|
| | |
| | val_video_ids = list(val.keys()) |
| | print(f"Found {len(val_video_ids)} video IDs in validation dataset") |
| |
|
| | |
| | |
| | |
| |
|
| | print("\n=== Copying Validation Videos ===") |
| | val_success = copy_sample_videos_from_list(val_video_ids, val_dir, num_samples=50) |
| |
|
| | print(f"\n=== Summary ===") |
| | |
| | print(f"Validation videos copied: {val_success}/25") |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | print(f"\n=== Copied Validation Videos ===") |
| | val_files = list(val_dir.glob("*.mp4")) |
| | for file in val_files: |
| | print(f" {file.name}") |
| |
|
| | |
| | print(f"\n=== Statistics ===") |
| | |
| | print(f"Total validation files: {len(val_files)}") |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | if val_files: |
| | total_val_size = sum(f.stat().st_size for f in val_files) |
| | print(f"Total validation directory size: {total_val_size / (1024*1024):.2f} MB") |