Dali: How to specify the start frame without specifying the end in VideoReader?

Created on 9 Sep 2020  ·  19Comments  ·  Source: NVIDIA/DALI

Hello. I have a video where the credits start (~10 seconds). I would not want to process them, and start immediately with 10 seconds. You have
https://docs.nvidia.com/deeplearning/dali/user-guide/docs/supported_ops.html?highlight=videoreader#nvidia.dali.ops.VideoReader
there are excellent explanations for how this can be done. But I don't know the length of the video. I can find it out, of course, but suddenly you can do it without calling additional methods.

Is there a way to do this? I tried

file_list= video_directory + f'/{name}' + f' 0 100  -1 \n' 

and

file_list= video_directory + f'/{name}' + f' 0 100  \n' 

but I get an error.

I would appreciate any information

enhancement

All 19 comments

Hi,
It is not possible now, but this PR should add this.

Please test DALI nightly build after it is merged and see if that helps your use case.

Thank you very much!! And how can I find out that PR was added to the nightly version?

I would download the nightly build with the data that follows the date when the commit has been merged. It is still under review but I hope to get it merged soon.

Hello. I saw that Your changes were added to the night version. I installed it, but for some reason nothing has changed

print(nvidia.dali.__version__)
file_list = list(filter(lambda x: x.endswith(('.mp4', '.avi', '.mkv', '.m4v')), os.listdir(video_folder)))
file_list_txt = ""
for i, name in enumerate(file_list):
    file_list_txt += video_folder + f'/{name}' + f' {i} 200 \n'
tf = tempfile.NamedTemporaryFile()
tf.write(str.encode(file_list_txt))
tf.flush()

vr = VideoPipe(batch_size=32, num_threads=2, device_id=0, data=tf.name)
vr.build()

output

0.27.0dev.20200909
Traceback (most recent call last):
  File "/home/MrNeither/PycharmProjects/DALItest/Video2Features/main_DALI.py", line 194, in <module>
    vr.save_videos(video_folder=video_path, save_path=save_path)
  File "/home/MrNeither/PycharmProjects/DALItest/Video2Features/main_DALI.py", line 124, in save_videos
    pipe.build()
  File "/home/MrNeither/anaconda3/envs/testWithDali/lib/python3.8/site-packages/nvidia/dali/pipeline.py", line 479, in build
    self._pipe.Build(self._names_and_devices)
RuntimeError: Critical error when building pipeline:
Error when constructing operator: VideoReaderResize encountered:
[/opt/dali/dali/operators/reader/loader/video_loader.cc:177] The allowed file list format is:
file_name label(int) start_time(float) end_time(float)
or
file_name label(int)
Example:
/home/nvidia/salvador.mp4 0 5.2 10.5
/home/nvidia/dali.mp4 1

It was merged on September 10, while your nightly is 20200909. We have some problems with the recent nightly builds but we hope to resolve them soon. This change should be included in this week nightly for sure, so stay tuned.

Nightly build are back on track. Please check the latest and see how that works.

@JanuszL Thank you so much :) Everything works. You also added the possibility of negative values, as in the slice list.
The last question may be indirectly related to this topic. Is there any way I can tell VideoReader that it doesn't need to start reading again after reading the video?
I would like to use VideoReader when evaluating the quality of the model, and I need to run my model without argument once for each frame in videos.I understand that there will be no increase in speed but I would like to use DALI in train and eval in the same way, without change pipeline logic
Thank you for your work!

Is there any way I can tell VideoReader that it doesn't need to start reading again after reading the video?

Do you mean to traverse the data set once? You can check reader_meta to see how many samples there is in the dataset and read only this amount. There is no way to ask the bare pipeline to stop, it just wraps up.

reader_meta return me

{'Reader': {'epoch_size': 24, 'epoch_size_padded': 24, 'number_of_shards': 1, 'shard_id': 0, 'pad_last_batch': 0, 'stick_to_shard': 0}}

In my folder i have 3 videos, which parameter is informative?

Sorry, I understand. Epoch_size shows how many epochs are needed for a single run

Thank you so much for your help, I figured it out

Epoch_size shows the data set size (number of distinct samples the readers see). If you run multi-GPU you need to divide it by the number of shards.

@JanuszL Will you close the issue yourself, or should I do it?

I will close when 0.27 is out, if that is not a problem for you.

Hello there. Sorry again, but I still have the same question with ReaderMeta. You said that ReaderMeta shows the number of samples in the dataset. As I understand it, it does not take into account batch size. This is very misleading, because I'm used to counting epoch size as the number of bootloader epochs.
Do I understand correctly that if I have a batch size of 32, then in order to find out the number of loader epochs, I must divide epoch size by batch size?
I checked that the values match in my case, but I'm not sure if the are correct.

You said that ReaderMeta shows the number of samples in the dataset.

For given shard to be exact. And yes to get the number of iterations you need to divide it by the batch size.

Thank you again!

DALI 0.27 is available. It should address your request.

Was this page helpful?
0 / 5 - 0 ratings