我有一个预训练的网络(我们称之为N
)我想在新网络中使用两次。有人知道如何复制吗?然后我想为每个副本分配不同的学习率。
例如 (N1
是第一个副本N
, N2
是第二个副本N
),新网络可能如下所示:
N1 --> [joint ip
N2 --> layer]
我知道如何重复利用N
然而,只有一个副本,因为N1
and N2
将有不同的(微调)学习率,我不知道如何制作 2 个副本N
并为每个分配不同的学习率。
Thanks!
使用同一个网络两次称为《连体网》 http://caffe.berkeleyvision.org/gathered/examples/siamese.html。它在 caffe 中的实现方式是显式复制网络,但使用"name"
param 为每个参数 blob 创建一个single基础参数的副本。看例如这个prototxt https://github.com/BVLC/caffe/blob/master/examples/siamese/mnist_siamese_train_test.prototxt.
一旦明确定义网络两次,您就可以分配不同的"lr_mult"
每个副本的参数。
所以假设你的参考网络N
有一个输入层(我将在本例中跳过)和一个名为的内积层"ip1"
. Then
layer {
name: "ip1_a"
bottom: "data_a"
top: "ip1_a"
type: "InnerProduct"
inner_product_param {
num_output: 10
}
param {
name: "ip1_w" # NOTE THIS NAME!
lr_mult: 1
}
param {
name: "ip1_b"
lr_mult: 2
}
}
layer {
name: "ip1_b"
bottom: "data_b"
top: "ip1_b"
type: "InnerProduct"
inner_product_param {
num_output: 10
}
param {
name: "ip1_w" # NOTE THIS NAME: it's the same!
lr_mult: 10 # different LR for this branch
}
param {
name: "ip1_b"
lr_mult: 20
}
}
# one layer to combine them
layer {
type: "Concat"
bottom: "ip1_a"
bottom: "ip1_b"
top: "ip1_combine"
name: "concat"
}
layer {
name: "joint_ip"
type: "InnerProduct"
bottom: "ip1_combine"
top: "joint_ip"
inner_product_param {
num_output: 30
}
}
如果您进行微调,您可能需要进行一些网络手术,以便将原始权重保存在.caffemodel
包含名称的文件"ip1_w"
and "ip1_b"
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)