kedro-org / kedro-org/kedro-plugins

VideoDataSet with GeneratorVideo save is broken

Open
#232 4 comments 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
Python
Stars
119
Forks
136
Avg merge
4d 10h
Merged PRs (30d)
5

Description

## Description
I wasn't sure if I should put this issue here or in the Kedro core repo since the `VideoDataSet` has been broken after a change in Kedro core.

Shortly, the video dataset has multiple backends that can be saved. One of them is the `GeneratorVideo` which is an `Iterable`.

In commit fcf3ab4a9 "Enable the usage of generator functions in nodes ([#2161](https://github.com/kedro-org/kedro/pull/2161))" by @idanov the runner functionality was changed to handle generator datasets.

Snippet from `_run_node_sequential` in `kedro/runner/runner.py`:
```python
items: Iterable = outputs.items()
# if all outputs are iterators, then the node is a generator node
if all(isinstance(d, Iterator) for d in outputs.values()):
# Python dictionaries are ordered so we are sure
# the keys and the chunk streams are in the same order
# [a, b, c]
keys = list(outputs.keys())
# [Iterator[chunk_a], Iterator[chunk_b], Iterator[chunk_c]]
streams = list(outputs.values())
# zip an endless cycle of the keys
# with an interleaved iterator of the streams
# [(a, chunk_a), (b, chunk_b), ...] until all outputs complete
items = zip(it.cycle(keys), interleave(*streams))

for name, data in items:
hook_manager.hook.before_dataset_saved(dataset_name=name, data=data, node=node)
catalog.save(name, data)
hook_manager.hook.after_dataset_saved(dataset_name=name, data=data, node=node)
return node
```

## Context
I have not had time yet to dive into the code and see what is actually happening, or how we should treat it in these situations. The effect now is that the runner will yield the first frame from the video and try to save that frame to the Video Dataset which is not possible.

The quick and dirty way to fix it would be to remove the `__iter__` method from the `GeneratorVideo` class and implement some special logic in the `VideoDataSet` class to iterate it correctly. This would however not be very nice from a user perspective since `iter(video)` would then result in an indexed-iteration of the generator.

## Steps to Reproduce
1. Create a `GeneratorVideo`
2. Create a `VideoDataSet`
3. Call save on the video dataset with the generator video

Contributor guide

Open the contributing guide

Research direction

Start in kedro/runner/runner.py at _run_node_sequential and trace how GeneratorVideo and VideoDataSet are handled during catalog.save. Reproduce the three listed steps, then determine how generator-backed video data should pass through the runner without saving the first frame as a standalone value. Done means calling save with a GeneratorVideo preserves the video backend behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.