Class: Torchrb::DataSet

Inherits:
Object
  • Object
show all
Defined in:
lib/torchrb/data_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(set, model, collection) ⇒ DataSet

Returns a new instance of DataSet.



4
5
6
7
8
# File 'lib/torchrb/data_set.rb', line 4

def initialize set, model, collection
  @set = set
  @model = model
  @collection = collection
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



3
4
5
# File 'lib/torchrb/data_set.rb', line 3

def collection
  @collection
end

#histogramObject (readonly)

Returns the value of attribute histogram.



3
4
5
# File 'lib/torchrb/data_set.rb', line 3

def histogram
  @histogram
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'lib/torchrb/data_set.rb', line 3

def model
  @model
end

Instance Method Details

#classesObject



18
19
20
# File 'lib/torchrb/data_set.rb', line 18

def classes
  model.classes
end

#dimensionsObject



41
42
43
# File 'lib/torchrb/data_set.rb', line 41

def dimensions
  torch.eval("return (##{var_name}.input):totable()", __FILE__, __LINE__).values.map(&:to_i)
end

#is_trainset?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/torchrb/data_set.rb', line 10

def is_trainset?
  @set == :train_set
end

#load(&progress_callback) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/torchrb/data_set.rb', line 22

def load &progress_callback
  @progress_callback = progress_callback

  load_classes if is_trainset?
  init_variables
  do_load

  torch.eval <<-EOF, __FILE__, __LINE__
    setmetatable(#{var_name}, {__index = function(t, i)
         return {t.input[i], t.label[i]}
     end}
    );
    function #{var_name}:size()
      return #{var_name}.input:size(1)
    end
  EOF
  self
end

#torchObject



45
46
47
# File 'lib/torchrb/data_set.rb', line 45

def torch
  model.torch
end

#var_nameObject



14
15
16
# File 'lib/torchrb/data_set.rb', line 14

def var_name
  @set.to_s
end