我可以在 Pytorch 中使用什么来代替 caffe 重量填充器
What can I use in Pytorch to remplace caffe's weight filler
我正在基于下面的caffe模型编写一个pytorch模型。你知道我如何在 pytorch 中编写 weight filler 和 bias filler 吗?
layer {
name: "conv3"
type: "Convolution"
bottom: "pool2"
top: "conv3"
param {
lr_mult: 1
decay_mult: 1
}
convolution_param {
num_output: 128
pad_h: 0
pad_w: 1
kernel_h: 1
kernel_w: 3
stride: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
value: 0
}
}
}
谢谢
Pytorch 有 torch.nn.init
库来帮助初始化网络权重。
您可能想使用 nn.init.normal_
for the "gaussian"
filler, and nn.init.constant_
作为偏差的 "constant"
填充物。
您可以使用函数来填充模块的权重m
:
def init_weights(m):
if type(m) == nn.Conv2d:
torch.nn.init.normal_(m.weight, std=0.1)
if m.bias is not None:
torch.nn.init.constant_(m.bias, val=0)
# define the net
net = MyCaffeLikeNetwork()
# use the function to init all weights of the net
net.apply(init_weights)
有关 pytorch 中权重初始化的更多信息,您可以查看 。
我正在基于下面的caffe模型编写一个pytorch模型。你知道我如何在 pytorch 中编写 weight filler 和 bias filler 吗?
layer {
name: "conv3"
type: "Convolution"
bottom: "pool2"
top: "conv3"
param {
lr_mult: 1
decay_mult: 1
}
convolution_param {
num_output: 128
pad_h: 0
pad_w: 1
kernel_h: 1
kernel_w: 3
stride: 1
weight_filler {
type: "gaussian"
std: 0.1
}
bias_filler {
type: "constant"
value: 0
}
}
}
谢谢
Pytorch 有 torch.nn.init
库来帮助初始化网络权重。
您可能想使用 nn.init.normal_
for the "gaussian"
filler, and nn.init.constant_
作为偏差的 "constant"
填充物。
您可以使用函数来填充模块的权重m
:
def init_weights(m):
if type(m) == nn.Conv2d:
torch.nn.init.normal_(m.weight, std=0.1)
if m.bias is not None:
torch.nn.init.constant_(m.bias, val=0)
# define the net
net = MyCaffeLikeNetwork()
# use the function to init all weights of the net
net.apply(init_weights)
有关 pytorch 中权重初始化的更多信息,您可以查看