Datasets:

Modalities:
Text
Formats:
parquet
ArXiv:
Libraries:
Datasets
pandas
ZihanWang314 commited on
Commit
dd8056d
·
verified ·
1 Parent(s): 05f895c

Create get_dataset_stat.py

Browse files
Files changed (1) hide show
  1. get_dataset_stat.py +97 -0
get_dataset_stat.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+
3
+ # Load the dataset
4
+ dataset = load_dataset("LVHaystack/LongVideoHaystack")
5
+
6
+ def calculate_statistics(dataset, splits=['train', 'test', 'val', 'test_tiny']):
7
+ statistics = {
8
+ "total_videos": 0,
9
+ "total_clips": 0,
10
+ "total_video_duration_hours": 0,
11
+ "total_vclip_duration_hours": 0,
12
+ "total_frames": 0,
13
+ "total_keyframes": 0,
14
+ "total_qa_pairs": 0,
15
+ "average_frames_per_video": 0,
16
+ "average_keyframes_per_question": 0,
17
+ "average_duration_per_video": 0,
18
+ "average_duration_per_vclip": 0,
19
+ "total_clips_deduplicated": 0,
20
+ "total_video_duration_hours_dedup": 0,
21
+ }
22
+
23
+ # Sets for deduplication
24
+ unique_video_ids = set()
25
+ unique_clips = set()
26
+
27
+ # Variables for calculations
28
+ total_clips = 0
29
+ total_video_duration = {}
30
+ total_vclip_duration = {}
31
+ total_frames = {}
32
+ total_keyframes = 0
33
+ total_questions = 0
34
+
35
+ for split in splits:
36
+ for entry in dataset[split]:
37
+ video_id = entry['video_metadata']['video_id']
38
+ clip_id = entry['vclip_id']
39
+
40
+ # Count unique videos
41
+ unique_video_ids.add(video_id)
42
+
43
+ # Track deduplicated clips
44
+ unique_clips.add(clip_id)
45
+
46
+ # Add clip duration to total duration
47
+ total_video_duration.update({entry['video_metadata']['video_id']: entry['video_metadata']['video_duration']})
48
+
49
+ # Add clip duration to total duration
50
+ total_vclip_duration.update({entry['vclip_id']: entry['video_metadata']['vclip_duration']})
51
+
52
+ # Add frame count to total frames
53
+ total_frames.update({entry['video_metadata']['video_id']: entry['video_metadata']['video_frame_count']})
54
+
55
+ # Add keyframes to total keyframes
56
+ total_keyframes += len(entry['frame_indexes_vclip'])
57
+
58
+ # Add question to total QA pairs
59
+ total_questions += 1
60
+
61
+ # Count video clips
62
+ total_clips += 1
63
+
64
+ # Populate statistics dictionary
65
+ statistics["total_videos"] = len(unique_video_ids)
66
+ statistics["total_clips"] = len(unique_clips)
67
+ statistics["total_video_duration_hours"] = sum(total_video_duration.values()) / 3600
68
+ statistics["total_vclip_duration_hours"] = sum(total_vclip_duration.values()) / 3600
69
+ statistics["total_frames"] = sum(total_frames.values())
70
+ statistics["total_keyframes"] = total_keyframes
71
+ statistics["total_qa_pairs"] = total_questions
72
+ statistics["average_frames_per_video"] = statistics["total_frames"] / len(unique_video_ids) if unique_video_ids else 0
73
+ statistics["average_keyframes_per_question"] = statistics["total_keyframes"] / total_questions if total_questions else 0
74
+ statistics["average_duration_per_video"] = statistics["total_video_duration_hours"] / len(unique_video_ids) * 3600 if unique_video_ids else 0
75
+ statistics["average_duration_per_vclip"] = statistics["total_vclip_duration_hours"] / len(unique_clips) * 3600 if unique_clips else 0
76
+
77
+ return statistics
78
+
79
+ def display(statistics, head="Dataset Statistics Summary"):
80
+ print("\n" + "="*40)
81
+ print(f" {head}")
82
+ print("="*40)
83
+ print(f"Total Videos: {statistics['total_videos']:,}")
84
+ print(f"Total Clips: {statistics['total_clips']:,}")
85
+ print(f"Total Video Duration (hours): {statistics['total_video_duration_hours']:.2f}")
86
+ print(f"Total Video Clip Duration (hours): {statistics['total_vclip_duration_hours']:.2f}")
87
+ print(f"Total Frames: {statistics['total_frames']:,}")
88
+ print(f"Total Keyframes: {statistics['total_keyframes']:,}")
89
+ print(f"Total QA Pairs: {statistics['total_qa_pairs']:,}")
90
+ print(f"Average Frames per Video: {statistics['average_frames_per_video']:.2f}")
91
+ print(f"Average Keyframes per Question: {statistics['average_keyframes_per_question']:.2f}")
92
+ print(f"Average Duration per Video (seconds, deduplicated): {statistics['average_duration_per_video']:.2f}")
93
+ print(f"Average Duration per Video Clip (seconds, deduplicated): {statistics['average_duration_per_vclip']:.2f}")
94
+ print("="*40 + "\n")
95
+
96
+ statistics = calculate_statistics(dataset)
97
+ display(statistics)