Get weights and bias from the saved model #2402
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 14 replies
-
The parameters for each module are accessible via their respective field. For example, you can get the let weight = linear.weight.val();
let bias = linear.bias.unwrap().val(); |
Beta Was this translation helpful? Give feedback.
-
@laggui In summary, in a complicated nested model, how to get and modify the parameters in a convenient way ? With pytorch, this can be achieved by the following code: for p in discriminator.parameters():
print(p.data.type)
p.data.clamp(-clip_value, clip_value) |
Beta Was this translation helpful? Give feedback.
-
@laggui /// Module visitor trait.
pub trait ModuleVisitor<B: Backend> {
/// Visit a tensor in the module.
fn visit<const D: usize>(&mut self, id: ParamId, tensor: &Tensor<B, D>);
}
/// Module mapper trait.
pub trait ModuleMapper<B: Backend> {
/// Map a tensor in the module.
fn map<const D: usize>(&mut self, id: ParamId, tensor: Tensor<B, D>) ->
Tensor<B, D>;
}
|
Beta Was this translation helpful? Give feedback.
-
@laggui
|
Beta Was this translation helpful? Give feedback.
-
l read carefully on burn's docs and source code. And here is my suggestions:
|
Beta Was this translation helpful? Give feedback.
The parameters for each module are accessible via their respective field. For example, you can get the
Linear
weight and bias tensor values with: