Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you generate this form of model #2

Closed
ruotianluo opened this issue Aug 28, 2016 · 2 comments
Closed

How do you generate this form of model #2

ruotianluo opened this issue Aug 28, 2016 · 2 comments

Comments

@ruotianluo
Copy link

I'm wondering where i can find the standard code to remove the gradBias and gradWeight and generate a unpack function to recover the model.

@szagoruyko
Copy link
Owner

for k,v in ipairs(net:listModules()) do
  v.gradWeight = nil
  v.gradBias = nil
end

local ts = {
  model = net:float(),
  unpack = function(self)
    for k,v in ipairs(self.model:listModules()) do
      if v.weight and not v.gradWeight then
        v.gradWeight = v.weight:clone()
        v.gradBias = v.bias:clone()
      end
    end
    return self.model
  end
}

torch.save('model.t7', ts)

@ruotianluo
Copy link
Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants