Skip to content
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

Expose api for custom datasets #1288

Closed
wants to merge 4 commits into from
Closed

Expose api for custom datasets #1288

wants to merge 4 commits into from

Conversation

pxl-th
Copy link
Member

@pxl-th pxl-th commented Jul 21, 2020

Expose Flux.Data.nobs and Flux.Data.getobs to be able to make custom datasets compatible with DataLoader.

PR Checklist

  • Tests are added
  • Entry in NEWS.md
  • Documentation, if applicable
  • Final review from @dhairyagandhi96 (for API changes).

@CarloLucibello
Copy link
Member

The interface could just be Flux._nobs, Flux._getobs and Base.eltype.
No need of subtyping AbstractArray then.
We can rename _nobs and _getobs to nobs and getobs.
By the way, we should specify that the interface is just to create DataLoader compatible data structures

@pxl-th
Copy link
Member Author

pxl-th commented Jul 21, 2020

Yes, this would be a better solution) I've changed code accordingly

@pxl-th pxl-th changed the title Add documentation for custom dataset Expose api for custom datasets Jul 21, 2020
@CarloLucibello
Copy link
Member

@DhairyaLGandhi are you ok with the interface we expose here?

Copy link
Member

@DhairyaLGandhi DhairyaLGandhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, this seems like a nice approach. I added a couple thoughts.

There needs to be an interface that can handle a more functional and generic approach. How would I make a lazy loaded dataset? How would putting things into channels and taking from there work? Things of that nature.

to make it compatible with `DataLoader`.

```julia
struct ZerosDataset{T, N}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we name this as CustomDataset, or add a line that says what it is intended to return (just an array of zeros)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

total::Int
end

Base.eltype(::DataLoader{ZerosDataset{T, N}}) where {T, N} = Array{T, N}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the eltype to be defined separately?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because by default eltype of the dataloader is the type of data that is holds, not the type of data that data returns.
Thus it causes type instability and issues with things like @inferred, collect, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little uncomfortable having to define eltypes like that, could we maybe make it part of the signature because strictly speaking, the elements of the data loader are the mini batches, which isn't represented by the T here.

@CarloLucibello
Copy link
Member

There needs to be an interface that can handle a more functional and generic approach. How would I make a lazy loaded dataset? How would putting things into channels and taking from there work? Things of that nature.

I think these are orthogonal concerns possibly related to the implementation of the Dataset itself and not the Dataloader, and I wouldn't charge this PR with solving things we haven't yet discussed

@ToucheSir
Copy link
Member

Instead of defining something custom, it would be best to wait for JuliaML/LearnBase.jl#44. Ideally Flux itself wouldn't contain any data loading functionality (see also: MLDatasets removal) and depend on a library (much like we're trying to do with Optimisers.jl).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants