Class: Torch::Utils::Data::DataLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/torch/utils/data/data_loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(dataset, batch_size: 1) ⇒ DataLoader

Returns a new instance of DataLoader.



5
6
7
8
# File 'lib/torch/utils/data/data_loader.rb', line 5

def initialize(dataset, batch_size: 1)
  @dataset = dataset
  @batch_size = batch_size
end

Instance Method Details

#eachObject



10
11
12
13
14
15
16
17
# File 'lib/torch/utils/data/data_loader.rb', line 10

def each
  size = @dataset.size
  start_index = 0
  while start_index < size
    yield @dataset[start_index...(start_index + @batch_size)]
    start_index += @batch_size
  end
end