Skip to content

Commit

Permalink
Merge pull request #47 from hatappi/fix/marshal-dump-save_file
Browse files Browse the repository at this point in the history
MarshalSerializer.save_file receives string file_path
  • Loading branch information
hatappi authored Apr 4, 2018
2 parents 5ffcff1 + 64f183b commit a7a18df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/chainer/serializers/marshal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ module Serializers
class MarshalSerializer < Chainer::Serializer
attr_accessor :target, :path

def self.save_file(filename, obj)
# @param [string] file_path Target file path
# @param [Object] obj Object to be serialized
def self.save_file(file_path, obj)
s = self.new
s.save(obj)
Marshal.dump(s.target, filename)
File.open(file_path, 'wb') do |f|
Marshal.dump(s.target, f)
end
end

def initialize(target: nil, path: "")
Expand Down
2 changes: 1 addition & 1 deletion lib/chainer/training/extensions/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def call(trainer)
filename = filename_proc.call(trainer)
prefix = "tmp#{filename}"
temp_file = Tempfile.create(basename: prefix, tmpdir: trainer.out)
save_class.save_file(temp_file, trainer)
save_class.save_file(temp_file.path, trainer)
FileUtils.move(temp_file.path, File.join(trainer.out, filename))
end
end
Expand Down

0 comments on commit a7a18df

Please sign in to comment.