Jerry Hill commited on
Commit
f6e44ec
·
1 Parent(s): 29a4395

adding basic x3d inference script

Browse files
__pycache__/inference.cpython-310.pyc ADDED
Binary file (2.97 kB). View file
 
inference.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ import json
4
+ import urllib.request
5
+ from pytorchvideo.data.encoded_video import EncodedVideo
6
+
7
+ # === Config ===
8
+ model_name = "x3d_m" # options: x3d_xs, x3d_s, x3d_m, x3d_l
9
+ device = torch.device("cpu")
10
+
11
+ # === Load Model ===
12
+ model = torch.hub.load(
13
+ "facebookresearch/pytorchvideo",
14
+ model_name,
15
+ pretrained=True
16
+ ).to(device).eval()
17
+
18
+ # === Load Kinetics-400 Labels ===
19
+ label_map_path = "kinetics_classnames.json"
20
+ if not os.path.exists(label_map_path):
21
+ urllib.request.urlretrieve(
22
+ "https://dl.fbaipublicfiles.com/pyslowfast/dataset/class_names/kinetics_classnames.json",
23
+ label_map_path
24
+ )
25
+ with open(label_map_path, "r") as f:
26
+ raw = json.load(f)
27
+ # raw may map label->id or be a list; invert mapping if necessary
28
+ if isinstance(raw, dict):
29
+ # raw: {label: id}
30
+ kinetics_labels = {v: k for k, v in raw.items()}
31
+ elif isinstance(raw, list):
32
+ # raw: [label0, label1, ...]
33
+ kinetics_labels = {i: raw[i] for i in range(len(raw))}
34
+ else:
35
+ raise ValueError("Unexpected label map format")
36
+
37
+ # === Preprocessing ===
38
+ def preprocess(frames, num_samples: int = 16, size: int = 224) -> torch.Tensor:
39
+ """
40
+ frames: Tensor [C, T, H, W]
41
+ returns: Tensor [1, C, T_sampled, size, size]
42
+ """
43
+ # Permute to [T, C, H, W]
44
+ C, T, H, W = frames.shape
45
+ vid = frames.permute(1, 0, 2, 3).float() / 255.0
46
+
47
+ # Log shapes
48
+ print(f"[DEBUG] Raw frames shape: {frames.shape}")
49
+
50
+ # Uniform temporal subsampling
51
+ idx = torch.linspace(0, T - 1, num_samples).long()
52
+ clip = vid[idx] # [num_samples, C, H, W]
53
+
54
+ # Center crop spatially
55
+ top = max((H - size) // 2, 0)
56
+ left = max((W - size) // 2, 0)
57
+ clip = clip[:, :, top:top+size, left:left+size]
58
+
59
+ # Log clipped shape
60
+ print(f"[DEBUG] After crop & sample clip shape: {clip.shape}")
61
+
62
+ # Permute to [C, T, H, W] and add batch => [1, C, T, H, W]
63
+ clip = clip.permute(1, 0, 2, 3).unsqueeze(0)
64
+
65
+ # Normalize channels
66
+ mean = torch.tensor([0.45, 0.45, 0.45], device=device).view(1, 3, 1, 1, 1)
67
+ std = torch.tensor([0.225, 0.225, 0.225], device=device).view(1, 3, 1, 1, 1)
68
+ clip = (clip - mean) / std
69
+
70
+ print(f"[DEBUG] Final input shape: {clip.shape}")
71
+ return clip
72
+
73
+ # === Prediction ===
74
+ def predict_clip(path: str):
75
+ print(f"[INFO] Processing clip: {path}")
76
+ video = EncodedVideo.from_path(path)
77
+ frames = video.get_clip(0, 2.0)["video"] # [C, T, H, W]
78
+
79
+ inp = preprocess(frames).to(device)
80
+
81
+ with torch.no_grad():
82
+ logits = model(inp)
83
+ probs = torch.softmax(logits, dim=1)[0]
84
+
85
+ top5 = torch.topk(probs, k=5)
86
+ results = []
87
+ for idx_tensor, score in zip(top5.indices, top5.values):
88
+ idx = idx_tensor.item()
89
+ label = kinetics_labels.get(idx, f"Class_{idx}")
90
+ results.append((label, float(score)))
91
+ return results
92
+
93
+ # === CLI ===
94
+ if __name__ == "__main__":
95
+ import sys
96
+ clip_path = sys.argv[1] if len(sys.argv) > 1 else "segments/segment_000.mp4"
97
+ preds = predict_clip(clip_path)
98
+ print("\nTop-5 labels:")
99
+ for label, score in preds:
100
+ print(f"{label:>30s} : {score:.3f}")
101
+
kinetics_classnames.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"\"sharpening knives\"": 290, "\"eating ice cream\"": 115, "\"cutting nails\"": 81, "\"changing wheel\"": 53, "\"bench pressing\"": 19, "deadlifting": 88, "\"eating carrots\"": 111, "marching": 192, "\"throwing discus\"": 358, "\"playing flute\"": 231, "\"cooking on campfire\"": 72, "\"breading or breadcrumbing\"": 33, "\"playing badminton\"": 218, "\"ripping paper\"": 276, "\"playing saxophone\"": 244, "\"milking cow\"": 197, "\"juggling balls\"": 169, "\"flying kite\"": 130, "capoeira": 43, "\"making jewelry\"": 187, "drinking": 100, "\"playing cymbals\"": 228, "\"cleaning gutters\"": 61, "\"hurling (sport)\"": 161, "\"playing organ\"": 239, "\"tossing coin\"": 361, "wrestling": 395, "\"driving car\"": 103, "headbutting": 150, "\"gymnastics tumbling\"": 147, "\"making bed\"": 186, "abseiling": 0, "\"holding snake\"": 155, "\"rock climbing\"": 278, "\"cooking egg\"": 71, "\"long jump\"": 182, "\"bee keeping\"": 17, "\"trimming or shaving beard\"": 365, "\"cleaning shoes\"": 63, "\"dancing gangnam style\"": 86, "\"catching or throwing softball\"": 50, "\"ice skating\"": 164, "jogging": 168, "\"eating spaghetti\"": 116, "bobsledding": 28, "\"assembling computer\"": 8, "\"playing cricket\"": 227, "\"playing monopoly\"": 238, "\"golf putting\"": 143, "\"making pizza\"": 188, "\"javelin throw\"": 166, "\"peeling potatoes\"": 211, "clapping": 57, "\"brushing hair\"": 36, "\"flipping pancake\"": 129, "\"drinking beer\"": 101, "\"dribbling basketball\"": 99, "\"playing bagpipes\"": 219, "somersaulting": 325, "\"canoeing or kayaking\"": 42, "\"riding unicycle\"": 275, "texting": 355, "\"tasting beer\"": 352, "\"hockey stop\"": 154, "\"playing clarinet\"": 225, "\"waxing legs\"": 389, "\"curling hair\"": 80, "\"running on treadmill\"": 281, "\"tai chi\"": 346, "\"driving tractor\"": 104, "\"shaving legs\"": 293, "\"sharpening pencil\"": 291, "\"making sushi\"": 190, "\"spray painting\"": 327, "situp": 305, "\"playing kickball\"": 237, "\"sticking tongue out\"": 331, "headbanging": 149, "\"folding napkins\"": 132, "\"playing piano\"": 241, "skydiving": 312, "\"dancing charleston\"": 85, "\"ice fishing\"": 163, "tickling": 359, "bandaging": 13, "\"high jump\"": 151, "\"making a sandwich\"": 185, "\"riding mountain bike\"": 271, "\"cutting pineapple\"": 82, "\"feeding goats\"": 125, "\"dancing macarena\"": 87, "\"playing basketball\"": 220, "krumping": 179, "\"high kick\"": 152, "\"balloon blowing\"": 12, "\"playing accordion\"": 217, "\"playing chess\"": 224, "\"hula hooping\"": 159, "\"pushing wheelchair\"": 263, "\"riding camel\"": 268, "\"blowing out candles\"": 27, "\"extinguishing fire\"": 121, "\"using computer\"": 373, "\"jumpstyle dancing\"": 173, "yawning": 397, "writing": 396, "\"jumping into pool\"": 172, "\"doing laundry\"": 96, "\"egg hunting\"": 118, "\"sanding floor\"": 284, "\"moving furniture\"": 200, "\"exercising arm\"": 119, "\"sword fighting\"": 345, "\"sign language interpreting\"": 303, "\"counting money\"": 74, "bartending": 15, "\"cleaning windows\"": 65, "\"blasting sand\"": 23, "\"petting cat\"": 213, "sniffing": 320, "bowling": 31, "\"playing poker\"": 242, "\"taking a shower\"": 347, "\"washing hands\"": 382, "\"water sliding\"": 384, "\"presenting weather forecast\"": 254, "tobogganing": 360, "celebrating": 51, "\"getting a haircut\"": 138, "snorkeling": 321, "\"weaving basket\"": 390, "\"playing squash or racquetball\"": 245, "parasailing": 206, "\"news anchoring\"": 202, "\"belly dancing\"": 18, "windsurfing": 393, "\"braiding hair\"": 32, "\"crossing river\"": 78, "\"laying bricks\"": 181, "\"roller skating\"": 280, "hopscotch": 156, "\"playing trumpet\"": 248, "\"dying hair\"": 108, "\"trimming trees\"": 366, "\"pumping fist\"": 256, "\"playing keyboard\"": 236, "snowboarding": 322, "\"garbage collecting\"": 136, "\"playing controller\"": 226, "dodgeball": 94, "\"recording music\"": 266, "\"country line dancing\"": 75, "\"dancing ballet\"": 84, "gargling": 137, "ironing": 165, "\"push up\"": 260, "\"frying vegetables\"": 135, "\"ski jumping\"": 307, "\"mowing lawn\"": 201, "\"getting a tattoo\"": 139, "\"rock scissors paper\"": 279, "cheerleading": 55, "\"using remote controller (not gaming)\"": 374, "\"shaking head\"": 289, "sailing": 282, "\"training dog\"": 363, "hurdling": 160, "\"fixing hair\"": 128, "\"climbing ladder\"": 67, "\"filling eyebrows\"": 126, "\"springboard diving\"": 329, "\"eating watermelon\"": 117, "\"drumming fingers\"": 106, "\"waxing back\"": 386, "\"playing didgeridoo\"": 229, "\"swimming backstroke\"": 339, "\"biking through snow\"": 22, "\"washing feet\"": 380, "\"mopping floor\"": 198, "\"throwing ball\"": 357, "\"eating doughnuts\"": 113, "\"drinking shots\"": 102, "\"tying bow tie\"": 368, "dining": 91, "\"surfing water\"": 337, "\"sweeping floor\"": 338, "\"grooming dog\"": 145, "\"catching fish\"": 47, "\"pumping gas\"": 257, "\"riding or walking with horse\"": 273, "\"massaging person's head\"": 196, "archery": 5, "\"ice climbing\"": 162, "\"playing recorder\"": 243, "\"decorating the christmas tree\"": 89, "\"peeling apples\"": 210, "snowmobiling": 324, "\"playing ukulele\"": 249, "\"eating burger\"": 109, "\"building cabinet\"": 38, "\"stomping grapes\"": 332, "\"drop kicking\"": 105, "\"passing American football (not in game)\"": 209, "applauding": 3, "hugging": 158, "\"eating hotdog\"": 114, "\"pole vault\"": 253, "\"reading newspaper\"": 265, "\"snatch weight lifting\"": 318, "zumba": 399, "\"playing ice hockey\"": 235, "breakdancing": 34, "\"feeding fish\"": 124, "\"shredding paper\"": 300, "\"catching or throwing frisbee\"": 49, "\"exercising with an exercise ball\"": 120, "\"pushing cart\"": 262, "\"swimming butterfly stroke\"": 341, "\"riding scooter\"": 274, "spraying": 328, "\"folding paper\"": 133, "\"golf driving\"": 142, "\"robot dancing\"": 277, "\"bending back\"": 20, "testifying": 354, "\"waxing chest\"": 387, "\"carving pumpkin\"": 46, "\"hitting baseball\"": 153, "\"riding elephant\"": 269, "\"brushing teeth\"": 37, "\"pull ups\"": 255, "\"riding a bike\"": 267, "skateboarding": 306, "\"cleaning pool\"": 62, "\"playing paintball\"": 240, "\"massaging back\"": 193, "\"shoveling snow\"": 299, "\"surfing crowd\"": 336, "unboxing": 371, "faceplanting": 122, "trapezing": 364, "\"swinging legs\"": 343, "hoverboarding": 157, "\"playing violin\"": 250, "\"wrapping present\"": 394, "\"blowing nose\"": 26, "\"kicking field goal\"": 174, "\"picking fruit\"": 214, "\"swinging on something\"": 344, "\"giving or receiving award\"": 140, "\"planting trees\"": 215, "\"water skiing\"": 383, "\"washing dishes\"": 379, "\"punching bag\"": 258, "\"massaging legs\"": 195, "\"throwing axe\"": 356, "\"salsa dancing\"": 283, "bookbinding": 29, "\"tying tie\"": 370, "\"skiing crosscountry\"": 309, "\"shining shoes\"": 295, "\"making snowman\"": 189, "\"front raises\"": 134, "\"doing nails\"": 97, "\"massaging feet\"": 194, "\"playing drums\"": 230, "smoking": 316, "\"punching person (boxing)\"": 259, "cartwheeling": 45, "\"passing American football (in game)\"": 208, "\"shaking hands\"": 288, "plastering": 216, "\"watering plants\"": 385, "kissing": 176, "slapping": 314, "\"playing harmonica\"": 233, "welding": 391, "\"smoking hookah\"": 317, "\"scrambling eggs\"": 285, "\"cooking chicken\"": 70, "\"pushing car\"": 261, "\"opening bottle\"": 203, "\"cooking sausages\"": 73, "\"catching or throwing baseball\"": 48, "\"swimming breast stroke\"": 340, "digging": 90, "\"playing xylophone\"": 252, "\"doing aerobics\"": 95, "\"playing trombone\"": 247, "knitting": 178, "\"waiting in line\"": 377, "\"tossing salad\"": 362, "squat": 330, "vault": 376, "\"using segway\"": 375, "\"crawling baby\"": 77, "\"reading book\"": 264, "motorcycling": 199, "barbequing": 14, "\"cleaning floor\"": 60, "\"playing cello\"": 223, "drawing": 98, "auctioning": 9, "\"carrying baby\"": 44, "\"diving cliff\"": 93, "busking": 41, "\"cutting watermelon\"": 83, "\"scuba diving\"": 286, "\"riding mechanical bull\"": 270, "\"making tea\"": 191, "\"playing tennis\"": 246, "crying": 79, "\"dunking basketball\"": 107, "\"cracking neck\"": 76, "\"arranging flowers\"": 7, "\"building shed\"": 39, "\"golf chipping\"": 141, "\"tasting food\"": 353, "\"shaving head\"": 292, "\"answering questions\"": 2, "\"climbing tree\"": 68, "\"skipping rope\"": 311, "kitesurfing": 177, "\"juggling fire\"": 170, "laughing": 180, "paragliding": 205, "\"contact juggling\"": 69, "slacklining": 313, "\"arm wrestling\"": 6, "\"making a cake\"": 184, "\"finger snapping\"": 127, "\"grooming horse\"": 146, "\"opening present\"": 204, "\"tapping pen\"": 351, "singing": 304, "\"shot put\"": 298, "\"cleaning toilet\"": 64, "\"spinning poi\"": 326, "\"setting table\"": 287, "\"tying knot (not on a tie)\"": 369, "\"blowing glass\"": 24, "\"eating chips\"": 112, "\"tap dancing\"": 349, "\"climbing a rope\"": 66, "\"brush painting\"": 35, "\"chopping wood\"": 56, "\"stretching leg\"": 334, "\"petting animal (not cat)\"": 212, "\"baking cookies\"": 11, "\"stretching arm\"": 333, "beatboxing": 16, "jetskiing": 167, "\"bending metal\"": 21, "sneezing": 319, "\"folding clothes\"": 131, "\"sled dog racing\"": 315, "\"tapping guitar\"": 350, "\"bouncing on trampoline\"": 30, "\"waxing eyebrows\"": 388, "\"air drumming\"": 1, "\"kicking soccer ball\"": 175, "\"washing hair\"": 381, "\"riding mule\"": 272, "\"blowing leaves\"": 25, "\"strumming guitar\"": 335, "\"playing cards\"": 222, "snowkiting": 323, "\"playing bass guitar\"": 221, "\"applying cream\"": 4, "\"shooting basketball\"": 296, "\"walking the dog\"": 378, "\"triple jump\"": 367, "\"shearing sheep\"": 294, "\"clay pottery making\"": 58, "\"bungee jumping\"": 40, "\"unloading truck\"": 372, "\"shuffling cards\"": 301, "\"shooting goal (soccer)\"": 297, "\"tango dancing\"": 348, "\"side kick\"": 302, "\"grinding meat\"": 144, "yoga": 398, "\"hammer throw\"": 148, "\"changing oil\"": 52, "\"checking tires\"": 54, "parkour": 207, "\"eating cake\"": 110, "\"skiing slalom\"": 310, "\"juggling soccer ball\"": 171, "whistling": 392, "\"feeding birds\"": 123, "\"playing volleyball\"": 251, "\"swing dancing\"": 342, "\"skiing (not slalom or crosscountry)\"": 308, "lunge": 183, "\"disc golfing\"": 92, "\"clean and jerk\"": 59, "\"playing guitar\"": 232, "\"baby waking up\"": 10, "\"playing harp\"": 234}
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ pytorchvideo
4
+ transformers
5
+ huggingface_hub
6
+ ffmpeg-python
results.json ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "segment_001.mov": [
3
+ [
4
+ "bobsledding",
5
+ 0.0029806457459926605
6
+ ],
7
+ [
8
+ "archery",
9
+ 0.0028982453513890505
10
+ ],
11
+ [
12
+ "skateboarding",
13
+ 0.002631985815241933
14
+ ],
15
+ [
16
+ "barbequing",
17
+ 0.002604125998914242
18
+ ],
19
+ [
20
+ "\"changing wheel\"",
21
+ 0.0026030109729617834
22
+ ]
23
+ ],
24
+ "segment_002.mov": [
25
+ [
26
+ "archery",
27
+ 0.003014166606590152
28
+ ],
29
+ [
30
+ "\"golf driving\"",
31
+ 0.002740557538345456
32
+ ],
33
+ [
34
+ "\"mowing lawn\"",
35
+ 0.002675712341442704
36
+ ],
37
+ [
38
+ "\"golf putting\"",
39
+ 0.0026040568482130766
40
+ ],
41
+ [
42
+ "bobsledding",
43
+ 0.0025902960915118456
44
+ ]
45
+ ],
46
+ "segment_003.mov": [
47
+ [
48
+ "\"changing wheel\"",
49
+ 0.003073550760746002
50
+ ],
51
+ [
52
+ "barbequing",
53
+ 0.002854740945622325
54
+ ],
55
+ [
56
+ "\"mowing lawn\"",
57
+ 0.0026648251805454493
58
+ ],
59
+ [
60
+ "\"changing oil\"",
61
+ 0.0025920344050973654
62
+ ],
63
+ [
64
+ "archery",
65
+ 0.0025756466202437878
66
+ ]
67
+ ],
68
+ "segment_004.mov": [
69
+ [
70
+ "\"tossing coin\"",
71
+ 0.004114203620702028
72
+ ],
73
+ [
74
+ "\"side kick\"",
75
+ 0.002894123550504446
76
+ ],
77
+ [
78
+ "\"rock scissors paper\"",
79
+ 0.002691109199076891
80
+ ],
81
+ [
82
+ "\"punching person (boxing)\"",
83
+ 0.0026034375187009573
84
+ ],
85
+ [
86
+ "\"shaking hands\"",
87
+ 0.0025962668005377054
88
+ ]
89
+ ],
90
+ "segment_005.mov": [
91
+ [
92
+ "\"tossing coin\"",
93
+ 0.003616387490183115
94
+ ],
95
+ [
96
+ "\"passing American football (not in game)\"",
97
+ 0.0027686816174536943
98
+ ],
99
+ [
100
+ "\"passing American football (in game)\"",
101
+ 0.002704756101593375
102
+ ],
103
+ [
104
+ "\"kicking field goal\"",
105
+ 0.002686359453946352
106
+ ],
107
+ [
108
+ "\"side kick\"",
109
+ 0.0026586230378597975
110
+ ]
111
+ ],
112
+ "segment_006.mov": [
113
+ [
114
+ "\"tossing coin\"",
115
+ 0.0035721457097679377
116
+ ],
117
+ [
118
+ "\"passing American football (in game)\"",
119
+ 0.0033913173247128725
120
+ ],
121
+ [
122
+ "\"side kick\"",
123
+ 0.002801080234348774
124
+ ],
125
+ [
126
+ "\"passing American football (not in game)\"",
127
+ 0.0025844001211225986
128
+ ],
129
+ [
130
+ "\"juggling soccer ball\"",
131
+ 0.0025617412757128477
132
+ ]
133
+ ],
134
+ "segment_007.mov": [
135
+ [
136
+ "beatboxing",
137
+ 0.0027317821513861418
138
+ ],
139
+ [
140
+ "\"pumping fist\"",
141
+ 0.002660650759935379
142
+ ],
143
+ [
144
+ "\"arm wrestling\"",
145
+ 0.002654405776411295
146
+ ],
147
+ [
148
+ "bobsledding",
149
+ 0.002652029972523451
150
+ ],
151
+ [
152
+ "archery",
153
+ 0.002651914255693555
154
+ ]
155
+ ],
156
+ "segment_008.mov": [
157
+ [
158
+ "crying",
159
+ 0.0034351919312030077
160
+ ],
161
+ [
162
+ "beatboxing",
163
+ 0.0026230965740978718
164
+ ],
165
+ [
166
+ "\"pumping fist\"",
167
+ 0.0026218448765575886
168
+ ],
169
+ [
170
+ "\"fixing hair\"",
171
+ 0.0026146825402975082
172
+ ],
173
+ [
174
+ "\"getting a haircut\"",
175
+ 0.0026112159248441458
176
+ ]
177
+ ],
178
+ "segment_009.mov": [
179
+ [
180
+ "\"passing American football (in game)\"",
181
+ 0.004364537075161934
182
+ ],
183
+ [
184
+ "\"side kick\"",
185
+ 0.003033441724255681
186
+ ],
187
+ [
188
+ "\"passing American football (not in game)\"",
189
+ 0.002836051397025585
190
+ ],
191
+ [
192
+ "\"kicking field goal\"",
193
+ 0.0027268915437161922
194
+ ],
195
+ [
196
+ "\"high kick\"",
197
+ 0.0025182710960507393
198
+ ]
199
+ ],
200
+ "segment_010.mov": [
201
+ [
202
+ "\"passing American football (in game)\"",
203
+ 0.005220369435846806
204
+ ],
205
+ [
206
+ "\"kicking field goal\"",
207
+ 0.0030636927112936974
208
+ ],
209
+ [
210
+ "\"passing American football (not in game)\"",
211
+ 0.0026047772262245417
212
+ ],
213
+ [
214
+ "\"side kick\"",
215
+ 0.002511046826839447
216
+ ],
217
+ [
218
+ "\"high kick\"",
219
+ 0.0024939693976193666
220
+ ]
221
+ ],
222
+ "segment_011.mov": [
223
+ [
224
+ "\"passing American football (in game)\"",
225
+ 0.00662989029660821
226
+ ],
227
+ [
228
+ "\"passing American football (not in game)\"",
229
+ 0.002533461432904005
230
+ ],
231
+ [
232
+ "\"side kick\"",
233
+ 0.0024943421594798565
234
+ ],
235
+ [
236
+ "\"kicking field goal\"",
237
+ 0.0024910743813961744
238
+ ],
239
+ [
240
+ "\"high kick\"",
241
+ 0.002490129554644227
242
+ ]
243
+ ],
244
+ "segment_012.mov": [
245
+ [
246
+ "\"passing American football (in game)\"",
247
+ 0.006737703923135996
248
+ ],
249
+ [
250
+ "\"passing American football (not in game)\"",
251
+ 0.002498970367014408
252
+ ],
253
+ [
254
+ "\"kicking field goal\"",
255
+ 0.0024903472512960434
256
+ ],
257
+ [
258
+ "\"side kick\"",
259
+ 0.0024894215166568756
260
+ ],
261
+ [
262
+ "celebrating",
263
+ 0.002489363308995962
264
+ ]
265
+ ],
266
+ "segment_013.mov": [
267
+ [
268
+ "\"passing American football (in game)\"",
269
+ 0.006262147333472967
270
+ ],
271
+ [
272
+ "\"kicking field goal\"",
273
+ 0.0025951964780688286
274
+ ],
275
+ [
276
+ "\"tossing coin\"",
277
+ 0.0025495628360658884
278
+ ],
279
+ [
280
+ "\"passing American football (not in game)\"",
281
+ 0.002519148401916027
282
+ ],
283
+ [
284
+ "\"shaking hands\"",
285
+ 0.002490811515599489
286
+ ]
287
+ ]
288
+ }
run_all_clips.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Loop over all .mov/.mp4 files in the `data/` directory, call `predict_clip` from inference.py on each,
4
+ print the results, and append each clip's scores to a JSON file as they're generated.
5
+ """
6
+ import os
7
+ import glob
8
+ import json
9
+ from inference import predict_clip
10
+
11
+
12
+ def main(input_dir: str = "data", output_file: str = "results.json"):
13
+ # find video files
14
+ patterns = ["*.mov", "*.mp4"]
15
+ clips = []
16
+ for pat in patterns:
17
+ clips.extend(glob.glob(os.path.join(input_dir, pat)))
18
+ clips = sorted(clips)
19
+ if not clips:
20
+ print(f"No clips found in '{input_dir}'.")
21
+ return
22
+
23
+ results = {}
24
+ # Ensure output file exists with empty JSON if first write fails
25
+ try:
26
+ with open(output_file, 'w') as f:
27
+ json.dump(results, f, indent=2)
28
+ except Exception as e:
29
+ print(f"[WARN] Could not initialize {output_file}: {e}")
30
+
31
+ for clip in clips:
32
+ clip_name = os.path.basename(clip)
33
+ print(f"\n=== Scoring {clip_name} ===")
34
+ scores = predict_clip(clip)
35
+ # Record even if empty (error cases will yield empty list)
36
+ results[clip_name] = scores
37
+ # Print to console
38
+ if scores:
39
+ for label, score in scores:
40
+ print(f"{label:>30s} : {score:.3f}")
41
+ else:
42
+ print(f"[INFO] No scores for {clip_name} (skipped or error)")
43
+
44
+ # Write incremental results after each clip
45
+ try:
46
+ with open(output_file, 'w') as f:
47
+ json.dump(results, f, indent=2)
48
+ except Exception as e:
49
+ print(f"[ERROR] Failed to write {output_file}: {e}")
50
+
51
+ print(f"\nFinished scoring. Results saved to '{output_file}'")
52
+
53
+
54
+ if __name__ == "__main__":
55
+ main()
56
+