Class: DNN::Savers::Saver

Inherits:
Object
  • Object
show all
Defined in:
lib/dnn/core/savers.rb

Direct Known Subclasses

JSONSaver, MarshalSaver

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Saver

Returns a new instance of Saver.



63
64
65
# File 'lib/dnn/core/savers.rb', line 63

def initialize(model)
  @model = model
end

Instance Method Details

#dump_binObject

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/dnn/core/savers.rb', line 78

def dump_bin
  raise NotImplementedError, "Class '#{self.class.name}' has implement method 'dump_bin'"
end

#save(file_name) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/dnn/core/savers.rb', line 67

def save(file_name)
  bin = dump_bin
  begin
    File.binwrite(file_name, bin)
  rescue Errno::ENOENT
    dir_name = file_name.match(%r`(.*)/.+$`)[1]
    Dir.mkdir(dir_name)
    File.binwrite(file_name, bin)
  end
end