MCPcopy Create free account
hub / github.com/NVIDIA/DALI / compare_experimental_to_legacy_reader

Function compare_experimental_to_legacy_reader

dali/test/python/test_video_reader.py:73–148  ·  view source on GitHub ↗
(device, batch_size, **kwargs)

Source from the content-addressed store, hash-verified

71
72
73def compare_experimental_to_legacy_reader(device, batch_size, **kwargs):
74 @pipeline_def(batch_size=batch_size, num_threads=3, device_id=0, prefetch_queue_depth=1)
75 def video_reader_pipeline():
76 kwargs_legacy = dict(kwargs) # Make a copy to avoid modifying the original
77 if "file_list_format" in kwargs:
78 file_list_format = kwargs["file_list_format"]
79 del kwargs_legacy["file_list_format"]
80 if file_list_format == "frames":
81 kwargs_legacy["file_list_frame_num"] = True
82 elif file_list_format == "timestamps":
83 kwargs_legacy["file_list_frame_num"] = False
84 file_list_rounding = kwargs.get("file_list_rounding", "start_down_end_up")
85 del kwargs_legacy["file_list_rounding"]
86 kwargs_legacy["file_list_include_preceding_frame"] = (
87 file_list_rounding == "start_down_end_up"
88 )
89 if "pad_mode" in kwargs:
90 pad_mode = kwargs["pad_mode"]
91 del kwargs_legacy["pad_mode"]
92 if pad_mode == "constant":
93 kwargs_legacy["pad_sequences"] = True
94 elif pad_mode == "none":
95 kwargs_legacy["pad_sequences"] = False
96 else:
97 raise ValueError(f"Unsupported pad_mode {pad_mode} in legacy reader")
98
99 outs0 = fn.readers.video(
100 device="gpu",
101 name="legacy_reader",
102 **kwargs_legacy,
103 )
104 if isinstance(outs0, DataNode):
105 outs0 = (outs0,)
106
107 outs1 = fn.experimental.readers.video(
108 device=device,
109 name="experimental_reader",
110 **kwargs,
111 )
112 if isinstance(outs1, DataNode):
113 outs1 = (outs1,)
114
115 return tuple(list(outs0) + list(outs1))
116
117 pipe = video_reader_pipeline()
118 pipe.build()
119 legacy_epoch_size = pipe.reader_meta("legacy_reader")["epoch_size"]
120 experimental_epoch_size = pipe.reader_meta("experimental_reader")["epoch_size"]
121 # The readers calculate the number of frames in the epoch differently,
122 # so we need to take the minimum of the two.
123 epoch_size = min(legacy_epoch_size, experimental_epoch_size)
124 for i in range(epoch_size):
125 outs = pipe.run()
126 n = len(outs)
127 assert n % 2 == 0
128 outs_legacy = outs[: n // 2]
129 outs_experimental = outs[n // 2 :]
130 assert len(outs_legacy) == len(outs_experimental)

Calls 6

reader_metaMethod · 0.80
video_reader_pipelineFunction · 0.70
compare_framesFunction · 0.70
minFunction · 0.50
buildMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected