Module: Torch::Utils::Data
- Defined in:
- lib/torch/utils/data.rb,
lib/torch/utils/data/subset.rb,
lib/torch/utils/data/dataset.rb,
lib/torch/utils/data/data_loader.rb,
lib/torch/utils/data/tensor_dataset.rb,
lib/torch/utils/data/iterable_dataset.rb,
lib/torch/utils/data/data_pipes/iter_data_pipe.rb,
lib/torch/utils/data/data_pipes/iter/file_lister.rb,
lib/torch/utils/data/data_pipes/iter/file_opener.rb,
lib/torch/utils/data/data_pipes/iter/stream_wrapper.rb,
lib/torch/utils/data/data_pipes/filter_iter_data_pipe.rb,
lib/torch/utils/data/data_pipes/iter/iterable_wrapper.rb
Defined Under Namespace
Modules: DataPipes Classes: DataLoader, Dataset, IterableDataset, Subset, TensorDataset
Class Method Summary collapse
Class Method Details
.random_split(dataset, lengths) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/torch/utils/data.rb', line 5 def random_split(dataset, lengths) if lengths.sum != dataset.length raise ArgumentError, "Sum of input lengths does not equal the length of the input dataset!" end indices = Torch.randperm(lengths.sum).to_a _accumulate(lengths).zip(lengths).map { |offset, length| Subset.new(dataset, indices[(offset - length)...offset]) } end |