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

Function test_video_decoder_frame_indices

dali/test/python/decoder/test_video.py:519–568  ·  view source on GitHub ↗
(device, batch_size, filenames, frames, pad_mode)

Source from the content-addressed store, hash-verified

517 ],
518)
519def test_video_decoder_frame_indices(device, batch_size, filenames, frames, pad_mode):
520 skip_if_m60()
521 num_iters = 1
522 batch = []
523 for i in range(batch_size):
524 with open(filenames[i % len(filenames)], "rb") as f:
525 batch.append(np.frombuffer(f.read(), dtype=np.uint8))
526
527 def get_batch():
528 return batch
529
530 fill_value = [118, 185, 0]
531
532 @pipeline_def
533 def test_pipeline():
534 encoded = fn.external_source(source=get_batch, device="cpu")
535 reference = fn.experimental.decoders.video(encoded, device=device)
536 if frames is None:
537 frames_shape = fn.random.uniform(range=(1, 10), shape=(1,), dtype=types.INT32)
538 frames_arg = fn.random.uniform(range=(0, 10), shape=frames_shape, dtype=types.INT32)
539 else:
540 frames_arg = frames
541 decoded = fn.experimental.decoders.video(
542 encoded, device=device, frames=frames_arg, pad_mode=pad_mode, fill_value=fill_value
543 )
544 return (reference, decoded, frames_arg)
545
546 pipe = test_pipeline(batch_size=batch_size, num_threads=3, device_id=0)
547 for _ in range(num_iters):
548 out0, out1, frames_arg = (o.as_cpu() for o in pipe.run())
549 # Verify each sample in the batch
550 for i in range(batch_size):
551 full_video = out0.at(i)
552 F, H, W, C = full_video.shape
553 out = out1.at(i)
554 frames = frames_arg.at(i)
555 # Get frames at specified indices for reference
556 if pad_mode == "none":
557 for f in frames:
558 assert f < full_video.shape[0]
559 out_reference = full_video[frames]
560 else:
561 padding = np.full((H, W, C), fill_value, dtype=np.uint8)
562 out_reference = np.zeros((len(frames), H, W, C), dtype=np.uint8)
563 for f in range(len(frames)):
564 if frames[f] < F:
565 out_reference[f] = full_video[frames[f]]
566 else:
567 out_reference[f] = padding
568 compare_videos(out_reference, out)
569
570
571@params(

Callers

nothing calls this directly

Calls 7

skip_if_m60Function · 0.90
compare_videosFunction · 0.85
readMethod · 0.80
test_pipelineFunction · 0.70
appendMethod · 0.45
runMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected