| | from datasets import load_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, |
| | } |
| |
|
| | |
| | unique_video_ids = set() |
| | unique_clips = set() |
| |
|
| | |
| | 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'] |
| |
|
| | |
| | unique_video_ids.add(video_id) |
| |
|
| | |
| | unique_clips.add(clip_id) |
| |
|
| | |
| | total_video_duration.update({entry['video_metadata']['video_id']: entry['video_metadata']['video_duration']}) |
| |
|
| | |
| | total_vclip_duration.update({entry['vclip_id']: entry['video_metadata']['vclip_duration']}) |
| | |
| | |
| | total_frames.update({entry['video_metadata']['video_id']: entry['video_metadata']['video_frame_count']}) |
| |
|
| | |
| | total_keyframes += len(entry['frame_indexes_vclip']) |
| |
|
| | |
| | total_questions += 1 |
| |
|
| | |
| | total_clips += 1 |
| |
|
| | |
| | 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) |
| |
|