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

Faster DataLoader class #57

Open
nbren12 opened this issue Jan 14, 2019 · 0 comments
Open

Faster DataLoader class #57

nbren12 opened this issue Jan 14, 2019 · 0 comments

Comments

@nbren12
Copy link
Owner

nbren12 commented Jan 14, 2019

cc @sarenehan

I think the main bottleneck in our training speed is the training data loader. This is probably because we are getting cache-misses when collecting the data at random indices. To speed this up, we will probably need to store the pre-shuffled data on disk.

I tried writing some code to do this, but I was running out of memory on the last step:

from itertools import product
from random import shuffle

import numpy as np
import xarray as xr

ds = xr.open_dataset("./data/processed/training.nc")

# construct the indices
x = range(len(ds.x))
y = range(len(ds.y))
z = range(len(ds.z))
time = range(len(ds.time))

indices = list(product(x, y, time))
shuffle(indices)
transposed = list(zip(*indices))

# construct xarray indexers following 
# http://xarray.pydata.org/en/stable/indexing.html#more-advanced-indexing
dims = ['x', 'y', 'time']
indexers = {
    dim: xr.DataArray(
        np.array(index),
        dims="sample",
        coords={'sample': np.arange(len(indices))})
    for dim, index in zip(dims, transposed)
}

# This step runs out of memory
shuffled_ds = ds.isel(**indexers)

To speed this up, we will probably need to do a couple of steps, with on-disk caching for each step:

  1. Transpose the data (time, z, y, x) --> (time, y, x, z)
  2. Reshape (time, y, x, z) --> (batch, time_and_next, z)
  3. Shuffle along batch dimension.
nbren12 added a commit that referenced this issue Jan 22, 2019
This commits starts my work on a faster data loader.

Related to #57.
nbren12 added a commit that referenced this issue Jan 25, 2019
This commits starts my work on a faster data loader.

Related to #57.
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

No branches or pull requests

1 participant