转载请注明出处:html
http://www.cnblogs.com/darkknightzh/p/6591667.htmlgit
参考网址:github
https://github.com/torch/torch7/blob/master/doc/serialization.mdspa
format可选binary(默认)和ascii。binary依赖操做系统,但更容易读写。ascii不依赖操做系统。操作系统
referenced指定是否须要保存object references(https://github.com/torch/torch7/blob/master/doc/file.md#torch.File.referenced)。当保存时设置为true,则读取时若设置为false,则不能成功读取。code
说明:感受若是要保存多个变量,须要使用列表:orm
obj = { -- arbitrary object mat = torch.randn(10,10), name = '10', test = { entry = 1 } } torch.save('test.dat', obj) -- save to disk
format可选ascii,binary(默认),b32,b64。当保存到32/64位的系统上,可使用b32/b64。htm
obj = torch.load('test.dat') -- given serialized object from section above, reload print(obj) -- will print: -- {[mat] = DoubleTensor - size: 10x10 -- [name] = string : "10" -- [test] = table - size: 0}
format可选binary(默认)和ascii,binary依赖操做系统,但更容易读写。ascii不依赖操做系统。blog
obj = { -- arbitrary object mat = torch.randn(10,10), name = '10', test = { entry = 1 } } str = torch.serialize(obj) -- serialize
format可选ascii,binary(默认)。 obj = torch.deserialize(str) -- given serialized object from section above, deserialize print(obj) -- will print: -- {[mat] = DoubleTensor - size: 10x10 -- [name] = string : "10" -- [test] = table - size: 0}