2020-10-13 11:18:07 +00:00
|
|
|
# Copyright The PyTorch Lightning team.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2020-10-04 01:17:24 +00:00
|
|
|
import torch
|
2022-05-02 15:42:12 +00:00
|
|
|
from torch.utils.data import Dataset, IterableDataset
|
|
|
|
|
|
|
|
from pytorch_lightning.demos.boring_classes import BoringDataModule, BoringModel, ManualOptimBoringModel, RandomDataset
|
2021-01-13 06:48:37 +00:00
|
|
|
|
2022-05-02 15:42:12 +00:00
|
|
|
__all__ = ["BoringDataModule", "BoringModel", "ManualOptimBoringModel", "RandomDataset"]
|
2020-10-04 01:17:24 +00:00
|
|
|
|
|
|
|
|
2020-10-06 01:30:41 +00:00
|
|
|
class RandomDictDataset(Dataset):
|
2021-08-10 06:39:00 +00:00
|
|
|
def __init__(self, size: int, length: int):
|
2020-10-06 01:30:41 +00:00
|
|
|
self.len = length
|
|
|
|
self.data = torch.randn(length, size)
|
|
|
|
|
|
|
|
def __getitem__(self, index):
|
|
|
|
a = self.data[index]
|
|
|
|
b = a + 2
|
2021-07-26 11:37:35 +00:00
|
|
|
return {"a": a, "b": b}
|
2020-10-06 01:30:41 +00:00
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return self.len
|
|
|
|
|
|
|
|
|
2021-05-03 18:50:26 +00:00
|
|
|
class RandomIterableDataset(IterableDataset):
|
|
|
|
def __init__(self, size: int, count: int):
|
|
|
|
self.count = count
|
|
|
|
self.size = size
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
for _ in range(self.count):
|
|
|
|
yield torch.randn(self.size)
|
|
|
|
|
|
|
|
|
|
|
|
class RandomIterableDatasetWithLen(IterableDataset):
|
|
|
|
def __init__(self, size: int, count: int):
|
|
|
|
self.count = count
|
|
|
|
self.size = size
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
for _ in range(len(self)):
|
|
|
|
yield torch.randn(self.size)
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return self.count
|