Class: DNN::Savers::MarshalSaver

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

Instance Method Summary collapse

Methods inherited from Saver

#save

Constructor Details

#initialize(model, include_model: true) ⇒ MarshalSaver

Returns a new instance of MarshalSaver.



84
85
86
87
# File 'lib/dnn/core/savers.rb', line 84

def initialize(model, include_model: true)
  super(model)
  @include_model = include_model
end

Instance Method Details

#dump_binObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/dnn/core/savers.rb', line 89

def dump_bin
  params_data = @model.get_all_params_data
  if @include_model
    @model.clean_layers
    data = {
      version: VERSION, class: @model.class.name,
      params: params_data, model: @model
    }
  else
    data = { version: VERSION, class: @model.class.name, params: params_data }
  end
  bin = Zlib::Deflate.deflate(Marshal.dump(data))
  @model.set_all_params_data(params_data) if @include_model
  bin
end