轉載請註明出處: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}