-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add audb.stream() and audb.DatabaseIterator #448
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit 2bfc800.
Co-authored-by: ChristianGeng <[email protected]>
ChristianGeng
approved these changes
Aug 21, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All points that were there have been addressed in separate conversations.
As the entire stream module and its functionality is new, there needn't be additional checks with respect to integration with other packges.
Therefore I will approve the MR.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to audeering/audformat#440
Provides pseudo-streaming functionality to
audb
with the new functionaudb.stream()
, which requires that the user selects a table to stream. It returns the newaudb.DatabaseIterator
object.The streaming functionality
Example:
It achieves this by
batch_size
argument) from the table fileNote regarding 1.: downloading the table first to cache makes it easy to add support for parquet and csv tables. If we want to stream just a part of the parquet table as proposed in audeering/audbcards#59 (comment), we can add this feature later on. Also note for loading the csv file, I'm only using
pd.read_csv()
as this provides an easy solution,pyarrow.csv
can fail for some csv files, and large tables are supposed to be stored as parquet files anyway.Random table rows and buffering
audb.stream()
provides the argumentshuffle
that allows to stream the data in a random order. As we cannot read random lines from the table files, this requires that we first read a larger part of the table into a buffer (as given by thebuffer_size
argument), and shuffling the buffer.Differences between audformat.Database and audb.DatabaseIterator
audb.DatabaseIterator
inherits fromaudformat.Database
and adds a__next__()
method,that uses
audb
internal functions likeaudb.load_media()
to allow streaming of the database.In addition, it limits the database object to the selected table.
The biggest difference for the user is that
list(db)
will now result in something different then before, as we also need to overwrite__iter__()
in order to make the iteration work:But I think it should be fine for the user, as the focus is streaming and there it is important that the following works:
Loading whole dependency table
In audeering/audformat#440, I proposed to also load only the part of the dependency table that is needed for table and the media files to download. As this requires some effort, and we also don't have an easy way of publishing a database, for which the dependency table does not fit into memory, I would skip that for now.
Possible improvement of code
I decided to implement streaming support directly in
audb
and not first inaudformat
(e.g. as part ofaudformat.Table.get(..., start=..., samples=...)
). The main reason is that for parquet files we cannot easily specify a beginning and end line, but we need to iterate through the file.As a consequence, I needed to copy some code from
audformat
for post-processing after reading from csv and parquet files, and code for pre-paring reading from the csv file. This can be enhanced at a later stage, by providing this code insideaudformat
as hidden methods, which we then can reuse here inaudb
. But for now, I would propose to go with my code, and improveaudformat
afterwards.Docstrings
Complete docstring of the new
audb.stream()
function:Beginning of the docstring of the new
audb.DatabaseIterator
class:New sub-section in usage documentation under "Load a database" section: