如何在CAFFE的新网络中重复使用同一网络两次 [英] How to reuse same network twice within a new network in CAFFE
问题描述
我有一个预先训练的网络(我们称它为N
),我想在一个新网络中使用两次.有人知道如何复制吗?然后我想给每个副本分配不同的学习率.
I have a pretrained network (let's call it N
) I would like to use twice within a new network. Anybody knows how to duplicate it? Then I would like to assign a different learning rate to each copy.
例如(N1
是N
的第一个副本,N2
是N
的第二个副本),新网络可能如下所示:
For example (N1
is the 1st copy of N
, N2
is the 2nd copy of N
), the new network might look like:
N1 --> [joint ip
N2 --> layer]
我知道如何以单个副本重用N
,但是,由于N1
和N2
的学习速度不同(微调),所以我不知道如何制作2个N
副本并为每个学习者分配不同的学习率.
I know how to reuse N
with a single copy, however, since N1
and N2
will have different (finetune) learning rates, I don't know how can I make 2 copies of N
and assign different learning rate for each.
谢谢!
推荐答案
两次使用同一网络称为暹罗网络" .在caffe中实现它的方式是通过显式复制网络,但对每个参数blob使用"name"
参数来创建基础参数的单个副本.例如,请参见此原型.
一旦明确定义了两次伪网,就可以为每个副本分配不同的"lr_mult"
参数.
Using the same net twice is something called "Siamese network". The way it is implemented in caffe is by explicitly duplicating the network, but using "name"
param for each parameters blob to create a single copy of the underlying parameters. See this prototxt for example.
Once you explicitly defeine the net twice, you can assign different "lr_mult"
params for each copy.
因此,假设您的参考网络N
具有一个输入层(在本示例中将跳过)和一个名为"ip1"
的内部产品层.然后
So suppose your reference network N
has an input layer (which I'll skip in this example) and an inner product layer named "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
}
}
如果您要微调,则可能需要进行一些网络手术,以便将原始格式以名称"ip1_w"
和"ip1_b"
的形式保存在.caffemodel
文件中.
If you finetune, you might need to do some net-surgery in order of the original wieghts to be saved in the .caffemodel
file with the names "ip1_w"
and "ip1_b"
.
这篇关于如何在CAFFE的新网络中重复使用同一网络两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!