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

Use preprocessed and cached tfrecord datasets with PyTorch #280

Open
ampersandmcd opened this issue Jun 24, 2024 · 1 comment
Open

Use preprocessed and cached tfrecord datasets with PyTorch #280

ampersandmcd opened this issue Jun 24, 2024 · 1 comment

Comments

@ampersandmcd
Copy link

  • IceNet version: 0.2.8
  • Python version: 3.11.7
  • Operating System: CentOS Linux 7 (BAS HPC)

Description

To accelerate training with PyTorch, it would be useful to make use of the preprocessed and cached tfrecord datasets we've produced for operational Tensorflow training! Loading from these tfrecord files is (should be?) much faster than loading from NetCDF files on the fly using the generate_sample logic in, e.g., the DaskMultiWorkerLoader.generate_sample defined in data/loaders/dask.py which must perform a decent amount of computation.

What I Did

I've implemented an IterableIceNetDatasetPyTorch class which inherits from torch.utils.data.IterableDataset as a first go, and will link it below in a pull request. The following script demonstrates its use and can easily be stepped through in a debugger. The batching logic works properly with torch.utils.data.DataLoader in the script below, but I've seen some weird behaviour (overrunning the number of samples that should be generated per epoch) during training runs when num_workers > 1 in the torch.utils.data.DataLoader so there's room to improve this first implementation.

import os
import torch
from utils import IterableIceNetDataSetPyTorch

dataset_config = "dataset_config.exp23_south.json"

ds = IterableIceNetDataSetPyTorch(dataset_config, "test", batch_size=4, shuffling=False)
dl = torch.utils.data.DataLoader(ds, batch_size=4, shuffle=False)

for i, batch in enumerate(dl):
    x, y, sw = batch
    print(x, y, sw)
    print(i)
@JimCircadian
Copy link
Member

CC @bnubald who has done some work in this area already

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 a pull request may close this issue.

2 participants