Skip to content

Commit

Permalink
Add proper error handling where there are no valid sequences in the V…
Browse files Browse the repository at this point in the history
…ideoReader (NVIDIA#2180)

- adds an enforce to check if there is any valid sequence in the VideoReader
- adds a test

Signed-off-by: Janusz Lisiecki <[email protected]>
  • Loading branch information
JanuszL authored Aug 6, 2020
1 parent bce39d2 commit 8e483a8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
3 changes: 3 additions & 0 deletions dali/operators/reader/loader/video_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ class VideoLoader : public Loader<GPUBackend, SequenceWrapper> {
codecpar(stream)->height, codecpar(stream)->width});
}
}
DALI_ENFORCE(!frame_starts_.empty(), "There are no valid sequences in the provided "
"dataset, check the length of the available videos and the requested sequence "
"length.");


const auto& file = get_or_open_file(file_info_[0].video_file);
Expand Down
35 changes: 15 additions & 20 deletions dali/operators/reader/video_reader_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,25 @@ class VideoReader : public DataReader<GPUBackend, SequenceWrapper> {
DALI_ENFORCE(dtype_ == DALI_FLOAT || dtype_ == DALI_UINT8,
"Data type must be FLOAT or UINT8.");

enable_label_output_ = !file_root_.empty() || !file_list_.empty();
DALI_ENFORCE(enable_label_output_ || !enable_frame_num_,
"frame numbers can be enabled only when "
"`file_list` or `file_root` argument is passed");
DALI_ENFORCE(enable_label_output_ || !enable_timestamps_,
"timestamps can be enabled only when "
"`file_list` or `file_root` argument is passed");
enable_label_output_ = !file_root_.empty() || !file_list_.empty();
DALI_ENFORCE(enable_label_output_ || !enable_frame_num_,
"frame numbers can be enabled only when "
"`file_list` or `file_root` argument is passed");
DALI_ENFORCE(enable_label_output_ || !enable_timestamps_,
"timestamps can be enabled only when "
"`file_list` or `file_root` argument is passed");

// TODO(spanev): Factor out the constructor body to make VideoReader compatible with lazy_init.
try {
loader_ = InitLoader<VideoLoader>(spec, filenames_);
} catch (std::exception &e) {
DALI_WARN(std::string(e.what()));
throw;
}
loader_ = InitLoader<VideoLoader>(spec, filenames_);

if (enable_label_output_) {
label_shape_ = uniform_list_shape(batch_size_, {1});
if (enable_label_output_) {
label_shape_ = uniform_list_shape(batch_size_, {1});

if (enable_frame_num_)
frame_num_shape_ = label_shape_;
if (enable_timestamps_)
timestamp_shape_ = uniform_list_shape(batch_size_, {count_});
}
if (enable_frame_num_)
frame_num_shape_ = label_shape_;
if (enable_timestamps_)
timestamp_shape_ = uniform_list_shape(batch_size_, {count_});
}
}

inline ~VideoReader() override = default;
Expand Down
16 changes: 10 additions & 6 deletions dali/test/python/test_video_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ def test_simple_videopipeline():
pipe.build()
for i in range(ITER):
print("Iter " + str(i))
pipe_out = pipe.run()
_ = pipe.run()
del pipe

def test_wrong_length_sequence_videopipeline():
pipe = VideoPipe(batch_size=BATCH_SIZE, data=VIDEO_FILES, sequence_length=100000)
assert_raises(RuntimeError, pipe.build)

def check_videopipeline_supported_type(dtype):
pipe = VideoPipe(batch_size=BATCH_SIZE, data=VIDEO_FILES, dtype=dtype)
pipe.build()
for i in range(ITER):
print("Iter " + str(i))
pipe_out = pipe.run()
_ = pipe.run()
del pipe

SUPPORTED_TYPES = [types.DALIDataType.FLOAT, types.DALIDataType.UINT8]
Expand All @@ -102,23 +106,23 @@ def test_file_list_videopipeline():
pipe.build()
for i in range(ITER):
print("Iter " + str(i))
pipe_out = pipe.run()
_ = pipe.run()
del pipe

def test_step_video_pipeline():
pipe = VideoPipe(batch_size=BATCH_SIZE, data=VIDEO_FILES, step=1)
pipe.build()
for i in range(ITER):
print("Iter " + str(i))
pipe_out = pipe.run()
_ = pipe.run()
del pipe

def test_stride_video_pipeline():
pipe = VideoPipe(batch_size=BATCH_SIZE, data=VIDEO_FILES, stride=3)
pipe.build()
for i in range(ITER):
print("Iter " + str(i))
pipe_out = pipe.run()
_ = pipe.run()
del pipe

def test_multiple_resolution_videopipeline():
Expand All @@ -127,7 +131,7 @@ def test_multiple_resolution_videopipeline():
pipe.build()
for i in range(ITER):
print("Iter " + str(i))
pipe_out = pipe.run()
_ = pipe.run()
except Exception as e:
if str(e) == "Decoder reconfigure feature not supported":
print("Multiple resolution test skipped")
Expand Down

0 comments on commit 8e483a8

Please sign in to comment.