|
8 | 8 | import importlib.resources |
9 | 9 | import os |
10 | 10 | import platform |
11 | | -import typing |
12 | | -from dataclasses import dataclass, field |
13 | 11 | from pathlib import Path |
14 | 12 |
|
15 | 13 | import torch |
16 | 14 |
|
17 | 15 | from benchmark_decoders_library import ( |
18 | | - AbstractDecoder, |
19 | | - DecordAccurate, |
20 | | - DecordAccurateBatch, |
| 16 | + decoder_registry, |
21 | 17 | plot_data, |
22 | 18 | run_benchmarks, |
23 | | - TorchAudioDecoder, |
24 | | - TorchCodecCore, |
25 | | - TorchCodecCoreBatch, |
26 | | - TorchCodecCoreCompiled, |
27 | | - TorchCodecCoreNonBatch, |
28 | | - TorchCodecPublic, |
29 | | - TorchCodecPublicNonBatch, |
30 | | - TorchVision, |
| 19 | + verify_outputs, |
31 | 20 | ) |
32 | 21 |
|
33 | 22 |
|
34 | | -@dataclass |
35 | | -class DecoderKind: |
36 | | - display_name: str |
37 | | - kind: typing.Type[AbstractDecoder] |
38 | | - default_options: dict[str, str] = field(default_factory=dict) |
39 | | - |
40 | | - |
41 | | -decoder_registry = { |
42 | | - "decord": DecoderKind("DecordAccurate", DecordAccurate), |
43 | | - "decord_batch": DecoderKind("DecordAccurateBatch", DecordAccurateBatch), |
44 | | - "torchcodec_core": DecoderKind("TorchCodecCore", TorchCodecCore), |
45 | | - "torchcodec_core_batch": DecoderKind("TorchCodecCoreBatch", TorchCodecCoreBatch), |
46 | | - "torchcodec_core_nonbatch": DecoderKind( |
47 | | - "TorchCodecCoreNonBatch", TorchCodecCoreNonBatch |
48 | | - ), |
49 | | - "torchcodec_core_compiled": DecoderKind( |
50 | | - "TorchCodecCoreCompiled", TorchCodecCoreCompiled |
51 | | - ), |
52 | | - "torchcodec_public": DecoderKind("TorchCodecPublic", TorchCodecPublic), |
53 | | - "torchcodec_public_nonbatch": DecoderKind( |
54 | | - "TorchCodecPublicNonBatch", TorchCodecPublicNonBatch |
55 | | - ), |
56 | | - "torchvision": DecoderKind( |
57 | | - # We don't compare against TorchVision's "pyav" backend because it doesn't support |
58 | | - # accurate seeks. |
59 | | - "TorchVision[backend=video_reader]", |
60 | | - TorchVision, |
61 | | - {"backend": "video_reader"}, |
62 | | - ), |
63 | | - "torchaudio": DecoderKind("TorchAudio", TorchAudioDecoder), |
64 | | -} |
65 | | - |
66 | | - |
67 | 23 | def in_fbcode() -> bool: |
68 | 24 | return "FB_PAR_RUNTIME_FILES" in os.environ |
69 | 25 |
|
@@ -144,6 +100,12 @@ def main() -> None: |
144 | 100 | type=str, |
145 | 101 | default="benchmarks.png", |
146 | 102 | ) |
| 103 | + parser.add_argument( |
| 104 | + "--verify-outputs", |
| 105 | + help="Verify that the outputs of the decoders are the same", |
| 106 | + default=False, |
| 107 | + action=argparse.BooleanOptionalAction, |
| 108 | + ) |
147 | 109 |
|
148 | 110 | args = parser.parse_args() |
149 | 111 | specified_decoders = set(args.decoders.split(",")) |
@@ -173,29 +135,32 @@ def main() -> None: |
173 | 135 | if entry.is_file() and entry.name.endswith(".mp4"): |
174 | 136 | video_paths.append(entry.path) |
175 | 137 |
|
176 | | - results = run_benchmarks( |
177 | | - decoders_to_run, |
178 | | - video_paths, |
179 | | - num_uniform_samples, |
180 | | - num_sequential_frames_from_start=[1, 10, 100], |
181 | | - min_runtime_seconds=args.min_run_seconds, |
182 | | - benchmark_video_creation=args.bm_video_creation, |
183 | | - ) |
184 | | - data = { |
185 | | - "experiments": results, |
186 | | - "system_metadata": { |
187 | | - "cpu_count": os.cpu_count(), |
188 | | - "system": platform.system(), |
189 | | - "machine": platform.machine(), |
190 | | - "python_version": str(platform.python_version()), |
191 | | - "cuda": ( |
192 | | - torch.cuda.get_device_properties(0).name |
193 | | - if torch.cuda.is_available() |
194 | | - else "not available" |
195 | | - ), |
196 | | - }, |
197 | | - } |
198 | | - plot_data(data, args.plot_path) |
| 138 | + if args.verify_outputs: |
| 139 | + verify_outputs(decoders_to_run, video_paths, num_uniform_samples) |
| 140 | + else: |
| 141 | + results = run_benchmarks( |
| 142 | + decoders_to_run, |
| 143 | + video_paths, |
| 144 | + num_uniform_samples, |
| 145 | + num_sequential_frames_from_start=[1, 10, 100], |
| 146 | + min_runtime_seconds=args.min_run_seconds, |
| 147 | + benchmark_video_creation=args.bm_video_creation, |
| 148 | + ) |
| 149 | + data = { |
| 150 | + "experiments": results, |
| 151 | + "system_metadata": { |
| 152 | + "cpu_count": os.cpu_count(), |
| 153 | + "system": platform.system(), |
| 154 | + "machine": platform.machine(), |
| 155 | + "python_version": str(platform.python_version()), |
| 156 | + "cuda": ( |
| 157 | + torch.cuda.get_device_properties(0).name |
| 158 | + if torch.cuda.is_available() |
| 159 | + else "not available" |
| 160 | + ), |
| 161 | + }, |
| 162 | + } |
| 163 | + plot_data(data, args.plot_path) |
199 | 164 |
|
200 | 165 |
|
201 | 166 | if __name__ == "__main__": |
|
0 commit comments