for my recent project I have saved my trained model using ..torch.save('model.t7', trainednetwork) ..But the problem is that size of model is very large its 1.6GB , practically not useful. Is there are any function to compress torch model to smaller size?
Saved networks can be bloated significantly by the temporaries stored in the nn modules. You might want to consider just saving the parameters - this will often already save you lots of space.
thanks Georg! you mean using this function? parameters,gradParameters = model:getParameters()?
Suppose I have saved only parameters, then how can I load those for testing against some inputs?
@n3011 One simple way of only selecting the parameters of the network, and still keeping the data structure, is to clone the model after calling the getParameters, but before start the training, and sharing the weight and bias.
Like this
model:cuda()
parameters, gradParameters = model:getParameters()
-- this need to be after :cuda and after :getParameters
lightModel = model:clone('weight','bias','running_mean','running_std')
-- do training, and when need to save, call
torch.save('model.t7',lightModel)
lightModel shares the same parameters as model, but it doesn't contain all the temporaries that comes while training. This can significantly reduce the size of the saved models.
Thanks @fmassa , Thts what i was looking for. But to load this parameter i would also need to pass the network configurations like proto.txt of caffe. Is there are any function in torch to do that?
@n3011 No torch.save uses torch serialization that serialize the whole object.
Note that if the model you save is on GPU (as in @fmassa example), it will be loaded back on the GPU. Thus you must require the cunn package before doing the torch.load
there is a dedicated method to do exactly this now: Module:clearstate https://github.com/torch/nn/blob/master/doc/module.md#clearstate
It is very strange that we train the model and the mode size is more than 1.3GB, but we have already added the clearState() into the train script when save the model. Seely it can't help to reduce the model size.
Also we try Sanitize.lua or net-toolkit to reduce the trained model file, all are helpless. So is there any other method to reduce model size?
I have the same problem with torch models.
The model size depends on the batchsize for training. I use clearState() in the training script and it doesn't help to reduce the model size.
Any help will be much appreciated!!!
Most importantly torch is outdated , use tensorflow.
On Sun, 29 Jan 2017 at 8:22 PM, shimen notifications@github.com wrote:
I have the same problem with torch models.
The model size depends on the batchsize for training. I use clearState()
in the training script and it doesn't help to reduce the model size.
Any help will be much appreciated!!!—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/torch/torch7/issues/411#issuecomment-275918583, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AC_oMAjZxBmz5DCKokrDZ1OSxGZeWWTkks5rXKe5gaJpZM4GRMOn
.>
Regards
Mrinal(Ishant) Haloi
www.linkedin.com/in/mrinalhaloi
Most helpful comment
there is a dedicated method to do exactly this now:
Module:clearstatehttps://github.com/torch/nn/blob/master/doc/module.md#clearstate