| 221 | |
| 222 | |
| 223 | class SubsetDataset(Dataset): |
| 224 | def __init__(self, ds, start, length): |
| 225 | assert start >= 0 and length > 0 and start + length <= len(ds), "Illegal start or length" |
| 226 | self.ds = ds |
| 227 | self.start = start |
| 228 | self.length = length |
| 229 | |
| 230 | def __len__(self): |
| 231 | return self.length |
| 232 | |
| 233 | def __getitem__(self, idx): |
| 234 | if idx < 0 or idx >= self.length: |
| 235 | raise IndexError("Index out of range") |
| 236 | return self.ds[idx + self.start] |
| 237 | |
| 238 | |
| 239 | def split_train_val_test(ds, split=[0.99, 0.01, 0.0], seed=None): |
no outgoing calls
no test coverage detected