Skip to content

Commit e1c19f9

Browse files
committed
Adjust video decoder tests
Signed-off-by: Michał Szołucha <[email protected]>
1 parent 7298f05 commit e1c19f9

File tree

1 file changed

+99
-42
lines changed

1 file changed

+99
-42
lines changed

dali/test/python/decoder/test_video.py

Lines changed: 99 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import glob
2222
import os
2323
import random
24-
from itertools import cycle
24+
from itertools import cycle, product
2525
from test_utils import get_dali_extra_path, is_mulit_gpu, skip_if_m60
2626
from nose2.tools import params
2727
from nose_utils import SkipTest, attr, assert_raises
@@ -215,7 +215,7 @@ def ref_iter(epochs=1, device="cpu"):
215215
yield np.array(output[0])
216216

217217

218-
@params(("mixed", fn.experimental))
218+
@params(("mixed", fn.experimental), ("mixed", fn))
219219
def test_video_decoder(device, module):
220220
skip_if_m60()
221221
batch_size = 3
@@ -283,8 +283,8 @@ def test_pipeline():
283283

284284

285285
@attr("multi_gpu")
286-
@params("cpu", "mixed")
287-
def test_multi_gpu_video(device):
286+
@params(*product(["cpu", "mixed"], [fn.experimental.decoders.video, fn.decoders.video]))
287+
def test_multi_gpu_video(device, decoder):
288288
skip_if_m60()
289289
if not is_mulit_gpu():
290290
raise SkipTest()
@@ -308,7 +308,7 @@ def input_gen(batch_size):
308308
@pipeline_def
309309
def test_pipeline():
310310
vid = fn.external_source(device="cpu", source=input_gen(batch_size))
311-
seq = fn.experimental.decoders.video(vid, device=device)
311+
seq = decoder(vid, device=device)
312312
return seq
313313

314314
video_pipeline_0 = test_pipeline(batch_size=1, num_threads=1, device_id=0)
@@ -353,16 +353,16 @@ def test_pipeline():
353353
samples_read += batch_size
354354

355355

356-
@params("cpu", "mixed")
357-
def test_error_source_info(device):
356+
@params(*product(["cpu", "mixed"], [fn.experimental.decoders.video, fn.decoders.video]))
357+
def test_error_source_info(device, decoder):
358358
skip_if_m60()
359359
error_file = "README.txt"
360360
filenames = os.path.join(get_dali_extra_path(), "db/video/cfr/", error_file)
361361

362362
@pipeline_def
363363
def test_pipeline():
364364
data, _ = fn.readers.file(files=filenames)
365-
return fn.experimental.decoders.video(data, device=device)
365+
return decoder(data, device=device)
366366

367367
batch_size = 4
368368
p = test_pipeline(batch_size=batch_size, num_threads=1, device_id=0)
@@ -372,34 +372,61 @@ def test_pipeline():
372372

373373
@params(
374374
# Test case 1: Constant frame rate video with sequence_length
375-
*[(device, 3, cfr_files, 5, 3, 1, None, True) for device in ["cpu", "mixed"]],
375+
*[
376+
(device, 3, cfr_files, 5, 3, 1, None, True, decoder)
377+
for device in ["cpu", "mixed"]
378+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
379+
],
376380
# Test case 2: Variable frame rate video with sequence_length
377-
*[(device, 3, vfr_files, 0, 4, 2, None, True) for device in ["cpu", "mixed"]],
381+
*[
382+
(device, 3, vfr_files, 0, 4, 2, None, True, decoder)
383+
for device in ["cpu", "mixed"]
384+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
385+
],
378386
# Test case 3: Constant frame rate video with sequence_length and padding
379387
*[
380-
(device, 3, cfr_files, 0, 10, 11, pad_mode, True)
388+
(device, 3, cfr_files, 0, 10, 11, pad_mode, True, decoder)
381389
for device in ["cpu", "mixed"]
382390
for pad_mode in ["constant", "edge", "symmetric", "reflect"]
391+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
383392
],
384393
# Test case 4: Constant frame rate video with end_frame
385-
*[(device, 3, cfr_files, 5, 8, 1, None, False) for device in ["cpu", "mixed"]],
394+
*[
395+
(device, 3, cfr_files, 5, 8, 1, None, False, decoder)
396+
for device in ["cpu", "mixed"]
397+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
398+
],
386399
# Test case 5: Variable frame rate video with end_frame
387-
*[(device, 3, vfr_files, 0, 8, 2, None, False) for device in ["cpu", "mixed"]],
400+
*[
401+
(device, 3, vfr_files, 0, 8, 2, None, False, decoder)
402+
for device in ["cpu", "mixed"]
403+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
404+
],
388405
# Test case 6: Constant frame rate video with end_frame and padding
389406
*[
390-
(device, 3, cfr_files, 0, 110, 11, pad_mode, False)
407+
(device, 3, cfr_files, 0, 110, 11, pad_mode, False, decoder)
391408
for device in ["cpu", "mixed"]
392409
for pad_mode in ["constant", "edge", "symmetric", "reflect"]
410+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
393411
],
394412
# Test case 7: Random parameters for both sequence_length and end_frame
395413
*[
396-
(device, 3, cfr_files, "random", "random", "random", None, use_seq_len)
414+
(device, 3, cfr_files, "random", "random", "random", None, use_seq_len, decoder)
397415
for device in ["cpu", "mixed"]
398416
for use_seq_len in [True, False]
417+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
399418
],
400419
)
401420
def test_video_decoder_frame_start_end_stride(
402-
device, batch_size, filenames, start_frame, length_or_end, stride, pad_mode, use_sequence_length
421+
device,
422+
batch_size,
423+
filenames,
424+
start_frame,
425+
length_or_end,
426+
stride,
427+
pad_mode,
428+
use_sequence_length,
429+
decoder,
403430
):
404431
skip_if_m60()
405432
num_iters = 1
@@ -416,7 +443,7 @@ def get_batch():
416443
@pipeline_def
417444
def test_pipeline():
418445
encoded = fn.external_source(source=get_batch, device="cpu")
419-
reference = fn.experimental.decoders.video(encoded, device=device)
446+
reference = decoder(encoded, device=device)
420447

421448
start_frame_arg = (
422449
fn.random.uniform(range=(0, 5), dtype=types.INT32)
@@ -436,7 +463,7 @@ def test_pipeline():
436463
fn.random.uniform(range=(1, 4), dtype=types.INT32) if stride == "random" else stride
437464
)
438465

439-
decoded = fn.experimental.decoders.video(
466+
decoded = decoder(
440467
encoded,
441468
device=device,
442469
start_frame=start_frame_arg,
@@ -474,22 +501,43 @@ def test_pipeline():
474501

475502
@params(
476503
# Test single constant frame rate video with simple frame indices
477-
*[(device, 3, cfr_files, [0, 5, 10], "none") for device in ["cpu", "mixed"]],
504+
*[
505+
(device, 3, cfr_files, [0, 5, 10], "none", decoder)
506+
for device in ["cpu", "mixed"]
507+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
508+
],
478509
# Test multiple variable frame rate videos with non-sequential frames
479-
*[(device, 3, vfr_files, [2, 4, 8], "none") for device in ["cpu", "mixed"]],
510+
*[
511+
(device, 3, vfr_files, [2, 4, 8], "none", decoder)
512+
for device in ["cpu", "mixed"]
513+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
514+
],
480515
# Test single constant frame rate video with non-monotonic frame indices
481-
*[(device, 3, cfr_files, [0, 5, 10, 8, 7, 6], "none") for device in ["cpu", "mixed"]],
516+
*[
517+
(device, 3, cfr_files, [0, 5, 10, 8, 7, 6], "none", decoder)
518+
for device in ["cpu", "mixed"]
519+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
520+
],
482521
# Test single constant frame rate video with repeated frame indices
483-
*[(device, 3, cfr_files, [0, 5, 10, 8, 10, 5, 0, 0], "none") for device in ["cpu", "mixed"]],
522+
*[
523+
(device, 3, cfr_files, [0, 5, 10, 8, 10, 5, 0, 0], "none", decoder)
524+
for device in ["cpu", "mixed"]
525+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
526+
],
484527
# Test multiple constant frame rate videos with random indices
485-
*[(device, 3, cfr_files, None, "none") for device in ["cpu", "mixed"]],
528+
*[
529+
(device, 3, cfr_files, None, "none", decoder)
530+
for device in ["cpu", "mixed"]
531+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
532+
],
486533
# Test out of bounds frame indices
487534
*[
488-
(device, 3, cfr_files, [0, 100, 1, 100, 2, 100, 3, 100], "constant")
535+
(device, 3, cfr_files, [0, 100, 1, 100, 2, 100, 3, 100], "constant", decoder)
489536
for device in ["cpu", "mixed"]
537+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
490538
],
491539
)
492-
def test_video_decoder_frame_indices(device, batch_size, filenames, frames, pad_mode):
540+
def test_video_decoder_frame_indices(device, batch_size, filenames, frames, pad_mode, decoder):
493541
skip_if_m60()
494542
num_iters = 1
495543
batch = []
@@ -505,13 +553,13 @@ def get_batch():
505553
@pipeline_def
506554
def test_pipeline():
507555
encoded = fn.external_source(source=get_batch, device="cpu")
508-
reference = fn.experimental.decoders.video(encoded, device=device)
556+
reference = decoder(encoded, device=device)
509557
if frames is None:
510558
frames_shape = fn.random.uniform(range=(1, 10), shape=(1,), dtype=types.INT32)
511559
frames_arg = fn.random.uniform(range=(0, 10), shape=frames_shape, dtype=types.INT32)
512560
else:
513561
frames_arg = frames
514-
decoded = fn.experimental.decoders.video(
562+
decoded = decoder(
515563
encoded, device=device, frames=frames_arg, pad_mode=pad_mode, fill_value=fill_value
516564
)
517565
return (reference, decoded, frames_arg)
@@ -543,11 +591,19 @@ def test_pipeline():
543591

544592
@params(
545593
# Test single constant frame rate video with start_frame near the end
546-
*[(device, 3, cfr_files, 1, 1000) for device in ["cpu", "mixed"]],
594+
*[
595+
(device, 3, cfr_files, 1, 1000, decoder)
596+
for device in ["cpu", "mixed"]
597+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
598+
],
547599
# Test multiple variable frame rate videos with large stride
548-
*[(device, 3, vfr_files, 2, 1000) for device in ["cpu", "mixed"]],
600+
*[
601+
(device, 3, vfr_files, 2, 1000, decoder)
602+
for device in ["cpu", "mixed"]
603+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
604+
],
549605
)
550-
def test_video_decoder_no_padding(device, batch_size, filenames, stride, sequence_length):
606+
def test_video_decoder_no_padding(device, batch_size, filenames, stride, sequence_length, decoder):
551607
skip_if_m60()
552608
batch = []
553609
for i in range(batch_size):
@@ -561,9 +617,9 @@ def get_batch():
561617
def test_pipeline():
562618
encoded = fn.external_source(source=get_batch, device="cpu")
563619
# Get full video first as reference
564-
reference = fn.experimental.decoders.video(encoded, device=device, stride=stride)
620+
reference = decoder(encoded, device=device, stride=stride)
565621
# Request frames that would exceed video length
566-
decoded = fn.experimental.decoders.video(
622+
decoded = decoder(
567623
encoded,
568624
device=device,
569625
stride=stride,
@@ -582,8 +638,8 @@ def test_pipeline():
582638
compare_videos(ref, actual)
583639

584640

585-
@params("cpu", "mixed")
586-
def test_incompatible_args(device):
641+
@params(*product(["cpu", "mixed"], [fn.experimental.decoders.video, fn.decoders.video]))
642+
def test_incompatible_args(device, decoder):
587643
skip_if_m60()
588644
batch = []
589645
with open(cfr_files[0], "rb") as f:
@@ -598,7 +654,7 @@ def test_pipeline(
598654
frames=None, start_frame=None, stride=None, sequence_length=None, end_frame=None
599655
):
600656
encoded = fn.external_source(source=get_batch, device="cpu")
601-
decoded = fn.experimental.decoders.video(
657+
decoded = decoder(
602658
encoded,
603659
device=device,
604660
frames=frames,
@@ -652,8 +708,8 @@ def test_pipeline(
652708
pipe.build()
653709

654710

655-
@params("cpu", "mixed")
656-
def test_multichannel_fill_value(device):
711+
@params(*product(["cpu", "mixed"], [fn.experimental.decoders.video, fn.decoders.video]))
712+
def test_multichannel_fill_value(device, decoder):
657713
skip_if_m60()
658714
batch = []
659715
batch_size = 3
@@ -670,13 +726,13 @@ def get_batch():
670726
@pipeline_def
671727
def test_pipeline():
672728
encoded = fn.external_source(source=get_batch, device="cpu")
673-
decoded0 = fn.experimental.decoders.video(
729+
decoded0 = decoder(
674730
encoded,
675731
stride=10,
676732
device=device,
677733
pad_mode="none",
678734
)
679-
decoded1 = fn.experimental.decoders.video(
735+
decoded1 = decoder(
680736
encoded,
681737
device=device,
682738
stride=10,
@@ -786,18 +842,19 @@ def compare_frames(frame, ref_frame, frame_idx, diff_step=2, threshold=0.03):
786842

787843
@params(
788844
*[
789-
(device, codec, start_frame, sequence_length, end_frame, stride)
845+
(device, codec, start_frame, sequence_length, end_frame, stride, decoder)
790846
for device in ["cpu", "mixed"]
791847
for codec in ["h264", "hevc", "vp8", "vp9", "av1", "mpeg4"]
792848
for start_frame, sequence_length, end_frame, stride in [
793849
(None, None, None, None), # Default case
794850
(5, 3, None, 2), # start_frame, sequence_length and stride
795851
(5, None, 10, 2), # start_frame, end_frame and stride
796852
]
853+
for decoder in [fn.experimental.decoders.video, fn.decoders.video]
797854
]
798855
)
799856
def test_decoder_operator_codec_support(
800-
device, codec, start_frame, sequence_length, end_frame, stride
857+
device, codec, start_frame, sequence_length, end_frame, stride, decoder
801858
):
802859
skip_if_m60()
803860
filenames = codec_files[codec]
@@ -823,7 +880,7 @@ def get_batch():
823880
@pipeline_def
824881
def decoder_pipeline():
825882
files = fn.external_source(source=get_batch)
826-
videos = fn.experimental.decoders.video(
883+
videos = decoder(
827884
files,
828885
device=device,
829886
start_frame=start_frame,

0 commit comments

Comments
 (0)