Download get_dataset_stat.py from MLL-Lab/LongVideoHaystack: direct link, hf CLI and curl.
- Browser
- Download file 4.2 kB
-
https://huggingface.co/datasets/MLL-Lab/LongVideoHaystack/resolve/main/get_dataset_stat.py
- Command line
-
hf download hf://datasets/MLL-Lab/LongVideoHaystack/get_dataset_stat.py
-
curl -L -o get_dataset_stat.py https://huggingface.co/datasets/MLL-Lab/LongVideoHaystack/resolve/main/get_dataset_stat.py
4.2 kB
| from datasets import load_dataset | |
| # Load the dataset | |
| dataset = load_dataset("LVHaystack/LongVideoHaystack") | |
| def calculate_statistics(dataset, splits=['train', 'test', 'val', 'test_tiny']): | |
| statistics = { | |
| "total_videos": 0, | |
| "total_clips": 0, | |
| "total_video_duration_hours": 0, | |
| "total_vclip_duration_hours": 0, | |
| "total_frames": 0, | |
| "total_keyframes": 0, | |
| "total_qa_pairs": 0, | |
| "average_frames_per_video": 0, | |
| "average_keyframes_per_question": 0, | |
| "average_duration_per_video": 0, | |
| "average_duration_per_vclip": 0, | |
| "total_clips_deduplicated": 0, | |
| "total_video_duration_hours_dedup": 0, | |
| } | |
| # Sets for deduplication | |
| unique_video_ids = set() | |
| unique_clips = set() | |
| # Variables for calculations | |
| total_clips = 0 | |
| total_video_duration = {} | |
| total_vclip_duration = {} | |
| total_frames = {} | |
| total_keyframes = 0 | |
| total_questions = 0 | |
| for split in splits: | |
| for entry in dataset[split]: | |
| video_id = entry['video_metadata']['video_id'] | |
| clip_id = entry['vclip_id'] | |
| # Count unique videos | |
| unique_video_ids.add(video_id) | |
| # Track deduplicated clips | |
| unique_clips.add(clip_id) | |
| # Add clip duration to total duration | |
| total_video_duration.update({entry['video_metadata']['video_id']: entry['video_metadata']['video_duration']}) | |
| # Add clip duration to total duration | |
| total_vclip_duration.update({entry['vclip_id']: entry['video_metadata']['vclip_duration']}) | |
| # Add frame count to total frames | |
| total_frames.update({entry['video_metadata']['video_id']: entry['video_metadata']['video_frame_count']}) | |
| # Add keyframes to total keyframes | |
| total_keyframes += len(entry['frame_indexes_vclip']) | |
| # Add question to total QA pairs | |
| total_questions += 1 | |
| # Count video clips | |
| total_clips += 1 | |
| # Populate statistics dictionary | |
| statistics["total_videos"] = len(unique_video_ids) | |
| statistics["total_clips"] = len(unique_clips) | |
| statistics["total_video_duration_hours"] = sum(total_video_duration.values()) / 3600 | |
| statistics["total_vclip_duration_hours"] = sum(total_vclip_duration.values()) / 3600 | |
| statistics["total_frames"] = sum(total_frames.values()) | |
| statistics["total_keyframes"] = total_keyframes | |
| statistics["total_qa_pairs"] = total_questions | |
| statistics["average_frames_per_video"] = statistics["total_frames"] / len(unique_video_ids) if unique_video_ids else 0 | |
| statistics["average_keyframes_per_question"] = statistics["total_keyframes"] / total_questions if total_questions else 0 | |
| statistics["average_duration_per_video"] = statistics["total_video_duration_hours"] / len(unique_video_ids) * 3600 if unique_video_ids else 0 | |
| statistics["average_duration_per_vclip"] = statistics["total_vclip_duration_hours"] / len(unique_clips) * 3600 if unique_clips else 0 | |
| return statistics | |
| def display(statistics, head="Dataset Statistics Summary"): | |
| print("\n" + "="*40) | |
| print(f" {head}") | |
| print("="*40) | |
| print(f"Total Videos: {statistics['total_videos']:,}") | |
| print(f"Total Clips: {statistics['total_clips']:,}") | |
| print(f"Total Video Duration (hours): {statistics['total_video_duration_hours']:.2f}") | |
| print(f"Total Video Clip Duration (hours): {statistics['total_vclip_duration_hours']:.2f}") | |
| print(f"Total Frames: {statistics['total_frames']:,}") | |
| print(f"Total Keyframes: {statistics['total_keyframes']:,}") | |
| print(f"Total QA Pairs: {statistics['total_qa_pairs']:,}") | |
| print(f"Average Frames per Video: {statistics['average_frames_per_video']:.2f}") | |
| print(f"Average Keyframes per Question: {statistics['average_keyframes_per_question']:.2f}") | |
| print(f"Average Duration per Video (seconds, deduplicated): {statistics['average_duration_per_video']:.2f}") | |
| print(f"Average Duration per Video Clip (seconds, deduplicated): {statistics['average_duration_per_vclip']:.2f}") | |
| print("="*40 + "\n") | |
| statistics = calculate_statistics(dataset) | |
| display(statistics) | |