Skip to content

ShuffleBuffer can not iterate twice #4841

@blezek

Description

@blezek

Describe the bug
ShuffleBuffer overwrites self.data on the first iteration and can not be iterated twice.

data is originally set to the source data, but overwritten during the first iteration.

The tests do not cover iterating through twice.

To Reproduce

import numpy as np
import monai
from monai.data import GridPatchDataset, DataLoader, PatchIter

# image-level dataset
images = [np.zeros(16, dtype=float).reshape(1, 4, 4),
          np.ones(16, dtype=float).reshape(1, 4, 4)]
patch_iter = PatchIter(patch_size=(2, 2), start_pos=(0, 0))

# construct the dataset
ds = GridPatchDataset(data=images,
                      patch_iter=patch_iter, with_coordinates=False
                      )

dss = monai.data.ShuffleBuffer(ds, buffer_size = 30, seed=42)

dataloader = DataLoader(dss, batch_size=1, num_workers=0)

# use the grid patch dataset
for item in dataloader:
    print(f"sum: {item[0].sum()} shape {item[0].shape}")


print ( "==== second pass, should produce output, but is empty")

for item in dataloader:
    print(f"sum: {item[0].sum()} shape {item[0].shape}")

Expected behavior
ShuffleBuffer should iterate through the dataset twice.

Environment

Slightly redacted.

================================
Printing MONAI config...
================================
MONAI version: 0.9.1
Numpy version: 1.21.4
Pytorch version: 1.10.0+cu113
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 356d2d2f41b473f588899d705bbc682308cee52c
Optional dependencies:
Pytorch Ignite version: 0.4.4
Nibabel version: 3.2.1
scikit-image version: 0.19.0
Pillow version: 8.4.0
Tensorboard version: 2.7.0
gdown version: 4.2.0
TorchVision version: 0.11.1+cu102
tqdm version: 4.62.3
lmdb version: 1.2.1
psutil version: 5.9.0
pandas version: 1.3.4
einops version: 0.3.2
transformers version: 4.12.3
mlflow version: NOT INSTALLED or UNKNOWN VERSION.
pynrrd version: NOT INSTALLED or UNKNOWN VERSION.
For details about installing the optional dependencies, please visit:
    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions